Skip to content

Commit 5e78417

Browse files
[MLIR][CUDA] Use _alloca instead of alloca on Windows (#85853)
MSVC/Windows does not support `alloca()`; instead it defines `_alloca()` in `malloc.h`.
1 parent 807fd07 commit 5e78417

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

mlir/lib/ExecutionEngine/CudaRuntimeWrappers.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#endif // MLIR_ENABLE_CUDA_CUSPARSE
2929

3030
#ifdef _WIN32
31+
#include <malloc.h>
3132
#define MLIR_CUDA_WRAPPERS_EXPORT __declspec(dllexport)
3233
#else
3334
#define MLIR_CUDA_WRAPPERS_EXPORT __attribute__((visibility("default")))
@@ -287,7 +288,11 @@ extern "C" MLIR_CUDA_WRAPPERS_EXPORT void
287288
mgpuMemHostRegisterMemRef(int64_t rank, StridedMemRefType<char, 1> *descriptor,
288289
int64_t elementSizeBytes) {
289290
// Only densely packed tensors are currently supported.
291+
#ifdef _WIN32
292+
int64_t *denseStrides = (int64_t *)_alloca(rank * sizeof(int64_t));
293+
#else
290294
int64_t *denseStrides = (int64_t *)alloca(rank * sizeof(int64_t));
295+
#endif // _WIN32
291296
int64_t *sizes = descriptor->sizes;
292297
for (int64_t i = rank - 1, runningStride = 1; i >= 0; i--) {
293298
denseStrides[i] = runningStride;

0 commit comments

Comments
 (0)