[llvm] [offload] add support for aligned allocations (PR #203353)
Piotr Balcer via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 12 02:44:54 PDT 2026
================
@@ -600,20 +615,44 @@ struct CUDADeviceTy : public GenericDeviceTy {
switch (Kind) {
case TARGET_ALLOC_DEFAULT:
case TARGET_ALLOC_DEVICE:
+ if (Alignment > 0 && Alignment > Granularity) {
+ return Plugin::error(
+ ErrorCode::UNSUPPORTED,
+ "too large alignment size for the device allocation");
+ }
+
Res = cuMemAlloc(&DevicePtr, Size);
MemAlloc = (void *)DevicePtr;
break;
case TARGET_ALLOC_HOST:
+ if (Alignment > 0 && Alignment > Granularity) {
+ return Plugin::error(
+ ErrorCode::UNSUPPORTED,
+ "too large alignment size for the host allocation");
+ }
+
Res = cuMemAllocHost(&MemAlloc, Size);
break;
case TARGET_ALLOC_SHARED:
+ if (Alignment > 0 && Alignment > Granularity) {
+ return Plugin::error(
+ ErrorCode::UNSUPPORTED,
+ "too large alignment size for the shared allocation");
+ }
+
Res = cuMemAllocManaged(&DevicePtr, Size, CU_MEM_ATTACH_GLOBAL);
MemAlloc = (void *)DevicePtr;
break;
}
if (auto Err = Plugin::check(Res, "error in cuMemAlloc[Host|Managed]: %s"))
return std::move(Err);
+
+ if (Alignment > 0 && !isAddrAligned(Align(Alignment), MemAlloc)) {
+ return Plugin::error(ErrorCode::UNSUPPORTED,
+ "unsupported alignment size");
----------------
pbalcer wrote:
ditto, this will leak MemAlloc.
https://github.com/llvm/llvm-project/pull/203353
More information about the llvm-commits
mailing list