Skip to content

Commit 7a0fd25

Browse files
committed
fix cuda 13 api compatibility
1 parent 0e70173 commit 7a0fd25

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

pfsimulator/amps/mpi1/amps_allreduce.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,40 @@ int amps_AllReduce(amps_Comm comm, amps_Invoice invoice, MPI_Op operation)
151151
if (cudaGetLastError() == cudaSuccess && attributes.type > 1)
152152
{
153153
if (stride == 1)
154-
CUDA_ERRCHK(cudaMemPrefetchAsync(data, (size_t)len * element_size, cudaCpuDeviceId, 0));
154+
{
155+
#if CUDART_VERSION >= 13000
156+
int deviceIndex;
157+
CUDA_ERRCHK(cudaGetDevice(&deviceIndex));
158+
struct cudaMemLocation location = {};
159+
location.type = cudaMemLocationTypeDevice;
160+
location.id = deviceIndex;
161+
CUDA_ERRCHK(cudaMemPrefetchAsync(data, (size_t)len * element_size, location, 0, 0));
162+
#else
163+
CUDA_ERRCHK(cudaMemPrefetchAsync(data, (size_t)len * element_size, cudaCpuDeviceId, 0));
164+
#endif
165+
}
155166
else
156-
for (ptr_src = data;
167+
{
168+
for (ptr_src = data;
157169
ptr_src < data + len * stride * element_size;
158170
ptr_src += stride * element_size)
159-
CUDA_ERRCHK(cudaMemPrefetchAsync(ptr_src, (size_t)element_size, cudaCpuDeviceId, 0));
171+
172+
{
173+
#if CUDART_VERSION >= 13000
174+
int deviceIndex;
175+
CUDA_ERRCHK(cudaGetDevice(&deviceIndex));
176+
struct cudaMemLocation location = {};
177+
location.type = cudaMemLocationTypeDevice;
178+
location.id = deviceIndex;
179+
CUDA_ERRCHK(cudaMemPrefetchAsync(ptr_src, (size_t)len * element_size, location, 0 , 0));
180+
#else
181+
CUDA_ERRCHK(cudaMemPrefetchAsync(ptr_src, (size_t)element_size, cudaCpuDeviceId, 0));
182+
#endif
183+
}
160184

161185
CUDA_ERRCHK(cudaStreamSynchronize(0));
162186
}
187+
}
163188
#endif
164189

165190
/* Copy into a contiguous buffer */

0 commit comments

Comments
 (0)