Added async memcpy driver api

Change-Id: I90e8a078d668a408e79f9e1142e7534771467a4f
This commit is contained in:
Aditya Atluri
2016-09-09 10:21:52 -05:00
parent 9145df8b63
commit 2d5140cb27
3 changed files with 107 additions and 6 deletions
+5 -1
View File
@@ -883,7 +883,11 @@ hipError_t hipMemcpyDtoH(void* dst, hipDeviceptr_t src, size_t sizeBytes);
hipError_t hipMemcpyDtoD(hipDeviceptr_t dst, hipDeviceptr_t src, size_t sizeBytes);
hipError_t hipMemcpyHtoH(void* dst, void* src, size_t sizeBytes);
hipError_t hipMemcpyHtoDAsync(hipDeviceptr_t dst, void* src, size_t sizeBytes, hipStream_t stream);
hipError_t hipMemcpyDtoHAsync(void* dst, hipDeviceptr_t src, size_t sizeBytes, hipStream_t stream);
hipError_t hipMemcpyDtoDAsync(hipDeviceptr_t dst, hipDeviceptr_t src, size_t sizeBytes, hipStream_t stream);
/**
+79
View File
@@ -576,6 +576,85 @@ hipError_t hipMemcpyAsync(void* dst, const void* src, size_t sizeBytes, hipMemcp
return ihipLogStatus(e);
}
hipError_t hipMemcpyHtoDAsync(hipDeviceptr_t dst, void* src, size_t sizeBytes, hipStream_t stream)
{
HIP_INIT_API(dst, src, sizeBytes, stream);
hipError_t e = hipSuccess;
stream = ihipSyncAndResolveStream(stream);
hipMemcpyKind kind = hipMemcpyHostToDevice;
if ((dst == NULL) || (src == NULL)) {
e= hipErrorInvalidValue;
} else if (stream) {
try {
stream->copyAsync((void*)dst, src, sizeBytes, kind);
}
catch (ihipException ex) {
e = ex._code;
}
} else {
e = hipErrorInvalidValue;
}
return ihipLogStatus(e);
}
hipError_t hipMemcpyDtoDAsync(hipDeviceptr_t dst, hipDeviceptr_t src, size_t sizeBytes, hipStream_t stream)
{
HIP_INIT_API(dst, src, sizeBytes, stream);
hipError_t e = hipSuccess;
hipMemcpyKind kind = hipMemcpyDeviceToDevice;
stream = ihipSyncAndResolveStream(stream);
if ((dst == NULL) || (src == NULL)) {
e= hipErrorInvalidValue;
} else if (stream) {
try {
stream->copyAsync((void*)dst, (void*)src, sizeBytes, kind);
}
catch (ihipException ex) {
e = ex._code;
}
} else {
e = hipErrorInvalidValue;
}
return ihipLogStatus(e);
}
hipError_t hipMemcpyDtoHAsync(void* dst, hipDeviceptr_t src, size_t sizeBytes, hipStream_t stream)
{
HIP_INIT_API(dst, src, sizeBytes, stream);
hipError_t e = hipSuccess;
stream = ihipSyncAndResolveStream(stream);
hipMemcpyKind kind = hipMemcpyDeviceToHost;
if ((dst == NULL) || (src == NULL)) {
e= hipErrorInvalidValue;
} else if (stream) {
try {
stream->copyAsync(dst, (void*)src, sizeBytes, kind);
}
catch (ihipException ex) {
e = ex._code;
}
} else {
e = hipErrorInvalidValue;
}
return ihipLogStatus(e);
}
// dpitch, spitch, and width in bytes
hipError_t hipMemcpy2D(void* dst, size_t dpitch, const void* src, size_t spitch,
size_t width, size_t height, hipMemcpyKind kind) {
+23 -5
View File
@@ -6,21 +6,39 @@
#define SIZE LEN<<2
int main(){
int *A, *B, *C;
hipDeviceptr Ad, Bd;
int *A, *B;
hipDeviceptr_t Ad, Bd;
A = new int[LEN];
B = new int[LEN];
C = new int[LEN];
for(int i=0;i<LEN;i++){
A[i] = i;
}
hipMalloc((void**)&Ad, SIZE);
hipMalloc((void**)&Bd, SIZE);
hipMemcpyHtoD(Ad, A, SIZE);
hipMemcpyDtoD(Bd, Ad, SIZE);
hipMemcpyDtoH(B, Bd, SIZE);
hipMemcpyHtoH(C, B,SIZE);
for(int i=0;i<16;i++){
std::cout<<A[i]<<" "<<C[i]<<std::endl;
std::cout<<A[i]<<" "<<B[i]<<std::endl;
}
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;
}