Skip to content

Commit 4cf4f9e

Browse files
authored
[SYCLomatic] Add test for migration of cuMemcpy and cuMemcpyAsync (#129)
* [SYCLomatic] Add test for cuMemcpy and cuMemcpyAsync Signed-off-by: Cai, Justin <[email protected]> * Add exec test for cuMemcpy * Modify test to iterate of amount of memory copied Signed-off-by: Cai, Justin <[email protected]>
1 parent 3e85eb9 commit 4cf4f9e

File tree

3 files changed

+82
-3
lines changed

3 files changed

+82
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__pycache__
2+
test_workspace

features/feature_case/driverMem/driverMem.cu

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
#include <cuda.h>
1010
#include <cuda_runtime_api.h>
1111
#include <iostream>
12-
int main(){
12+
#include <vector>
13+
#include <algorithm>
14+
15+
void test1(){
1316
size_t result1, result2;
1417
int size = 32;
1518
float* f_A;
@@ -53,6 +56,15 @@ int main(){
5356

5457
cuMemcpyDtoH(f_A, f_D, size);
5558

59+
cuMemcpy(f_D, f_D2, size);
60+
r = cuMemcpy(f_D, f_D2, size);
61+
62+
cuMemcpyAsync(f_D, f_D2, size, stream);
63+
r = cuMemcpyAsync(f_D, f_D2, size, stream);
64+
65+
cuMemcpyAsync(f_D, f_D2, size, 0);
66+
r = cuMemcpyAsync(f_D, f_D2, size, 0);
67+
5668

5769
cuMemHostGetDevicePointer(&f_D, f_A, 0);
5870

@@ -147,7 +159,72 @@ int main(){
147159
cuMemHostRegister((void *)pFlags, size, CU_MEMHOSTREGISTER_PORTABLE);
148160

149161
cuMemHostUnregister((void *)pFlags);
162+
}
150163

151-
return 0;
164+
int test2() {
165+
int ret = 0;
166+
constexpr int size = 64;
167+
int v1[size];
168+
int v2[size];
169+
170+
CUdeviceptr p1 = (CUdeviceptr)v1;
171+
CUdeviceptr p2 = (CUdeviceptr)v2;
172+
CUdeviceptr q1;
173+
CUdeviceptr q2;
174+
175+
// check if v1 and v2 agree on first i elements
176+
177+
auto check = [&](int i, std::string fail) {
178+
if (!std::equal(v1, v1+i, v2)) {
179+
std::cout << fail << "\n";
180+
ret = 1;
181+
}
182+
};
183+
184+
// v1 = {0, 1, 2, ...}
185+
// v2 = {-1, -1, ...}
186+
auto initialize = [&]() {
187+
for (int i = 0; i < size; ++i) {
188+
v1[i] = i;
189+
v2[i] = -1;
190+
}
191+
cuMemAlloc(&q1, sizeof(int)*size);
192+
cuMemAlloc(&q2, sizeof(int)*size);
193+
};
194+
195+
for (int i = 1; i < size; i *= 2) {
196+
int n = sizeof(int)*i;
197+
198+
// host to host copy
199+
initialize();
200+
cuMemcpy(p2, p1, n);
201+
check(i, "cuMemcpy fail " + std::to_string(i));
202+
203+
// host to device copy async, device to host copy
204+
initialize();
205+
cuMemcpyAsync(q1, p1, n, 0);
206+
cuStreamSynchronize(0);
207+
cuMemcpy(p2, q1, n);
208+
check(i, "cuMemcpyAsync 1 fail " + std::to_string(i));
209+
210+
// host to device copy, device to device async copy,
211+
// device to host copy
212+
initialize();
213+
cuMemcpy(q1, p1, n);
214+
cuMemcpyAsync(q2, q1, n, 0);
215+
cuStreamSynchronize(0);
216+
cuMemcpy(p2, q2, n);
217+
check(i, "cuMemcpyAsync 2 fail " + std::to_string(i));
218+
}
219+
220+
return ret;
152221
}
153222

223+
int main() {
224+
cuInit(0);
225+
CUdevice dev = 0;
226+
cuDeviceGet(&dev, 0);
227+
CUcontext ctx = 0;
228+
cuCtxCreate(&ctx, 0, dev);
229+
return test2();
230+
}

features/test_feature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
'cudnn-sum', 'math-funnelshift', 'ccl', 'thrust-sort_by_key', 'thrust-find', 'thrust-inner_product', 'thrust-reduce_by_key',
3232
'math-bfloat16', 'libcu_atomic', 'test_shared_memory', 'cudnn-reduction', 'cudnn-binary', 'cudnn-bnp1', 'cudnn-bnp2', 'cudnn-bnp3',
3333
'cudnn-normp1', 'cudnn-normp2', 'cudnn-normp3', 'cudnn-convp1', 'cudnn-convp2', 'cudnn-convp3', 'cudnn-convp4', 'cudnn-convp5',
34-
'thrust-unique_by_key', 'cufft_test', "pointer_attributes", 'math_intel_specific', 'math-drcp', 'thrust-pinned-allocator']
34+
'thrust-unique_by_key', 'cufft_test', "pointer_attributes", 'math_intel_specific', 'math-drcp', 'thrust-pinned-allocator', 'driverMem']
3535

3636

3737
def setup_test():

0 commit comments

Comments
 (0)