Files
rocm-systems/tests/src/hipDrvMemcpy.cpp
T

45 lines
913 B
C++
Raw Normal View History

2016-08-26 13:11:01 -05:00
#include<iostream>
#include<hip/hip_runtime.h>
#include<hip/hip_runtime_api.h>
#define LEN 1024
#define SIZE LEN<<2
int main(){
2016-09-09 10:21:52 -05:00
int *A, *B;
hipDeviceptr_t Ad, Bd;
2016-08-26 13:11:01 -05:00
A = new int[LEN];
B = new int[LEN];
2016-09-09 10:21:52 -05:00
2016-08-26 13:11:01 -05:00
for(int i=0;i<LEN;i++){
A[i] = i;
}
2016-09-09 10:21:52 -05:00
2016-08-26 13:11:01 -05:00
hipMalloc((void**)&Ad, SIZE);
hipMalloc((void**)&Bd, SIZE);
2016-09-09 10:21:52 -05:00
2016-08-26 13:11:01 -05:00
hipMemcpyHtoD(Ad, A, SIZE);
hipMemcpyDtoD(Bd, Ad, SIZE);
hipMemcpyDtoH(B, Bd, SIZE);
2016-09-09 10:21:52 -05:00
2016-08-26 13:11:01 -05:00
for(int i=0;i<16;i++){
2016-09-09 10:21:52 -05:00
std::cout<<A[i]<<" "<<B[i]<<std::endl;
2016-08-26 13:11:01 -05:00
}
2016-09-09 10:21:52 -05:00
int *Ah, *Bh;
hipHostMalloc(&Ah, SIZE, 0);
hipHostMalloc(&Bh, SIZE, 0);
memcpy(Ah, A, SIZE);
hipStream_t stream;
hipStreamCreate(&stream);
hipMemcpyHtoDAsync(Ad, Ah, SIZE, stream);
hipStreamSynchronize(stream);
hipMemcpyDtoDAsync(Bd, Ad, SIZE, stream);
hipStreamSynchronize(stream);
hipMemcpyDtoHAsync(Bh, Bd, SIZE, stream);
hipStreamSynchronize(stream);
std::cout<<Ah[10]<<" "<<Bh[10]<<std::endl;
2016-08-26 13:11:01 -05:00
}