[Mlir-commits] [mlir] [MLIR][CUDA] Use _alloca instead of alloca on Windows (PR #85853)

Justin Holewinski llvmlistbot at llvm.org
Tue Mar 19 12:35:51 PDT 2024


https://github.com/jholewinski created https://github.com/llvm/llvm-project/pull/85853

MSVC/Windows does not support `alloca()`; instead it defines `_alloca()` in `malloc.h`.

>From 1b5fd8f214e7a86d2faf41f7897a57ee7b14576a Mon Sep 17 00:00:00 2001
From: Justin Holewinski <jholewinski at nvidia.com>
Date: Tue, 19 Mar 2024 19:05:14 +0000
Subject: [PATCH] [MLIR][CUDA] Use _alloca instead of alloca on Windows

---
 mlir/lib/ExecutionEngine/CudaRuntimeWrappers.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mlir/lib/ExecutionEngine/CudaRuntimeWrappers.cpp b/mlir/lib/ExecutionEngine/CudaRuntimeWrappers.cpp
index 9d406bdfc7cc9a..09dc30365e37c0 100644
--- a/mlir/lib/ExecutionEngine/CudaRuntimeWrappers.cpp
+++ b/mlir/lib/ExecutionEngine/CudaRuntimeWrappers.cpp
@@ -28,6 +28,7 @@
 #endif // MLIR_ENABLE_CUDA_CUSPARSE
 
 #ifdef _WIN32
+#include <malloc.h>
 #define MLIR_CUDA_WRAPPERS_EXPORT __declspec(dllexport)
 #else
 #define MLIR_CUDA_WRAPPERS_EXPORT __attribute__((visibility("default")))
@@ -287,7 +288,11 @@ extern "C" MLIR_CUDA_WRAPPERS_EXPORT void
 mgpuMemHostRegisterMemRef(int64_t rank, StridedMemRefType<char, 1> *descriptor,
                           int64_t elementSizeBytes) {
   // Only densely packed tensors are currently supported.
+#ifdef _WIN32
+  int64_t *denseStrides = (int64_t *)_alloca(rank * sizeof(int64_t));
+#else
   int64_t *denseStrides = (int64_t *)alloca(rank * sizeof(int64_t));
+#endif // _WIN32
   int64_t *sizes = descriptor->sizes;
   for (int64_t i = rank - 1, runningStride = 1; i >= 0; i--) {
     denseStrides[i] = runningStride;



More information about the Mlir-commits mailing list