Skip to content

Commit 8d79988

Browse files
committed
Add the two AOTI shims PyTorch 2.14 links against, and export all three
Lowering a CUDA model for a Windows target fails at link time: x86_64-w64-mingw32-ld: undefined reference to `aoti_torch_dtype_uint8' x86_64-w64-mingw32-ld: undefined reference to `aoti_torch_empty_strided_pinned' x86_64-w64-mingw32-ld: undefined reference to `aoti_torch_is_defined' collect2: error: ld returned 1 exit status PyTorch generates a wrapper for the model and links it against this project's shims. The wrapper's own header started calling these three in 2.14, where it called none of them before, so the link now needs all three present. Two did not exist here: `aoti_torch_is_defined` asks whether a handle refers to a real tensor. PyTorch has an undefined-tensor state with no equivalent here, so this is a null check. `aoti_torch_empty_strided_pinned` asks for page-locked host memory, which lets the copy of the model's constants to the device overlap with filling the next buffer. There is no allocator for that memory here, so this reports that and the caller takes the plain synchronous copy it already falls back to. That path is not an error case: the calling code is named for trying, and every way it can fail logs that it is falling back and carries on. Adding a real pinned allocator means teaching the storage layer a new kind of memory and a matching way to release it, which is a change of its own rather than part of moving a version pin. The third, `aoti_torch_dtype_uint8`, was already implemented and simply missing from the list of names the Windows link stub exports, along with the other two. That stub is a checked-in file, so it is regenerated here. Every previous pin bump has had to do the same. Test Plan: Read the requirement from the generated wrapper's header on both branches rather than inferring it from the link error: it names these three in 2.14 and none of them in 2.13, which is why this appears only after the pin moves. Compiled the common shims and confirmed with the symbol table that `aoti_torch_is_defined` is defined rather than merely declared. Checked its signature against PyTorch's own header parameter by parameter, and matched the pointer spelling the neighbouring shims already use for a tensor handle. Regenerated the link stub from the names it already exported plus these three, so it went from 42 to 45. Confirmed the result is a strict superset, that nothing was dropped, that the counts of the two kinds of entry agree, and that all three names are now in it. Confirmed the caller treats a refusal as an ordinary outcome by reading it: it returns empty and logs that it is falling back to the synchronous copy. Formatting is clean on the changed files. The CUDA shim file needs the CUDA headers to compile, which this machine does not have, so that half is for CI to confirm. Whether a Windows target now links is also for CI, since it needs the cross toolchain.
1 parent 6a7ae1f commit 8d79988

5 files changed

Lines changed: 48 additions & 0 deletions

File tree

‎backends/aoti/common_shims.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ AOTITorchError aoti_torch_get_numel(Tensor* tensor, int64_t* ret_numel) {
159159
return Error::Ok;
160160
}
161161

162+
AOTITorchError aoti_torch_is_defined(Tensor* tensor, bool* ret_is_defined) {
163+
*ret_is_defined = tensor != nullptr;
164+
return Error::Ok;
165+
}
166+
162167
// Device and layout utility functions
163168
int32_t aoti_torch_device_type_cpu() {
164169
// Let's say cpu is 0 for ET as well

‎backends/aoti/common_shims.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ aoti_torch_get_dim(Tensor* tensor, int64_t* ret_dim);
6262
AOTI_SHIM_EXPORT AOTITorchError
6363
aoti_torch_get_numel(Tensor* tensor, int64_t* ret_numel);
6464

65+
// Reports whether the handle refers to a real tensor. PyTorch has an undefined
66+
// tensor state that ExecuTorch has no equivalent for, so this is a null check.
67+
AOTI_SHIM_EXPORT AOTITorchError
68+
aoti_torch_is_defined(Tensor* tensor, bool* ret_is_defined);
69+
6570
// Utility functions for device and layout information
6671
AOTI_SHIM_EXPORT int32_t aoti_torch_device_type_cpu();
6772
AOTI_SHIM_EXPORT int32_t aoti_torch_layout_strided();
25.4 KB
Binary file not shown.

‎backends/cuda/runtime/shims/memory.cpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,24 @@ AOTITorchError aoti_torch_empty_strided(
195195
return Error::Ok;
196196
}
197197

198+
AOTITorchError aoti_torch_empty_strided_pinned(
199+
int64_t ndim,
200+
const int64_t* sizes_ptr,
201+
const int64_t* strides_ptr,
202+
int32_t dtype,
203+
int32_t device_type,
204+
int32_t device_index,
205+
SlimTensor** ret_new_tensor) {
206+
(void)ndim;
207+
(void)sizes_ptr;
208+
(void)strides_ptr;
209+
(void)dtype;
210+
(void)device_type;
211+
(void)device_index;
212+
(void)ret_new_tensor;
213+
return Error::NotSupported;
214+
}
215+
198216
AOTITorchError aoti_torch_delete_tensor_object(SlimTensor* tensor) {
199217
ET_CHECK_OR_RETURN_ERROR(
200218
tensor != nullptr,

‎backends/cuda/runtime/shims/memory.h‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,26 @@ AOTI_SHIM_EXPORT AOTITorchError aoti_torch_empty_strided(
9595
int32_t device_index,
9696
SlimTensor** ret_new_tensor);
9797

98+
/**
99+
* Reports that pinned host memory is unavailable.
100+
*
101+
* Generated wrappers call this to stage constants through page-locked host
102+
* memory, which lets the copy to the device run asynchronously. There is no
103+
* pinned allocator here, so this always fails and the caller uses the
104+
* synchronous copy it already falls back to. Correct, and slower only while
105+
* loading.
106+
*
107+
* @return Error::NotSupported
108+
*/
109+
AOTI_SHIM_EXPORT AOTITorchError aoti_torch_empty_strided_pinned(
110+
int64_t ndim,
111+
const int64_t* sizes_ptr,
112+
const int64_t* strides_ptr,
113+
int32_t dtype,
114+
int32_t device_type,
115+
int32_t device_index,
116+
SlimTensor** ret_new_tensor);
117+
98118
/**
99119
* Deletes a tensor object and frees associated resources.
100120
*

0 commit comments

Comments
 (0)