-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp2p_copy.cu
47 lines (36 loc) · 934 Bytes
/
p2p_copy.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <cuda.h>
#include <cuda_runtime.h>
#include <stdio.h>
float p2p_copy (size_t size)
{
int *pointers[2];
cudaSetDevice (0);
cudaDeviceEnablePeerAccess (1, 0);
cudaMalloc (&pointers[0], size);
cudaSetDevice (1);
cudaDeviceEnablePeerAccess (0, 0);
cudaMalloc (&pointers[1], size);
cudaEvent_t begin, end;
cudaEventCreate (&begin);
cudaEventCreate (&end);
cudaEventRecord (begin);
cudaMemcpyAsync (pointers[0], pointers[1], size, cudaMemcpyDeviceToDevice);
cudaEventRecord (end);
cudaEventSynchronize (end);
float elapsed;
cudaEventElapsedTime (&elapsed, begin, end);
elapsed /= 1000;
cudaSetDevice (0);
cudaFree (pointers[0]);
cudaSetDevice (1);
cudaFree (pointers[1]);
cudaEventDestroy (end);
cudaEventDestroy (begin);
return elapsed;
}
int main(){
float elapse_p2p_copy;
size_t size = 100000;
elapse_p2p_copy = p2p_copy(size);
printf("Elapsed time p2p copy: %f s \n", elapse_p2p_copy);
}