Re-sync with upstream.
This commit is contained in:
@@ -27,70 +27,6 @@ THE SOFTWARE.
|
||||
#include "hip/hip_runtime.h"
|
||||
#include <atomic>
|
||||
|
||||
//=================================================================================================
|
||||
/*
|
||||
Implementation of malloc and free device functions.
|
||||
|
||||
This is the best place to put them because the device
|
||||
global variables need to be initialized at the start.
|
||||
*/
|
||||
__device__ char gpuHeap[SIZE_OF_HEAP];
|
||||
__device__ uint32_t gpuFlags[NUM_PAGES];
|
||||
|
||||
__device__ void* __hip_hc_malloc(size_t size) {
|
||||
char* heap = (char*)gpuHeap;
|
||||
if (size > SIZE_OF_HEAP) {
|
||||
return (void*)nullptr;
|
||||
}
|
||||
uint32_t totalThreads =
|
||||
blockDim.x * gridDim.x * blockDim.y * gridDim.y * blockDim.z * gridDim.z;
|
||||
uint32_t currentWorkItem = threadIdx.x + blockDim.x * blockIdx.x;
|
||||
|
||||
uint32_t numHeapsPerWorkItem = NUM_PAGES / totalThreads;
|
||||
uint32_t heapSizePerWorkItem = SIZE_OF_HEAP / totalThreads;
|
||||
|
||||
uint32_t stride = size / SIZE_OF_PAGE;
|
||||
uint32_t start = numHeapsPerWorkItem * currentWorkItem;
|
||||
|
||||
uint32_t k = 0;
|
||||
|
||||
while (gpuFlags[k] > 0) {
|
||||
k++;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < stride - 1; i++) {
|
||||
gpuFlags[i + start + k] = 1;
|
||||
}
|
||||
|
||||
gpuFlags[start + stride - 1 + k] = 2;
|
||||
|
||||
void* ptr = (void*)(heap + heapSizePerWorkItem * currentWorkItem + k * SIZE_OF_PAGE);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
__device__ void* __hip_hc_free(void* ptr) {
|
||||
if (ptr == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint32_t offsetByte = (uint64_t)ptr - (uint64_t)gpuHeap;
|
||||
uint32_t offsetPage = offsetByte / SIZE_OF_PAGE;
|
||||
|
||||
while (gpuFlags[offsetPage] != 0) {
|
||||
if (gpuFlags[offsetPage] == 2) {
|
||||
gpuFlags[offsetPage] = 0;
|
||||
offsetPage++;
|
||||
break;
|
||||
} else {
|
||||
gpuFlags[offsetPage] = 0;
|
||||
offsetPage++;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// abort
|
||||
__device__ void abort() { return hc::abort(); }
|
||||
|
||||
|
||||
@@ -29,14 +29,6 @@ THE SOFTWARE.
|
||||
Heap size computation for malloc and free device functions.
|
||||
*/
|
||||
|
||||
#define NUM_PAGES_PER_THREAD 16
|
||||
#define SIZE_OF_PAGE 64
|
||||
#define NUM_THREADS_PER_CU 64
|
||||
#define NUM_CUS_PER_GPU 64 // Specific for r9 Nano
|
||||
#define NUM_PAGES NUM_PAGES_PER_THREAD* NUM_THREADS_PER_CU* NUM_CUS_PER_GPU
|
||||
#define SIZE_MALLOC NUM_PAGES* SIZE_OF_PAGE
|
||||
#define SIZE_OF_HEAP SIZE_MALLOC
|
||||
|
||||
#define HIP_SQRT_2 1.41421356237
|
||||
#define HIP_SQRT_PI 1.77245385091
|
||||
|
||||
@@ -62,9 +54,6 @@ THE SOFTWARE.
|
||||
|
||||
#define HIP_PI 3.14159265358979323846
|
||||
|
||||
__device__ void* __hip_hc_malloc(size_t size);
|
||||
__device__ void* __hip_hc_free(void* ptr);
|
||||
|
||||
__device__ float __hip_erfinvf(float x);
|
||||
__device__ double __hip_erfinv(double x);
|
||||
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ hipError_t hipDeviceGetLimit(size_t* pValue, hipLimit_t limit) {
|
||||
return ihipLogStatus(hipErrorInvalidValue);
|
||||
}
|
||||
if (limit == hipLimitMallocHeapSize) {
|
||||
*pValue = (size_t)SIZE_OF_HEAP;
|
||||
*pValue = (size_t)__HIP_SIZE_OF_HEAP;
|
||||
return ihipLogStatus(hipSuccess);
|
||||
} else {
|
||||
return ihipLogStatus(hipErrorUnsupportedLimit);
|
||||
|
||||
@@ -1543,6 +1543,8 @@ hipError_t ihipMemset(void* dst, int value, size_t sizeBytes, hipStream_t strea
|
||||
{
|
||||
hipError_t e = hipSuccess;
|
||||
|
||||
if (sizeBytes == 0) return e;
|
||||
|
||||
if (stream && (dst != NULL)) {
|
||||
if(copyDataType == ihipMemsetDataTypeChar){
|
||||
if ((sizeBytes & 0x3) == 0) {
|
||||
|
||||
Reference in New Issue
Block a user