From bdae5e7544a691e35d6e1ea03cfb2a5f945c34ff Mon Sep 17 00:00:00 2001 From: Nicholas Wilt Date: Fri, 25 Mar 2022 09:37:06 -0500 Subject: [PATCH] Continue porting stream samples to HIP --- chLib/chError.h | 13 +++++++++++++ streaming/stream3Streams.cu | 6 +++--- streaming/stream4Mapped.cu | 10 +++++----- streaming/stream5MappedXfer.cu | 10 +++++----- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/chLib/chError.h b/chLib/chError.h index d0801f4..4c1522e 100644 --- a/chLib/chError.h +++ b/chLib/chError.h @@ -71,21 +71,34 @@ template hipError_t hipHostAlloc( T **pp, size_t N, unsigned int Fla return hipHostMalloc( (void **) pp, N, Flags ); } +template hipError_t hipHostGetDevicePointer( T **pp, void *p, unsigned int Flags ) { + return hipHostGetDevicePointer( (void **) pp, p, Flags ); +} + #endif // entry points #define cudaDeviceMapHost hipDeviceMapHost #define cudaFree hipFree #define cudaHostFree hipHostFree +#define cudaHostGetDevicePointer hipHostGetDevicePointer +#define cudaStreamDestroy hipStreamDestroy #define cudaEventDestroy hipEventDestroy +// data types +typedef hipStream_t cudaStream_t; + +// defines #define cudaMemcpyHostToDevice hipMemcpyHostToDevice #define cudaMemcpyDeviceToHost hipMemcpyDeviceToHost #define cudaMemcpyDeviceToDevice hipMemcpyDeviceToDevice +#define cudaHostAllocMapped 0 + // error defines #define cudaSuccess hipSuccess #define cudaErrorUnknown hipErrorUnknown +#define cudaErrorInvalidValue hipErrorInvalidValue #define cudaErrorMemoryAllocation hipErrorMemoryAllocation #else diff --git a/streaming/stream3Streams.cu b/streaming/stream3Streams.cu index 8c14e92..07fa18b 100644 --- a/streaming/stream3Streams.cu +++ b/streaming/stream3Streams.cu @@ -158,9 +158,9 @@ Error: cudaFree( dptrOut ); cudaFree( dptrX ); cudaFree( dptrY ); - cudaFreeHost( hptrOut ); - cudaFreeHost( hptrX ); - cudaFreeHost( hptrY ); + cudaHostFree( hptrOut ); + cudaHostFree( hptrX ); + cudaHostFree( hptrY ); return status; } diff --git a/streaming/stream4Mapped.cu b/streaming/stream4Mapped.cu index 799bcc2..e30bbf1 100644 --- a/streaming/stream4Mapped.cu +++ b/streaming/stream4Mapped.cu @@ -77,8 +77,8 @@ MeasureTimes( cuda(EventCreate( &evStart ) ); cuda(EventCreate( &evStop ) ); for ( size_t i = 0; i < N; i++ ) { - hptrX[i] = (float) rand() / RAND_MAX; - hptrY[i] = (float) rand() / RAND_MAX; + hptrX[i] = (float) ((double) rand() / RAND_MAX); + hptrY[i] = (float) ((double) rand() / RAND_MAX); } // @@ -107,9 +107,9 @@ MeasureTimes( Error: cudaEventDestroy( evStop ); cudaEventDestroy( evStart ); - cudaFreeHost( hptrOut ); - cudaFreeHost( hptrX ); - cudaFreeHost( hptrY ); + cudaHostFree( hptrOut ); + cudaHostFree( hptrX ); + cudaHostFree( hptrY ); return status; } diff --git a/streaming/stream5MappedXfer.cu b/streaming/stream5MappedXfer.cu index 577aa3d..04ccc29 100644 --- a/streaming/stream5MappedXfer.cu +++ b/streaming/stream5MappedXfer.cu @@ -75,8 +75,8 @@ MeasureTimes( cuda(EventCreate( &evStart ) ); cuda(EventCreate( &evStop ) ); for ( size_t i = 0; i < N; i++ ) { - hptrX[i] = (float) rand() / RAND_MAX; - hptrY[i] = (float) rand() / RAND_MAX; + hptrX[i] = (float) ((double) rand() / RAND_MAX); + hptrY[i] = (float) ((double) rand() / RAND_MAX); } // @@ -107,9 +107,9 @@ Error: cudaEventDestroy( evStop ); cudaEventDestroy( evStart ); cudaFree( dptrOut ); - cudaFreeHost( hptrOut ); - cudaFreeHost( hptrX ); - cudaFreeHost( hptrY ); + cudaHostFree( hptrOut ); + cudaHostFree( hptrX ); + cudaHostFree( hptrY ); return status; }