Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab910ef

Browse files
committed
hipHostRegister and hipHostMalloc refactor.
Note hipHostMalloc (not hipHostAlloc or hipMallocHost). - the hipHost* is used for all HIP APIs dealing with Host memory. (including hipHostMalloc, hipHostFree, hipHostRegister, hipHostUnregister, hipHostGetFlags, hipHostGetDevicePointer). - hipMallocHost is consistent with "hipMalloc" for allocating device memory. Enumerations hipHostMalloc* also used as optional flags parm to hipHostMalloc.
1 parent 8087bc0 commit ab910ef

17 files changed

Lines changed: 95 additions & 70 deletions

RELEASE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Stay tuned - the work for many of these features is already in-flight.
1515

1616
Next:
1717
- Deprecate hipDeviceGetProp, replace with hipGetDeviceProp
18-
- Deprecate hipMallocHost (Replace with hipHostAlloc with hipHostAllocDefault as last parameter).
18+
- Deprecate hipMallocHost (Replace with hipHostMalloc)
1919
- Deprecate hipFreeHost (Replace with hipHostFree).
2020

2121

bin/hipify

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,15 @@ while (@ARGV) {
283283
#--------
284284
# Memory management:
285285
$ft{'mem'} += s/\bcudaMalloc\b/hipMalloc/g;
286-
$ft{'mem'} += s/\bcudaMallocHost\b/hipMallocHost/g;
286+
$ft{'mem'} += s/\bcudaMallocHost\b/hipHostMalloc/g; # note conversion to standard hipHost* naming convention
287287
$ft{'mem'} += s/\bcudaFree\b/hipFree/g;
288-
$ft{'mem'} += s/\bcudaFreeHost\b/hipFreeHost/g;
288+
$ft{'mem'} += s/\bcudaFreeHost\b/hipHostFree/g; # note conversion to standard hipHost* naming convention
289289
$ft{'mem'} += s/\bcudaHostAlloc\b/hipHostAlloc/g;
290290
$ft{'mem'} += s/\bcudaHostGetDevicePointer\b/hipHostGetDevicePointer/g;
291-
$ft{'mem'} += s/\bcudaHostAllocDefault\b/hipHostAllocDefault/g;
292-
$ft{'mem'} += s/\bcudaHostAllocPortable\b/hipHostAllocPortable/g;
293-
$ft{'mem'} += s/\bcudaHostAllocMapped\b/hipHostAllocMapped/g;
294-
$ft{'mem'} += s/\bcudaHostAllocWriteCombined\b/hipHostAllocWriteCombined/g;
291+
$ft{'mem'} += s/\bcudaHostAllocDefault\b/hipHostMallocDefault/g;
292+
$ft{'mem'} += s/\bcudaHostAllocPortable\b/hipHostMallocPortable/g;
293+
$ft{'mem'} += s/\bcudaHostAllocMapped\b/hipHostMallocMapped/g;
294+
$ft{'mem'} += s/\bcudaHostAllocWriteCombined\b/hipHostMallocWriteCombined/g;
295295

296296

297297
#--------

include/hcc_detail/hip_runtime_api.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ extern "C" {
5656
#define hipEventInterprocess 0x4 ///< Event can support IPC. @warning - not supported in HIP.
5757

5858

59-
#define hipHostAllocDefault 0x0
60-
#define hipHostAllocPortable 0x1
61-
#define hipHostAllocMapped 0x2
62-
#define hipHostAllocWriteCombined 0x4
59+
#define hipHostMallocDefault 0x0
60+
#define hipHostMallocPortable 0x1
61+
#define hipHostMallocMapped 0x2
62+
#define hipHostMallocWriteCombined 0x4
6363

6464
#define hipHostRegisterDefault 0x0
6565
#define hipHostRegisterPortable 0x1
@@ -670,7 +670,7 @@ hipError_t hipMalloc(void** ptr, size_t size) ;
670670
* @param[in] size Requested memory size
671671
* @return Error code
672672
*/
673-
hipError_t hipMallocHost(void** ptr, size_t size) __attribute__((deprecated("use hipHostAlloc instead"))) ;
673+
hipError_t hipMallocHost(void** ptr, size_t size) __attribute__((deprecated("use hipHostMalloc instead"))) ;
674674

675675
/**
676676
* @brief Allocate device accessible page locked host memory
@@ -680,7 +680,8 @@ hipError_t hipMallocHost(void** ptr, size_t size) __attribute__((deprecated("use
680680
* @param[in] flags Type of host memory allocation
681681
* @return Error code
682682
*/
683-
hipError_t hipHostAlloc(void** ptr, size_t size, unsigned int flags) ;
683+
hipError_t hipHostMalloc(void** ptr, size_t size, unsigned int flags) ;
684+
hipError_t hipHostAlloc(void** ptr, size_t size, unsigned int flags) __attribute__((deprecated("use hipHostMalloc instead"))) ;;
684685

685686
/**
686687
* @brief Get Device pointer from Host Pointer allocated through hipHostAlloc
@@ -696,7 +697,7 @@ hipError_t hipHostGetDevicePointer(void** devPtr, void* hstPtr, size_t size) ;
696697
* @brief Get flags associated with host pointer
697698
*
698699
* @param[out] flagsPtr Memory location to store flags
699-
* @param[in] hostPtr Host Pointer allocated through hipHostAlloc
700+
* @param[in] hostPtr Host Pointer allocated through hipHostMalloc
700701
* @return Error code
701702
*/
702703
hipError_t hipHostGetFlags(unsigned int* flagsPtr, void* hostPtr) ;
@@ -786,7 +787,7 @@ hipError_t hipMemcpyToSymbol(const char* symbolName, const void *src, size_t siz
786787
/**
787788
* @brief Copy data from src to dst asynchronously.
788789
*
789-
* @warning If host or dest are not pinned, the memory copy will be performed synchronously. For best performance, use hipHostAlloc to
790+
* @warning If host or dest are not pinned, the memory copy will be performed synchronously. For best performance, use hipHostMalloc to
790791
* allocate host memory that is transferred asynchronously.
791792
*
792793
* @param[out] dst Data being copy to

include/hip_runtime_api.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ static inline hipError_t hipMalloc ( T** devPtr, size_t size)
220220

221221
// Provide an override to automatically typecast the pointer type from void**, and also provide a default for the flags.
222222
template<class T>
223-
static inline hipError_t hipHostAlloc( T** ptr, size_t size, unsigned int flags = hipHostAllocDefault)
223+
static inline hipError_t hipHostMalloc( T** ptr, size_t size, unsigned int flags = hipHostMallocDefault)
224224
{
225-
return hipHostAlloc((void**)ptr, size, flags);
225+
return hipHostMalloc((void**)ptr, size, flags);
226226
}
227227
#endif

include/nvcc_detail/hip_runtime_api.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ inline static hipError_t hipFree(void* ptr) {
119119
return hipCUDAErrorTohipError(cudaFree(ptr));
120120
}
121121

122-
inline static hipError_t hipMallocHost(void** ptr, size_t size) __attribute__((deprecated("use hipHostAlloc instead")));
122+
inline static hipError_t hipMallocHost(void** ptr, size_t size) __attribute__((deprecated("use hipHostMalloc instead")));
123123

124124
inline static hipError_t hipMallocHost(void** ptr, size_t size) {
125125
return hipCUDAErrorTohipError(cudaMallocHost(ptr, size));
126126
}
127127

128-
inline static hipError_t hipHostAlloc(void** ptr, size_t size, unsigned int flags){
128+
inline static hipError_t hipHostMalloc(void** ptr, size_t size, unsigned int flags){
129129
return hipCUDAErrorTohipError(cudaHostAlloc(ptr, size, flags));
130130
}
131131

samples/1_Utils/hipBusBandwidth/hipBusBandwidth.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void RunBenchmark_H2D(ResultDatabase &resultDB)
108108
float *hostMem = NULL;
109109
if (p_pinned)
110110
{
111-
hipHostAlloc((void**)&hostMem, sizeof(float) * numMaxFloats, hipHostAllocDefault);
111+
hipHostMalloc((void**)&hostMem, sizeof(float) * numMaxFloats);
112112
while (hipGetLastError() != hipSuccess)
113113
{
114114
// drop the size and try again
@@ -120,7 +120,7 @@ void RunBenchmark_H2D(ResultDatabase &resultDB)
120120
return;
121121
}
122122
numMaxFloats = 1024 * (sizes[nSizes-1]) / 4;
123-
hipHostAlloc((void**)&hostMem, sizeof(float) * numMaxFloats, hipHostAllocDefault);
123+
hipHostMalloc((void**)&hostMem, sizeof(float) * numMaxFloats);
124124
}
125125
}
126126
else
@@ -232,7 +232,7 @@ void RunBenchmark_H2D(ResultDatabase &resultDB)
232232
CHECK_HIP_ERROR();
233233
if (p_pinned)
234234
{
235-
hipFreeHost((void*)hostMem);
235+
hipHostFree((void*)hostMem);
236236
CHECK_HIP_ERROR();
237237
}
238238
else
@@ -259,15 +259,15 @@ void RunBenchmark_D2H(ResultDatabase &resultDB)
259259
float *hostMem2;
260260
if (p_pinned)
261261
{
262-
hipHostAlloc((void**)&hostMem1, sizeof(float)*numMaxFloats, hipHostAllocDefault);
262+
hipHostMalloc((void**)&hostMem1, sizeof(float)*numMaxFloats);
263263
hipError_t err1 = hipGetLastError();
264-
hipHostAlloc((void**)&hostMem2, sizeof(float)*numMaxFloats, hipHostAllocDefault);
264+
hipHostMalloc((void**)&hostMem2, sizeof(float)*numMaxFloats);
265265
hipError_t err2 = hipGetLastError();
266266
while (err1 != hipSuccess || err2 != hipSuccess)
267267
{
268268
// free the first buffer if only the second failed
269269
if (err1 == hipSuccess)
270-
hipFreeHost((void*)hostMem1);
270+
hipHostFree((void*)hostMem1);
271271

272272
// drop the size and try again
273273
if (p_verbose) std::cout << " - dropping size allocating pinned mem\n";
@@ -383,9 +383,9 @@ void RunBenchmark_D2H(ResultDatabase &resultDB)
383383
CHECK_HIP_ERROR();
384384
if (p_pinned)
385385
{
386-
hipFreeHost((void*)hostMem1);
386+
hipHostFree((void*)hostMem1);
387387
CHECK_HIP_ERROR();
388-
hipFreeHost((void*)hostMem2);
388+
hipHostFree((void*)hostMem2);
389389
CHECK_HIP_ERROR();
390390
}
391391
else
@@ -523,8 +523,8 @@ void RunBenchmark_Bidir(ResultDatabase &resultDB)
523523
CHECK_HIP_ERROR();
524524
if (p_pinned)
525525
{
526-
hipFreeHost((void*)hostMem[0]);
527-
hipFreeHost((void*)hostMem[1]);
526+
hipHostFree((void*)hostMem[0]);
527+
hipHostFree((void*)hostMem[1]);
528528
CHECK_HIP_ERROR();
529529
}
530530
else

src/hip_hcc.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,23 +2085,23 @@ hipError_t hipMallocHost(void** ptr, size_t sizeBytes)
20852085
}
20862086

20872087

2088-
hipError_t hipHostAlloc(void** ptr, size_t sizeBytes, unsigned int flags){
2088+
hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags){
20892089
std::call_once(hip_initialized, ihipInit);
20902090

20912091
hipError_t hip_status = hipSuccess;
20922092

20932093
auto device = ihipGetTlsDefaultDevice();
20942094

20952095
if(device){
2096-
if(flags == hipHostAllocDefault){
2096+
if(flags == hipHostMallocDefault){
20972097
*ptr = hc::am_alloc(sizeBytes, device->_acc, amHostPinned);
20982098
if(sizeBytes && (*ptr == NULL)){
20992099
hip_status = hipErrorMemoryAllocation;
21002100
}else{
21012101
hc::am_memtracker_update(*ptr, device->_device_index, 0);
21022102
}
21032103
tprintf(DB_MEM, " %s: pinned ptr=%p\n", __func__, *ptr);
2104-
} else if(flags & hipHostAllocMapped){
2104+
} else if(flags & hipHostMallocMapped){
21052105
*ptr = hc::am_alloc(sizeBytes, device->_acc, amHostPinned);
21062106
if(sizeBytes && (*ptr == NULL)){
21072107
hip_status = hipErrorMemoryAllocation;
@@ -2115,6 +2115,14 @@ hipError_t hipHostAlloc(void** ptr, size_t sizeBytes, unsigned int flags){
21152115
}
21162116

21172117

2118+
// TODO - remove me, this is deprecated.
2119+
hipError_t hipHostAlloc(void** ptr, size_t sizeBytes, unsigned int flags)
2120+
{
2121+
return hipHostMalloc(ptr, sizeBytes, flags);
2122+
};
2123+
2124+
2125+
21182126
hipError_t hipHostGetDevicePointer(void** devPtr, void* hstPtr, size_t size){
21192127
std::call_once(hip_initialized, ihipInit);
21202128

tests/src/hipHostAlloc.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ if(prop.canMapHostMemory != 1){
4242
//std::cout<<"Exiting..."<<std::endl;
4343
}
4444

45-
HIPCHECK(hipHostAlloc((void**)&A, SIZE, hipHostAllocWriteCombined | hipHostAllocMapped));
46-
HIPCHECK(hipHostAlloc((void**)&B, SIZE, hipHostAllocDefault));
47-
HIPCHECK(hipHostAlloc((void**)&C, SIZE, hipHostAllocMapped));
45+
HIPCHECK(hipHostMalloc((void**)&A, SIZE, hipHostMallocWriteCombined | hipHostMallocMapped));
46+
HIPCHECK(hipHostMalloc((void**)&B, SIZE, hipHostMallocDefault));
47+
HIPCHECK(hipHostMalloc((void**)&C, SIZE, hipHostMallocMapped));
4848

4949
HIPCHECK(hipHostGetDevicePointer((void**)&Ad, A, 0));
5050
HIPCHECK(hipHostGetDevicePointer((void**)&Cd, C, 0));

tests/src/hipHostGetFlags.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ int main(){
3535
float *A, *B, *C, *D;
3636
float *Ad, *Bd, *Cd, *Dd;
3737
unsigned int FlagA, FlagB, FlagC;
38-
FlagA = hipHostAllocWriteCombined | hipHostAllocMapped;
39-
FlagB = hipHostAllocWriteCombined | hipHostAllocMapped;
40-
FlagC = hipHostAllocMapped;
38+
FlagA = hipHostMallocWriteCombined | hipHostMallocMapped;
39+
FlagB = hipHostMallocWriteCombined | hipHostMallocMapped;
40+
FlagC = hipHostMallocMapped;
4141
hipDeviceProp_t prop;
4242
int device;
4343
HIPCHECK(hipGetDevice(&device));
4444
HIPCHECK(hipGetDeviceProperties(&prop, device));
4545
if(prop.canMapHostMemory != 1){
4646
std::cout<<"Exiting..."<<std::endl;
4747
}
48-
HIPCHECK(hipHostAlloc((void**)&A, SIZE, hipHostAllocWriteCombined | hipHostAllocMapped));
49-
HIPCHECK(hipHostAlloc((void**)&B, SIZE, hipHostAllocWriteCombined | hipHostAllocMapped));
50-
HIPCHECK(hipHostAlloc((void**)&C, SIZE, hipHostAllocMapped));
48+
HIPCHECK(hipHostMalloc((void**)&A, SIZE, hipHostMallocWriteCombined | hipHostMallocMapped));
49+
HIPCHECK(hipHostMalloc((void**)&B, SIZE, hipHostMallocWriteCombined | hipHostMallocMapped));
50+
HIPCHECK(hipHostMalloc((void**)&C, SIZE, hipHostMallocMapped));
5151

52-
HIPCHECK(hipHostAlloc((void**)&D, SIZE, hipHostAllocDefault));
52+
HIPCHECK(hipHostMalloc((void**)&D, SIZE, hipHostMallocDefault));
5353

5454
unsigned int flagA, flagB, flagC;
5555

tests/src/hipMemcpy.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void printSep()
3636
// The subroutine allocates memory , copies to device, runs a vector add kernel, copies back, and checks the result.
3737
//
3838
// IN: numElements controls the number of elements used for allocations.
39-
// IN: usePinnedHost : If true, allocate host with hipHostAlloc and is pinned ; else allocate host memory with malloc.
39+
// IN: usePinnedHost : If true, allocate host with hipHostMalloc and is pinned ; else allocate host memory with malloc.
4040
// IN: useHostToHost : If true, add an extra host-to-host copy.
4141
// IN: useDeviceToDevice : If true, add an extra deviceto-device copy after result is produced.
4242
// 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
6767

6868
if (useHostToHost) {
6969
if (usePinnedHost) {
70-
HIPCHECK ( hipHostAlloc((void**)&A_hh, sizeElements, hipHostAllocDefault) );
71-
HIPCHECK ( hipHostAlloc((void**)&B_hh, sizeElements, hipHostAllocDefault) );
70+
HIPCHECK ( hipHostMalloc((void**)&A_hh, sizeElements, hipHostMallocDefault) );
71+
HIPCHECK ( hipHostMalloc((void**)&B_hh, sizeElements, hipHostMallocDefault) );
7272
} else {
7373
A_hh = (T*)malloc(sizeElements);
7474
B_hh = (T*)malloc(sizeElements);

0 commit comments

Comments
 (0)