Skip to content

[UR][CUDA] Add support for CUDA 13 #19752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions unified-runtime/source/adapters/cuda/enqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ ur_result_t enqueueEventsWait(ur_queue_handle_t CommandQueue, CUstream Stream,
}
}

#if CUDA_VERSION >= 13000
using CuLocationType = CUmemLocation;
#else
using CuLocationType = CUdevice;
#endif
void setCuMemAdvise(CUdeviceptr DevPtr, size_t Size,
ur_usm_advice_flags_t URAdviceFlags, CUdevice Device) {
ur_usm_advice_flags_t URAdviceFlags,
CuLocationType Location) {
std::unordered_map<ur_usm_advice_flags_t, CUmem_advise>
URToCUMemAdviseDeviceFlagsMap = {
{UR_USM_ADVICE_FLAG_SET_READ_MOSTLY, CU_MEM_ADVISE_SET_READ_MOSTLY},
Expand All @@ -64,7 +70,7 @@ void setCuMemAdvise(CUdeviceptr DevPtr, size_t Size,
};
for (auto &FlagPair : URToCUMemAdviseDeviceFlagsMap) {
if (URAdviceFlags & FlagPair.first) {
UR_CHECK_ERROR(cuMemAdvise(DevPtr, Size, FlagPair.second, Device));
UR_CHECK_ERROR(cuMemAdvise(DevPtr, Size, FlagPair.second, Location));
}
}

Expand All @@ -82,7 +88,14 @@ void setCuMemAdvise(CUdeviceptr DevPtr, size_t Size,

for (auto &FlagPair : URToCUMemAdviseHostFlagsMap) {
if (URAdviceFlags & FlagPair.first) {
UR_CHECK_ERROR(cuMemAdvise(DevPtr, Size, FlagPair.second, CU_DEVICE_CPU));
#if CUDA_VERSION >= 13000
CUmemLocation LocationHost;
LocationHost.id = 0; // ignored with HOST_NUMA_CURRENT
LocationHost.type = CU_MEM_LOCATION_TYPE_HOST_NUMA_CURRENT;
#else
int LocationHost = CU_DEVICE_CPU;
#endif
UR_CHECK_ERROR(cuMemAdvise(DevPtr, Size, FlagPair.second, LocationHost));
}
}

Expand Down Expand Up @@ -1550,8 +1563,17 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMPrefetch(
return UR_RESULT_SUCCESS;
}

#if CUDA_VERSION >= 13000
CUmemLocation Location;
Location.id = Device->get();
Location.type = CU_MEM_LOCATION_TYPE_DEVICE;
unsigned int Flags = 0U;
UR_CHECK_ERROR(
cuMemPrefetchAsync((CUdeviceptr)pMem, size, Location, Flags, CuStream));
#else
UR_CHECK_ERROR(
cuMemPrefetchAsync((CUdeviceptr)pMem, size, Device->get(), CuStream));
#endif
} catch (ur_result_t Err) {
return Err;
}
Expand Down Expand Up @@ -1619,19 +1641,24 @@ urEnqueueUSMAdvise(ur_queue_handle_t hQueue, const void *pMem, size_t size,
return UR_RESULT_SUCCESS;
}

#if CUDA_VERSION >= 13000
CUmemLocation Location;
Location.id = hQueue->getDevice()->get();
Location.type = CU_MEM_LOCATION_TYPE_DEVICE;
#else
int Location = hQueue->getDevice()->get();
#endif

if (advice & UR_USM_ADVICE_FLAG_DEFAULT) {
UR_CHECK_ERROR(cuMemAdvise((CUdeviceptr)pMem, size,
CU_MEM_ADVISE_UNSET_READ_MOSTLY,
hQueue->getDevice()->get()));
CU_MEM_ADVISE_UNSET_READ_MOSTLY, Location));
UR_CHECK_ERROR(cuMemAdvise((CUdeviceptr)pMem, size,
CU_MEM_ADVISE_UNSET_PREFERRED_LOCATION,
hQueue->getDevice()->get()));
Location));
UR_CHECK_ERROR(cuMemAdvise((CUdeviceptr)pMem, size,
CU_MEM_ADVISE_UNSET_ACCESSED_BY,
hQueue->getDevice()->get()));
CU_MEM_ADVISE_UNSET_ACCESSED_BY, Location));
} else {
setCuMemAdvise((CUdeviceptr)pMem, size, advice,
hQueue->getDevice()->get());
setCuMemAdvise((CUdeviceptr)pMem, size, advice, Location);
}
} catch (ur_result_t err) {
return err;
Expand Down