Deprecating hipMallocHost to hipHostAlloc

[ROCm/hip commit: cbdc8c277c]
This commit is contained in:
Aditya Atluri
2016-03-15 06:30:16 -05:00
rodzic 0abf5db89e
commit 4c54a8d9d5
7 zmienionych plików z 46 dodań i 46 usunięć
+3 -3
Wyświetl plik
@@ -36,7 +36,7 @@ void printSep()
// The subroutine allocates memory , copies to device, runs a vector add kernel, copies back, and checks the result. // The subroutine allocates memory , copies to device, runs a vector add kernel, copies back, and checks the result.
// //
// IN: numElements controls the number of elements used for allocations. // IN: numElements controls the number of elements used for allocations.
// IN: usePinnedHost : If true, allocate host with hipMallocHost and is pinned ; else allocate host memory with malloc. // IN: usePinnedHost : If true, allocate host with hipHostAlloc and is pinned ; else allocate host memory with malloc.
// IN: useHostToHost : If true, add an extra host-to-host copy. // IN: useHostToHost : If true, add an extra host-to-host copy.
// IN: useDeviceToDevice : If true, add an extra deviceto-device copy after result is produced. // IN: useDeviceToDevice : If true, add an extra deviceto-device copy after result is produced.
// IN: useMemkindDefault : If true, use memkinddefault (runtime figures out direction). if false, use explicit memcpy direction. // IN: useMemkindDefault : If true, use memkinddefault (runtime figures out direction). if false, use explicit memcpy direction.
@@ -67,8 +67,8 @@ void memcpytest2(size_t numElements, bool usePinnedHost, bool useHostToHost, boo
if (useHostToHost) { if (useHostToHost) {
if (usePinnedHost) { if (usePinnedHost) {
HIPCHECK ( hipMallocHost(&A_hh, sizeElements) ); HIPCHECK ( hipHostAlloc((void**)&A_hh, sizeElements, hipHostAllocDefault) );
HIPCHECK ( hipMallocHost(&B_hh, sizeElements) ); HIPCHECK ( hipHostAlloc((void**)&B_hh, sizeElements, hipHostAllocDefault) );
} else { } else {
A_hh = (T*)malloc(sizeElements); A_hh = (T*)malloc(sizeElements);
B_hh = (T*)malloc(sizeElements); B_hh = (T*)malloc(sizeElements);
@@ -33,7 +33,7 @@ void simpleNegTest()
size_t Nbytes = N*sizeof(float); size_t Nbytes = N*sizeof(float);
A_malloc = (float*)malloc(Nbytes); A_malloc = (float*)malloc(Nbytes);
HIPCHECK(hipMallocHost(&A_pinned, Nbytes)); HIPCHECK(hipHostAlloc((void**)&A_pinned, Nbytes, hipHostAllocDefault));
HIPCHECK(hipMalloc(&A_d, Nbytes)); HIPCHECK(hipMalloc(&A_d, Nbytes));
@@ -61,7 +61,7 @@ struct HostTraits<Pinned>
static void *Alloc(size_t sizeBytes) { static void *Alloc(size_t sizeBytes) {
void *p; void *p;
HIPCHECK(hipMallocHost(&p, sizeBytes)); HIPCHECK(hipHostAlloc((void**)&p, sizeBytes, hipHostAllocDefault));
return p; return p;
}; };
}; };
@@ -181,8 +181,8 @@ void test_manyInflightCopies(hipStream_t stream, int numElements, int numCopies,
T *A_d; T *A_d;
T *A_h1, *A_h2; T *A_h1, *A_h2;
HIPCHECK(hipMallocHost(&A_h1, Nbytes)); HIPCHECK(hipHostAlloc((void**)&A_h1, Nbytes, hipHostAllocDefault));
HIPCHECK(hipMallocHost(&A_h2, Nbytes)); HIPCHECK(hipHostAlloc((void**)&A_h2, Nbytes, hipHostAllocDefault));
HIPCHECK(hipMalloc(&A_d, Nbytes)); HIPCHECK(hipMalloc(&A_d, Nbytes));
for (int i=0; i<numElements; i++) { for (int i=0; i<numElements; i++) {
@@ -67,8 +67,8 @@ void simpleTest2(size_t numElements, bool usePinnedHost)
T *A_d, *A_h1, *A_h2; T *A_d, *A_h1, *A_h2;
if (usePinnedHost) { if (usePinnedHost) {
HIPCHECK ( hipMallocHost(&A_h1, sizeElements) ); HIPCHECK ( hipHostAlloc((void**)&A_h1, sizeElements, hipHostAllocDefault) );
HIPCHECK ( hipMallocHost(&A_h2, sizeElements) ); HIPCHECK ( hipHostAlloc((void**)&A_h2, sizeElements, hipHostAllocDefault) );
} else { } else {
A_h1 = (T*)malloc(sizeElements); A_h1 = (T*)malloc(sizeElements);
A_h2 = (T*)malloc(sizeElements); A_h2 = (T*)malloc(sizeElements);
@@ -34,21 +34,21 @@ Array[tx] = Array[tx] + T(1);
void run1(size_t size, hipStream_t stream){ void run1(size_t size, hipStream_t stream){
float *Ah, *Bh, *Cd, *Dd, *Eh; float *Ah, *Bh, *Cd, *Dd, *Eh;
hipMallocHost(&Ah, size); HIPCHECK(hipHostAlloc((void**)&Ah, size, hipHostAllocDefault));
hipMallocHost(&Bh, size); HIPCHECK(hipHostAlloc((void**)&Bh, size, hipHostAllocDefault));
hipMalloc(&Cd, size); HIPCHECK(hipMalloc(&Cd, size));
hipMalloc(&Dd, size); HIPCHECK(hipMalloc(&Dd, size));
hipMallocHost(&Eh, size); HIPCHECK(hipHostAlloc((void**)&Eh, size, hipHostAllocDefault));
for(int i=0;i<N;i++){ for(int i=0;i<N;i++){
Ah[i] = 1.0f; Ah[i] = 1.0f;
} }
hipMemcpyAsync(Bh, Ah, size, hipMemcpyHostToHost, stream); HIPCHECK(hipMemcpyAsync(Bh, Ah, size, hipMemcpyHostToHost, stream));
hipMemcpyAsync(Cd, Bh, size, hipMemcpyHostToDevice, stream); HIPCHECK(hipMemcpyAsync(Cd, Bh, size, hipMemcpyHostToDevice, stream));
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N/500), dim3(500), 0, stream, Cd); hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N/500), dim3(500), 0, stream, Cd);
hipMemcpyAsync(Dd, Cd, size, hipMemcpyDeviceToDevice, stream); HIPCHECK(hipMemcpyAsync(Dd, Cd, size, hipMemcpyDeviceToDevice, stream));
hipMemcpyAsync(Eh, Dd, size, hipMemcpyDeviceToHost, stream); HIPCHECK(hipMemcpyAsync(Eh, Dd, size, hipMemcpyDeviceToHost, stream));
HIPCHECK(hipDeviceSynchronize()); HIPCHECK(hipDeviceSynchronize());
HIPASSERT(Eh[10] == Ah[10] + 1.0f); HIPASSERT(Eh[10] == Ah[10] + 1.0f);
} }
@@ -58,27 +58,27 @@ void run(size_t size, hipStream_t stream1, hipStream_t stream2){
float *Ah, *Bh, *Cd, *Dd, *Eh; float *Ah, *Bh, *Cd, *Dd, *Eh;
float *Ahh, *Bhh, *Cdd, *Ddd, *Ehh; float *Ahh, *Bhh, *Cdd, *Ddd, *Ehh;
hipMallocHost(&Ah, size); HIPCHECK(hipHostAlloc((void**)&Ah, size, hipHostAllocDefault));
hipMallocHost(&Bh, size); HIPCHECK(hipHostAlloc((void**)&Bh, size, hipHostAllocDefault));
hipMalloc(&Cd, size); HIPCHECK(hipMalloc(&Cd, size));
hipMalloc(&Dd, size); HIPCHECK(hipMalloc(&Dd, size));
hipMallocHost(&Eh, size); HIPCHECK(hipHostAlloc((void**)&Eh, size, hipHostAllocDefault));
hipMallocHost(&Ahh, size); HIPCHECK(hipHostAlloc((void**)&Ahh, size, hipHostAllocDefault));
hipMallocHost(&Bhh, size); HIPCHECK(hipHostAlloc((void**)&Bhh, size, hipHostAllocDefault));
hipMalloc(&Cdd, size); HIPCHECK(hipMalloc(&Cdd, size));
hipMalloc(&Ddd, size); HIPCHECK(hipMalloc(&Ddd, size));
hipMallocHost(&Ehh, size); HIPCHECK(hipHostAlloc((void**)&Ehh, size, hipHostAllocDefault));
hipMemcpyAsync(Bh, Ah, size, hipMemcpyHostToHost, stream1); HIPCHECK(hipMemcpyAsync(Bh, Ah, size, hipMemcpyHostToHost, stream1));
hipMemcpyAsync(Bhh, Ahh, size, hipMemcpyHostToHost, stream2); HIPCHECK(hipMemcpyAsync(Bhh, Ahh, size, hipMemcpyHostToHost, stream2));
hipMemcpyAsync(Cd, Bh, size, hipMemcpyHostToDevice, stream1); HIPCHECK(hipMemcpyAsync(Cd, Bh, size, hipMemcpyHostToDevice, stream1));
hipMemcpyAsync(Cdd, Bhh, size, hipMemcpyHostToDevice, stream2); HIPCHECK(hipMemcpyAsync(Cdd, Bhh, size, hipMemcpyHostToDevice, stream2));
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N/500), dim3(500), 0, stream1, Cd); hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N/500), dim3(500), 0, stream1, Cd);
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N/500), dim3(500), 0, stream2, Cdd); hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N/500), dim3(500), 0, stream2, Cdd);
hipMemcpyAsync(Dd, Cd, size, hipMemcpyDeviceToDevice, stream1); HIPCHECK(hipMemcpyAsync(Dd, Cd, size, hipMemcpyDeviceToDevice, stream1));
hipMemcpyAsync(Ddd, Cdd, size, hipMemcpyDeviceToDevice, stream2); HIPCHECK(hipMemcpyAsync(Ddd, Cdd, size, hipMemcpyDeviceToDevice, stream2));
hipMemcpyAsync(Eh, Dd, size, hipMemcpyDeviceToHost, stream1); HIPCHECK(hipMemcpyAsync(Eh, Dd, size, hipMemcpyDeviceToHost, stream1));
hipMemcpyAsync(Ehh, Ddd, size, hipMemcpyDeviceToHost, stream2); HIPCHECK(hipMemcpyAsync(Ehh, Ddd, size, hipMemcpyDeviceToHost, stream2));
HIPCHECK(hipDeviceSynchronize()); HIPCHECK(hipDeviceSynchronize());
HIPASSERT(Eh[10] = Ah[10] + 1.0f); HIPASSERT(Eh[10] = Ah[10] + 1.0f);
HIPASSERT(Ehh[10] = Ahh[10] + 1.0f); HIPASSERT(Ehh[10] = Ahh[10] + 1.0f);
@@ -115,7 +115,7 @@ void testSimple()
hipError_t e; hipError_t e;
HIPCHECK ( hipMalloc(&A_d, Nbytes) ); HIPCHECK ( hipMalloc(&A_d, Nbytes) );
HIPCHECK ( hipMallocHost(&A_Pinned_h, Nbytes) ); HIPCHECK ( hipHostAlloc((void**)&A_Pinned_h, Nbytes, hipHostAllocDefault) );
A_OSAlloc_h = (char*)malloc(Nbytes); A_OSAlloc_h = (char*)malloc(Nbytes);
size_t free, total; size_t free, total;
@@ -168,7 +168,7 @@ void testSimple()
// Device-visible host memory // Device-visible host memory
printf ("\nDevice-visible host memory (hipMallocHost)\n"); printf ("\nDevice-visible host memory (hipHostAlloc)\n");
HIPCHECK( hipPointerGetAttributes(&attribs, A_Pinned_h)); HIPCHECK( hipPointerGetAttributes(&attribs, A_Pinned_h));
printf("getAttr:%-20s", "A_pinned_h"); printAttribs(&attribs); printf("getAttr:%-20s", "A_pinned_h"); printAttribs(&attribs);
@@ -277,13 +277,13 @@ void clusterAllocs(int numAllocs, size_t minSize, size_t maxSize)
void * ptr; void * ptr;
if (isDevice) { if (isDevice) {
totalDeviceAllocated[reference[i]._attrib.device] += reference[i]._sizeBytes; totalDeviceAllocated[reference[i]._attrib.device] += reference[i]._sizeBytes;
HIPCHECK(hipMalloc(&ptr, reference[i]._sizeBytes)); HIPCHECK(hipHostAlloc((void**)&ptr, reference[i]._sizeBytes, hipHostAllocDefault));
reference[i]._attrib.memoryType = hipMemoryTypeDevice; reference[i]._attrib.memoryType = hipMemoryTypeDevice;
reference[i]._attrib.devicePointer = ptr; reference[i]._attrib.devicePointer = ptr;
reference[i]._attrib.hostPointer = NULL; reference[i]._attrib.hostPointer = NULL;
reference[i]._attrib.allocationFlags = 0; // TODO-randomize these. reference[i]._attrib.allocationFlags = 0; // TODO-randomize these.
} else { } else {
HIPCHECK(hipMallocHost(&ptr, reference[i]._sizeBytes)); HIPCHECK(hipHostAlloc((void**)&ptr, reference[i]._sizeBytes, hipHostAllocDefault));
reference[i]._attrib.memoryType = hipMemoryTypeHost; reference[i]._attrib.memoryType = hipMemoryTypeHost;
reference[i]._attrib.devicePointer = ptr; reference[i]._attrib.devicePointer = ptr;
reference[i]._attrib.hostPointer = ptr; reference[i]._attrib.hostPointer = ptr;
+2 -2
Wyświetl plik
@@ -85,7 +85,7 @@ void initArrays(T **Ad, T **Ah,
HIPCHECK( hipMalloc(Ad, NBytes)); HIPCHECK( hipMalloc(Ad, NBytes));
} }
if(usePinnedHost){ if(usePinnedHost){
HIPCHECK( hipMallocHost(Ah, NBytes)); HIPCHECK( hipHostAlloc((void**)Ah, NBytes, hipHostAllocDefault));
} }
else{ else{
*Ah = new T[N]; *Ah = new T[N];
@@ -102,7 +102,7 @@ void initArrays(T **Ad, size_t N,
HIPCHECK( hipMalloc(Ad, NBytes)); HIPCHECK( hipMalloc(Ad, NBytes));
}else{ }else{
if(usePinnedHost){ if(usePinnedHost){
HIPCHECK(hipMallocHost(Ad, NBytes)); HIPCHECK(hipHostAlloc((void**)Ad, NBytes, hipHostAllocDefault));
}else{ }else{
*Ad = new T[N]; *Ad = new T[N];
HIPASSERT(*Ad != NULL); HIPASSERT(*Ad != NULL);
+4 -4
Wyświetl plik
@@ -141,13 +141,13 @@ void initArrays(T **A_d, T **B_d, T **C_d,
if (usePinnedHost) { if (usePinnedHost) {
if (A_h) { if (A_h) {
HIPCHECK ( hipMallocHost(A_h, Nbytes) ); HIPCHECK ( hipHostAlloc((void**)A_h, Nbytes, hipHostAllocDefault) );
} }
if (B_h) { if (B_h) {
HIPCHECK ( hipMallocHost(B_h, Nbytes) ); HIPCHECK ( hipHostAlloc((void**)B_h, Nbytes, hipHostAllocDefault) );
} }
if (C_h) { if (C_h) {
HIPCHECK ( hipMallocHost(C_h, Nbytes) ); HIPCHECK ( hipHostAlloc((void**)C_h, Nbytes, hipHostAllocDefault) );
} }
} else { } else {
if (A_h) { if (A_h) {
@@ -258,7 +258,7 @@ struct Pinned {
static void *Alloc(size_t sizeBytes) static void *Alloc(size_t sizeBytes)
{ {
void *p; void *p;
HIPCHECK(hipMallocHost(&p, sizeBytes)); HIPCHECK(hipHostAlloc((void**)&p, sizeBytes, hipHostAllocDefault));
return p; return p;
}; };
}; };