SWDEV-470372 - Added hipExtHostAlloc API

This change adds a new HIP API `hipExtHostAlloc` which preserves
the functionality of `hipHostMalloc`.

Change-Id: I13504c6fc13465ddd7aed329795bb4f2fef1baff
Этот коммит содержится в:
Ioannis Assiouras
2024-08-01 00:54:31 +01:00
родитель bb52d9ed62
Коммит 2c84211b58
9 изменённых файлов: 71 добавлений и 13 удалений
+1
Просмотреть файл
@@ -478,3 +478,4 @@ hipGraphNodeSetParams
hipGraphExecNodeSetParams
hipDrvGraphMemcpyNodeSetParams
hipDrvGraphMemcpyNodeGetParams
hipExtHostAlloc
+5 -2
Просмотреть файл
@@ -347,6 +347,7 @@ hipError_t hipHostFree(void* ptr);
hipError_t hipHostGetDevicePointer(void** devPtr, void* hstPtr, unsigned int flags);
hipError_t hipHostGetFlags(unsigned int* flagsPtr, void* hostPtr);
hipError_t hipHostMalloc(void** ptr, size_t size, unsigned int flags);
hipError_t hipExtHostAlloc(void** ptr, size_t size, unsigned int flags);
hipError_t hipHostRegister(void* hostPtr, size_t sizeBytes, unsigned int flags);
hipError_t hipHostUnregister(void* hostPtr);
hipError_t hipImportExternalMemory(hipExternalMemory_t* extMem_out,
@@ -1026,6 +1027,7 @@ void UpdateDispatchTable(HipDispatchTable* ptrDispatchTable) {
ptrDispatchTable->hipHostGetDevicePointer_fn = hip::hipHostGetDevicePointer;
ptrDispatchTable->hipHostGetFlags_fn = hip::hipHostGetFlags;
ptrDispatchTable->hipHostMalloc_fn = hip::hipHostMalloc;
ptrDispatchTable->hipExtHostAlloc_fn = hip::hipExtHostAlloc;
ptrDispatchTable->hipHostRegister_fn = hip::hipHostRegister;
ptrDispatchTable->hipHostUnregister_fn = hip::hipHostUnregister;
ptrDispatchTable->hipImportExternalMemory_fn = hip::hipImportExternalMemory;
@@ -1870,6 +1872,7 @@ HIP_ENFORCE_ABI(HipDispatchTable, hipGraphExecNodeSetParams_fn, 457);
HIP_ENFORCE_ABI(HipDispatchTable, hipExternalMemoryGetMappedMipmappedArray_fn, 458)
HIP_ENFORCE_ABI(HipDispatchTable, hipDrvGraphMemcpyNodeGetParams_fn, 459)
HIP_ENFORCE_ABI(HipDispatchTable, hipDrvGraphMemcpyNodeSetParams_fn, 460)
HIP_ENFORCE_ABI(HipDispatchTable, hipExtHostAlloc_fn, 461)
// if HIP_ENFORCE_ABI entries are added for each new function pointer in the table, the number below
// will be +1 of the number in the last HIP_ENFORCE_ABI line. E.g.:
@@ -1877,9 +1880,9 @@ HIP_ENFORCE_ABI(HipDispatchTable, hipDrvGraphMemcpyNodeSetParams_fn, 460)
// HIP_ENFORCE_ABI(<table>, <functor>, 8)
//
// HIP_ENFORCE_ABI_VERSIONING(<table>, 9) <- 8 + 1 = 9
HIP_ENFORCE_ABI_VERSIONING(HipDispatchTable, 461)
HIP_ENFORCE_ABI_VERSIONING(HipDispatchTable, 462)
static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0 && HIP_RUNTIME_API_TABLE_STEP_VERSION == 4,
static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0 && HIP_RUNTIME_API_TABLE_STEP_VERSION == 5,
"If you get this error, add new HIP_ENFORCE_ABI(...) code for the new function "
"pointers and then update this check so it is true");
#endif
+7
Просмотреть файл
@@ -578,3 +578,10 @@ global:
local:
*;
} hip_6.1;
hip_6.3 {
global:
hipExtHostAlloc;
local:
*;
} hip_6.2;
+20 -8
Просмотреть файл
@@ -352,7 +352,7 @@ hipError_t ihipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags)
}
*ptr = nullptr;
const unsigned int coherentFlags = hipHostMallocCoherent | hipHostMallocNonCoherent;
const unsigned int coherentFlags = hipExtHostAllocCoherent | hipExtHostAllocNonCoherent;
// can't have both Coherent and NonCoherent flags set at the same time
if ((flags & coherentFlags) == coherentFlags) {
@@ -365,16 +365,16 @@ hipError_t ihipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags)
unsigned int ihipFlags = CL_MEM_SVM_FINE_GRAIN_BUFFER;
if (flags == 0 ||
flags & (hipHostMallocCoherent | hipHostMallocMapped | hipHostMallocNumaUser) ||
(!(flags & hipHostMallocNonCoherent) && HIP_HOST_COHERENT)) {
flags & (hipExtHostAllocCoherent | hipHostAllocMapped | hipExtHostAllocNumaUser) ||
(!(flags & hipExtHostAllocNonCoherent) && HIP_HOST_COHERENT)) {
ihipFlags |= CL_MEM_SVM_ATOMICS;
}
if (flags & hipHostMallocNumaUser) {
if (flags & hipExtHostAllocNumaUser) {
ihipFlags |= CL_MEM_FOLLOW_USER_NUMA_POLICY;
}
if (flags & hipHostMallocNonCoherent) {
if (flags & hipExtHostAllocNonCoherent) {
ihipFlags &= ~CL_MEM_SVM_ATOMICS;
}
@@ -679,6 +679,16 @@ hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags) {
HIP_RETURN_DURATION(status, *ptr);
}
hipError_t hipExtHostAlloc(void** ptr, size_t sizeBytes, unsigned int flags) {
HIP_INIT_API(hipExtHostAlloc, ptr, sizeBytes, flags);
CHECK_STREAM_CAPTURE_SUPPORTED();
if (ptr == nullptr) {
HIP_RETURN(hipErrorInvalidValue);
}
hipError_t status = ihipHostMalloc(ptr, sizeBytes, flags);
HIP_RETURN_DURATION(status, *ptr);
}
hipError_t hipFree(void* ptr) {
HIP_INIT_API(hipFree, ptr);
CHECK_STREAM_CAPTURE_SUPPORTED();
@@ -1222,7 +1232,8 @@ hipError_t hipHostGetFlags(unsigned int* flagsPtr, void* hostPtr) {
HIP_RETURN(hipErrorInvalidValue);
}
// To match with Nvidia behaviour validate that hostPtr passed was allocated using hipHostMalloc(), and not hipMalloc()
// To match with Nvidia behaviour validate that hostPtr passed
// was allocated using hipHostAlloc(), and not hipMalloc()
if (!(svmMem->getMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) {
HIP_RETURN(hipErrorInvalidValue);
}
@@ -1314,11 +1325,12 @@ hipError_t hipHostUnregister(void* hostPtr) {
hipError_t hipHostAlloc(void** ptr, size_t sizeBytes, unsigned int flags) {
HIP_INIT_API(hipHostAlloc, ptr, sizeBytes, flags);
CHECK_STREAM_CAPTURE_SUPPORTED();
if (ptr == nullptr) {
HIP_RETURN(hipErrorInvalidValue);
}
if (flags > (hipHostMallocPortable | hipHostMallocMapped |
hipHostMallocWriteCombined)) {
if (flags > (hipHostAllocPortable | hipHostAllocMapped |
hipHostAllocWriteCombined)) {
HIP_RETURN(hipErrorInvalidValue);
}
+3
Просмотреть файл
@@ -1805,3 +1805,6 @@ hipError_t hipDrvGraphMemcpyNodeGetParams(hipGraphNode_t hNode, HIP_MEMCPY3D* no
hipError_t hipDrvGraphMemcpyNodeSetParams(hipGraphNode_t hNode, const HIP_MEMCPY3D* nodeParams) {
return hip::GetHipDispatchTable()->hipDrvGraphMemcpyNodeSetParams_fn(hNode, nodeParams);
}
hipError_t hipExtHostAlloc(void** ptr, size_t size, unsigned int flags) {
return hip::GetHipDispatchTable()->hipExtHostAlloc_fn(ptr, size, flags);
}