SWDEV-470698 - fix formatting, add format check workflow (#657)
This commit is contained in:
کامیت شده توسط
GitHub
والد
5840940caa
کامیت
f7338717ae
@@ -20,8 +20,7 @@ THE SOFTWARE.
|
||||
#include "deviceAllocCommon.h"
|
||||
|
||||
__device__ static void* dev_mem_glob;
|
||||
__device__ struct deviceAllocFunc allocfunc{&deviceAlloc, &deviceWrite,
|
||||
&deviceFree};
|
||||
__device__ struct deviceAllocFunc allocfunc{&deviceAlloc, &deviceWrite, &deviceFree};
|
||||
__device__ class derivedAlloc classalloc;
|
||||
constexpr auto num_threads = 5;
|
||||
static bool thread_results[num_threads];
|
||||
@@ -32,15 +31,15 @@ __device__ static void* dev_ptr[num_threads][GRIDSIZE];
|
||||
* of every block.
|
||||
*/
|
||||
template <typename T>
|
||||
static __global__ void kerTestDynamicAllocInAllThread(T *outputBuf,
|
||||
int test_type, T value, size_t perThreadSize) {
|
||||
static __global__ void kerTestDynamicAllocInAllThread(T* outputBuf, int test_type, T value,
|
||||
size_t perThreadSize) {
|
||||
int myId = threadIdx.x + blockDim.x * blockIdx.x;
|
||||
// Allocate
|
||||
size_t size = 0;
|
||||
T* ptr = nullptr;
|
||||
if (test_type == TEST_MALLOC_FREE) {
|
||||
size = perThreadSize * sizeof(T);
|
||||
ptr = reinterpret_cast<T*> (malloc(size));
|
||||
ptr = reinterpret_cast<T*>(malloc(size));
|
||||
} else {
|
||||
size = perThreadSize;
|
||||
ptr = new T[perThreadSize];
|
||||
@@ -55,7 +54,7 @@ static __global__ void kerTestDynamicAllocInAllThread(T *outputBuf,
|
||||
}
|
||||
// Copy to output buffer
|
||||
for (size_t idx = 0; idx < perThreadSize; idx++) {
|
||||
outputBuf[myId*perThreadSize + idx] = ptr[idx];
|
||||
outputBuf[myId * perThreadSize + idx] = ptr[idx];
|
||||
}
|
||||
// Free memory
|
||||
if (test_type == TEST_MALLOC_FREE) {
|
||||
@@ -69,10 +68,9 @@ static __global__ void kerTestDynamicAllocInAllThread(T *outputBuf,
|
||||
* This kernel allocates and deallocates using virtual functions in every
|
||||
* thread of every block.
|
||||
*/
|
||||
static __global__ void kerTestDynamicAllocVirtualFunc(int *outputBuf,
|
||||
size_t perThreadSize) {
|
||||
static __global__ void kerTestDynamicAllocVirtualFunc(int* outputBuf, size_t perThreadSize) {
|
||||
int myId = threadIdx.x + blockDim.x * blockIdx.x;
|
||||
baseAlloc *palloc = &classalloc;
|
||||
baseAlloc* palloc = &classalloc;
|
||||
// Allocate
|
||||
int* ptr = palloc->alloc(perThreadSize);
|
||||
|
||||
@@ -86,7 +84,7 @@ static __global__ void kerTestDynamicAllocVirtualFunc(int *outputBuf,
|
||||
}
|
||||
// Copy to output buffer
|
||||
for (size_t idx = 0; idx < perThreadSize; idx++) {
|
||||
outputBuf[myId*perThreadSize + idx] = ptr[idx];
|
||||
outputBuf[myId * perThreadSize + idx] = ptr[idx];
|
||||
}
|
||||
// Free memory
|
||||
palloc->free(ptr);
|
||||
@@ -98,18 +96,16 @@ static __global__ void kerTestDynamicAllocVirtualFunc(int *outputBuf,
|
||||
* data to host and frees the memory in another thread.
|
||||
*/
|
||||
template <typename T>
|
||||
static __global__ void kerTestAccessInAllThreadsInBlock(T *outputBuf,
|
||||
int test_type, T value, int host_thr_idx) {
|
||||
static __global__ void kerTestAccessInAllThreadsInBlock(T* outputBuf, int test_type, T value,
|
||||
int host_thr_idx) {
|
||||
int myThreadId = threadIdx.x, lastThreadId = (blockDim.x - 1);
|
||||
int myId = threadIdx.x + blockDim.x * blockIdx.x;
|
||||
// Allocate memory in thread 0
|
||||
if (0 == myThreadId) {
|
||||
if (test_type == TEST_MALLOC_FREE) {
|
||||
dev_ptr[host_thr_idx][blockIdx.x] =
|
||||
reinterpret_cast<void*> (malloc(blockDim.x*sizeof(T)));
|
||||
dev_ptr[host_thr_idx][blockIdx.x] = reinterpret_cast<void*>(malloc(blockDim.x * sizeof(T)));
|
||||
} else {
|
||||
dev_ptr[host_thr_idx][blockIdx.x] =
|
||||
reinterpret_cast<void*> (new T[blockDim.x]);
|
||||
dev_ptr[host_thr_idx][blockIdx.x] = reinterpret_cast<void*>(new T[blockDim.x]);
|
||||
}
|
||||
}
|
||||
// All threads wait at this barrier
|
||||
@@ -119,7 +115,7 @@ static __global__ void kerTestAccessInAllThreadsInBlock(T *outputBuf,
|
||||
printf("Device Allocation Failed in thread = %d \n", myId);
|
||||
return;
|
||||
}
|
||||
T *ptr = reinterpret_cast<T*> (dev_ptr[host_thr_idx][blockIdx.x]);
|
||||
T* ptr = reinterpret_cast<T*>(dev_ptr[host_thr_idx][blockIdx.x]);
|
||||
// Copy to buffer
|
||||
ptr[myThreadId] = value;
|
||||
// All threads wait
|
||||
@@ -207,18 +203,15 @@ static __global__ void kerTestAccessInAllThreads_CmplxStr(int test_type, int* re
|
||||
* access/modifies it in all threads of block and copies
|
||||
* data to host and frees the memory in another thread.
|
||||
*/
|
||||
static __global__ void kerTestAccessInAllThreadsForUnion(
|
||||
testInfoUnion *outputBuf, int test_type) {
|
||||
static __global__ void kerTestAccessInAllThreadsForUnion(testInfoUnion* outputBuf, int test_type) {
|
||||
int myThreadId = threadIdx.x, lastThreadId = (blockDim.x - 1);
|
||||
int myId = threadIdx.x + blockDim.x * blockIdx.x;
|
||||
// Allocate memory in thread 0
|
||||
if (0 == myThreadId) {
|
||||
if (test_type == TEST_MALLOC_FREE) {
|
||||
dev_ptr[0][blockIdx.x] =
|
||||
reinterpret_cast<void*> (malloc(blockDim.x*sizeof(testInfoUnion)));
|
||||
dev_ptr[0][blockIdx.x] = reinterpret_cast<void*>(malloc(blockDim.x * sizeof(testInfoUnion)));
|
||||
} else {
|
||||
dev_ptr[0][blockIdx.x] =
|
||||
reinterpret_cast<void*> (new testInfoUnion[blockDim.x]);
|
||||
dev_ptr[0][blockIdx.x] = reinterpret_cast<void*>(new testInfoUnion[blockDim.x]);
|
||||
}
|
||||
}
|
||||
// All threads wait at this barrier
|
||||
@@ -228,15 +221,24 @@ static __global__ void kerTestAccessInAllThreadsForUnion(
|
||||
printf("Device Allocation Failed in thread = %d \n", myId);
|
||||
return;
|
||||
}
|
||||
testInfoUnion *ptr =
|
||||
reinterpret_cast<testInfoUnion*> (dev_ptr[0][blockIdx.x]);
|
||||
testInfoUnion* ptr = reinterpret_cast<testInfoUnion*>(dev_ptr[0][blockIdx.x]);
|
||||
// Copy to buffer
|
||||
switch (myId % 5) {
|
||||
case 0: ptr[myThreadId].ival = INT_MAX; break;
|
||||
case 1: ptr[myThreadId].dval = DBL_MAX; break;
|
||||
case 2: ptr[myThreadId].fval = FLT_MAX; break;
|
||||
case 3: ptr[myThreadId].sval = SHRT_MAX; break;
|
||||
case 4: ptr[myThreadId].cval = SCHAR_MAX; break;
|
||||
case 0:
|
||||
ptr[myThreadId].ival = INT_MAX;
|
||||
break;
|
||||
case 1:
|
||||
ptr[myThreadId].dval = DBL_MAX;
|
||||
break;
|
||||
case 2:
|
||||
ptr[myThreadId].fval = FLT_MAX;
|
||||
break;
|
||||
case 3:
|
||||
ptr[myThreadId].sval = SHRT_MAX;
|
||||
break;
|
||||
case 4:
|
||||
ptr[myThreadId].cval = SCHAR_MAX;
|
||||
break;
|
||||
}
|
||||
// All threads wait
|
||||
__syncthreads();
|
||||
@@ -256,17 +258,14 @@ static __global__ void kerTestAccessInAllThreadsForUnion(
|
||||
/**
|
||||
* This kernel allocates memory in one thread.
|
||||
*/
|
||||
template <typename T>
|
||||
static __global__ void kerAlloc(int test_type) {
|
||||
template <typename T> static __global__ void kerAlloc(int test_type) {
|
||||
int myId = threadIdx.x + blockDim.x * blockIdx.x;
|
||||
// Allocate memory in thread 0 of block 0
|
||||
if (0 == myId) {
|
||||
if (test_type == TEST_MALLOC_FREE) {
|
||||
dev_mem_glob =
|
||||
reinterpret_cast<void*> (malloc(blockDim.x*gridDim.x*sizeof(T)));
|
||||
dev_mem_glob = reinterpret_cast<void*>(malloc(blockDim.x * gridDim.x * sizeof(T)));
|
||||
} else {
|
||||
dev_mem_glob =
|
||||
reinterpret_cast<void*> (new T[blockDim.x*gridDim.x]);
|
||||
dev_mem_glob = reinterpret_cast<void*>(new T[blockDim.x * gridDim.x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -274,15 +273,14 @@ static __global__ void kerAlloc(int test_type) {
|
||||
/**
|
||||
* This kernel writes to memory allocated in <kerAlloc>.
|
||||
*/
|
||||
template <typename T>
|
||||
static __global__ void kerWrite(T value) {
|
||||
template <typename T> static __global__ void kerWrite(T value) {
|
||||
int myId = threadIdx.x + blockDim.x * blockIdx.x;
|
||||
// Check allocated memory in all threads in block before access
|
||||
if (dev_mem_glob == nullptr) {
|
||||
printf("Device Allocation Failed in thread = %d \n", myId);
|
||||
return;
|
||||
}
|
||||
T *ptr = reinterpret_cast<T*> (dev_mem_glob);
|
||||
T* ptr = reinterpret_cast<T*>(dev_mem_glob);
|
||||
// Copy to buffer
|
||||
ptr[myId] = value;
|
||||
}
|
||||
@@ -291,8 +289,7 @@ static __global__ void kerWrite(T value) {
|
||||
* This kernel copies the contents of memory allocated in <kerAlloc>
|
||||
* to host and deletes the memory from thread 0.
|
||||
*/
|
||||
template <typename T>
|
||||
static __global__ void kerFree(T *outputBuf, int test_type) {
|
||||
template <typename T> static __global__ void kerFree(T* outputBuf, int test_type) {
|
||||
int myId = threadIdx.x + blockDim.x * blockIdx.x;
|
||||
// Check allocated memory in all threads in block before access
|
||||
if (dev_mem_glob == nullptr) {
|
||||
@@ -300,9 +297,9 @@ static __global__ void kerFree(T *outputBuf, int test_type) {
|
||||
return;
|
||||
}
|
||||
|
||||
T *ptr = reinterpret_cast<T*> (dev_mem_glob);
|
||||
T* ptr = reinterpret_cast<T*>(dev_mem_glob);
|
||||
if (0 == myId) {
|
||||
for (size_t idx = 0; idx < (blockDim.x*gridDim.x); idx++) {
|
||||
for (size_t idx = 0; idx < (blockDim.x * gridDim.x); idx++) {
|
||||
outputBuf[idx] = ptr[idx];
|
||||
}
|
||||
if (test_type == TEST_MALLOC_FREE) {
|
||||
@@ -317,13 +314,11 @@ static __global__ void kerFree(T *outputBuf, int test_type) {
|
||||
* This device function allocates memory in one thread.
|
||||
*/
|
||||
static __device__ int* deviceAlloc(int test_type) {
|
||||
int *ptr = nullptr;
|
||||
int* ptr = nullptr;
|
||||
if (test_type == TEST_MALLOC_FREE) {
|
||||
ptr =
|
||||
reinterpret_cast<int*> (malloc(INTERNAL_BUFFER_SIZE*sizeof(int)));
|
||||
ptr = reinterpret_cast<int*>(malloc(INTERNAL_BUFFER_SIZE * sizeof(int)));
|
||||
} else {
|
||||
ptr =
|
||||
reinterpret_cast<int*> (new int[INTERNAL_BUFFER_SIZE]);
|
||||
ptr = reinterpret_cast<int*>(new int[INTERNAL_BUFFER_SIZE]);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
@@ -331,7 +326,7 @@ static __device__ int* deviceAlloc(int test_type) {
|
||||
/**
|
||||
* This device function writes to memory allocated in deviceAlloc().
|
||||
*/
|
||||
static __device__ void deviceWrite(int myId, int *devmem) {
|
||||
static __device__ void deviceWrite(int myId, int* devmem) {
|
||||
// Check allocated memory in all threads in block before access
|
||||
if (devmem == nullptr) {
|
||||
printf("Device Allocation Failed in thread = %d \n", myId);
|
||||
@@ -347,15 +342,14 @@ static __device__ void deviceWrite(int myId, int *devmem) {
|
||||
* This device function copies the contents of memory allocated
|
||||
* in deviceAlloc() to host and deletes the memory from thread 0.
|
||||
*/
|
||||
static __device__ void deviceFree(int *outputBuf, int *devmem,
|
||||
int test_type, int myId) {
|
||||
static __device__ void deviceFree(int* outputBuf, int* devmem, int test_type, int myId) {
|
||||
// Check allocated memory in all threads in block before access
|
||||
if (devmem == nullptr) {
|
||||
printf("Device Allocation Failed in thread = %d \n", myId);
|
||||
return;
|
||||
}
|
||||
for (size_t idx = 0; idx < INTERNAL_BUFFER_SIZE; idx++) {
|
||||
outputBuf[myId*INTERNAL_BUFFER_SIZE + idx] = devmem[idx];
|
||||
outputBuf[myId * INTERNAL_BUFFER_SIZE + idx] = devmem[idx];
|
||||
}
|
||||
if (test_type == TEST_MALLOC_FREE) {
|
||||
free(devmem);
|
||||
@@ -367,11 +361,10 @@ static __device__ void deviceFree(int *outputBuf, int *devmem,
|
||||
/**
|
||||
* This kernel invokes __device__ allocation functions via pointers.
|
||||
*/
|
||||
static __global__ void kerTestAllocationUsingDevFunc(int *outputBuf,
|
||||
int test_type) {
|
||||
static __global__ void kerTestAllocationUsingDevFunc(int* outputBuf, int test_type) {
|
||||
int myId = threadIdx.x + blockDim.x * blockIdx.x;
|
||||
struct deviceAllocFunc *func = &allocfunc;
|
||||
int *dev_ptr = nullptr;
|
||||
struct deviceAllocFunc* func = &allocfunc;
|
||||
int* dev_ptr = nullptr;
|
||||
dev_ptr = func->alloc(test_type);
|
||||
func->write(myId, dev_ptr);
|
||||
func->free(outputBuf, dev_ptr, test_type, myId);
|
||||
@@ -383,20 +376,18 @@ static __global__ void kerTestAllocationUsingDevFunc(int *outputBuf,
|
||||
* to host to validate.
|
||||
*/
|
||||
template <typename T>
|
||||
static bool TestAllocInAllThread(int test_type,
|
||||
T value, size_t sizeBufferPerThread) {
|
||||
static bool TestAllocInAllThread(int test_type, T value, size_t sizeBufferPerThread) {
|
||||
T *outputVec_d{nullptr}, *outputVec_h{nullptr};
|
||||
size_t arraysize = (sizeBufferPerThread * BLOCKSIZE * GRIDSIZE);
|
||||
outputVec_h = reinterpret_cast<T*> (malloc(sizeof(T) * arraysize));
|
||||
outputVec_h = reinterpret_cast<T*>(malloc(sizeof(T) * arraysize));
|
||||
REQUIRE(outputVec_h != nullptr);
|
||||
HIP_CHECK(hipMalloc(&outputVec_d, (sizeof(T) * arraysize)));
|
||||
// Launch Test Kernel
|
||||
kerTestDynamicAllocInAllThread<T><<<GRIDSIZE, BLOCKSIZE>>>(
|
||||
outputVec_d, test_type, value, sizeBufferPerThread);
|
||||
kerTestDynamicAllocInAllThread<T>
|
||||
<<<GRIDSIZE, BLOCKSIZE>>>(outputVec_d, test_type, value, sizeBufferPerThread);
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
// Copy to host buffer
|
||||
HIP_CHECK(hipMemcpy(outputVec_h, outputVec_d, sizeof(T) * arraysize,
|
||||
hipMemcpyDefault));
|
||||
HIP_CHECK(hipMemcpy(outputVec_h, outputVec_d, sizeof(T) * arraysize, hipMemcpyDefault));
|
||||
bool bPassed = true;
|
||||
for (size_t idx = 0; idx < arraysize; idx++) {
|
||||
if (outputVec_h[idx] != value) {
|
||||
@@ -414,21 +405,19 @@ static bool TestAllocInAllThread(int test_type,
|
||||
* launches kerTestAccessInAllThreadsInBlock<<<>>> and copies data back
|
||||
* to host to validate.
|
||||
*/
|
||||
template <typename T>
|
||||
static bool TestMemoryAccessInAllThread(int test_type, int thread_idx) {
|
||||
template <typename T> static bool TestMemoryAccessInAllThread(int test_type, int thread_idx) {
|
||||
T *outputVec_d{nullptr}, *outputVec_h{nullptr};
|
||||
size_t arraysize = (BLOCKSIZE * GRIDSIZE);
|
||||
T data_value = std::numeric_limits<T>::max();
|
||||
outputVec_h = reinterpret_cast<T*> (malloc(sizeof(T) * arraysize));
|
||||
outputVec_h = reinterpret_cast<T*>(malloc(sizeof(T) * arraysize));
|
||||
REQUIRE(outputVec_h != nullptr);
|
||||
HIP_CHECK(hipMalloc(&outputVec_d, (sizeof(T) * arraysize)));
|
||||
// Launch Test Kernel
|
||||
kerTestAccessInAllThreadsInBlock<T><<<GRIDSIZE, BLOCKSIZE>>>(outputVec_d,
|
||||
test_type, data_value, thread_idx);
|
||||
kerTestAccessInAllThreadsInBlock<T>
|
||||
<<<GRIDSIZE, BLOCKSIZE>>>(outputVec_d, test_type, data_value, thread_idx);
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
// Copy to host buffer
|
||||
HIP_CHECK(hipMemcpy(outputVec_h, outputVec_d, sizeof(T) * arraysize,
|
||||
hipMemcpyDefault));
|
||||
HIP_CHECK(hipMemcpy(outputVec_h, outputVec_d, sizeof(T) * arraysize, hipMemcpyDefault));
|
||||
bool bPassed = true;
|
||||
for (size_t idx = 0; idx < arraysize; idx++) {
|
||||
if (outputVec_h[idx] != data_value) {
|
||||
@@ -444,10 +433,8 @@ static bool TestMemoryAccessInAllThread(int test_type, int thread_idx) {
|
||||
/**
|
||||
* Local function: Launch kerAlloc<<<>>>
|
||||
*/
|
||||
template <typename T>
|
||||
static void runTestMemoryAccessInAllThread(int test_type, int thread_idx) {
|
||||
thread_results[thread_idx] = TestMemoryAccessInAllThread<T>(test_type,
|
||||
thread_idx);
|
||||
template <typename T> static void runTestMemoryAccessInAllThread(int test_type, int thread_idx) {
|
||||
thread_results[thread_idx] = TestMemoryAccessInAllThread<T>(test_type, thread_idx);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -456,12 +443,11 @@ static void runTestMemoryAccessInAllThread(int test_type, int thread_idx) {
|
||||
* streams.
|
||||
*/
|
||||
template <typename T>
|
||||
static bool TestMemoryAcrossMulKernels(int test_type,
|
||||
bool multistream = false) {
|
||||
static bool TestMemoryAcrossMulKernels(int test_type, bool multistream = false) {
|
||||
T *outputVec_d{nullptr}, *outputVec_h{nullptr};
|
||||
size_t arraysize = (BLOCKSIZE * GRIDSIZE);
|
||||
T data_value = std::numeric_limits<T>::max();
|
||||
outputVec_h = reinterpret_cast<T*> (malloc(sizeof(T) * arraysize));
|
||||
outputVec_h = reinterpret_cast<T*>(malloc(sizeof(T) * arraysize));
|
||||
REQUIRE(outputVec_h != nullptr);
|
||||
HIP_CHECK(hipMalloc(&outputVec_d, (sizeof(T) * arraysize)));
|
||||
// Launch Test Kernel
|
||||
@@ -486,8 +472,7 @@ static bool TestMemoryAcrossMulKernels(int test_type,
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
}
|
||||
// Copy to host buffer
|
||||
HIP_CHECK(hipMemcpy(outputVec_h, outputVec_d, sizeof(T) * arraysize,
|
||||
hipMemcpyDefault));
|
||||
HIP_CHECK(hipMemcpy(outputVec_h, outputVec_d, sizeof(T) * arraysize, hipMemcpyDefault));
|
||||
bool bPassed = true;
|
||||
for (size_t idx = 0; idx < arraysize; idx++) {
|
||||
if (outputVec_h[idx] != data_value) {
|
||||
@@ -503,24 +488,21 @@ static bool TestMemoryAcrossMulKernels(int test_type,
|
||||
/**
|
||||
* Local function: Launch kerAlloc<<<>>>
|
||||
*/
|
||||
template <typename T>
|
||||
static void runKerAlloc(int test_type) {
|
||||
template <typename T> static void runKerAlloc(int test_type) {
|
||||
kerAlloc<T><<<GRIDSIZE, BLOCKSIZE>>>(test_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Local function: Launch kerWrite<<<>>>
|
||||
*/
|
||||
template <typename T>
|
||||
static void runKerWrite(T data_value) {
|
||||
template <typename T> static void runKerWrite(T data_value) {
|
||||
kerWrite<T><<<GRIDSIZE, BLOCKSIZE>>>(data_value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Local function: Launch kerFree<<<>>>
|
||||
*/
|
||||
template <typename T>
|
||||
static void runKerFree(T *outputVec_d, int test_type) {
|
||||
template <typename T> static void runKerFree(T* outputVec_d, int test_type) {
|
||||
kerFree<T><<<GRIDSIZE, BLOCKSIZE>>>(outputVec_d, test_type);
|
||||
}
|
||||
|
||||
@@ -528,12 +510,11 @@ static void runKerFree(T *outputVec_d, int test_type) {
|
||||
* Local function: Launch kerAlloc<<<>>>, kerWrite<<<>>> and kerFree<<<>>>
|
||||
* across multiple threads.
|
||||
*/
|
||||
template <typename T>
|
||||
static bool TestDevMemAllocMulKerMulThrd(int test_type) {
|
||||
template <typename T> static bool TestDevMemAllocMulKerMulThrd(int test_type) {
|
||||
T *outputVec_d{nullptr}, *outputVec_h{nullptr};
|
||||
size_t arraysize = (BLOCKSIZE * GRIDSIZE);
|
||||
T data_value = std::numeric_limits<T>::max();
|
||||
outputVec_h = reinterpret_cast<T*> (malloc(sizeof(T) * arraysize));
|
||||
outputVec_h = reinterpret_cast<T*>(malloc(sizeof(T) * arraysize));
|
||||
REQUIRE(outputVec_h != nullptr);
|
||||
HIP_CHECK(hipMalloc(&outputVec_d, (sizeof(T) * arraysize)));
|
||||
// Launch all Test Kernel threads
|
||||
@@ -546,8 +527,7 @@ static bool TestDevMemAllocMulKerMulThrd(int test_type) {
|
||||
// Wait for all kernels in device
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
// Copy to host buffer
|
||||
HIP_CHECK(hipMemcpy(outputVec_h, outputVec_d, sizeof(T) * arraysize,
|
||||
hipMemcpyDefault));
|
||||
HIP_CHECK(hipMemcpy(outputVec_h, outputVec_d, sizeof(T) * arraysize, hipMemcpyDefault));
|
||||
bool bPassed = true;
|
||||
for (size_t idx = 0; idx < arraysize; idx++) {
|
||||
if (outputVec_h[idx] != data_value) {
|
||||
@@ -596,18 +576,15 @@ static bool TestMemoryAccessInAllThread_CmplxStr(int test_type) {
|
||||
static bool TestMemoryAccessInAllThread_Union(int test_type) {
|
||||
testInfoUnion *outputVec_d{nullptr}, *outputVec_h{nullptr};
|
||||
size_t arraysize = (BLOCKSIZE * GRIDSIZE);
|
||||
outputVec_h = reinterpret_cast<testInfoUnion*>
|
||||
(malloc(sizeof(testInfoUnion) * arraysize));
|
||||
outputVec_h = reinterpret_cast<testInfoUnion*>(malloc(sizeof(testInfoUnion) * arraysize));
|
||||
REQUIRE(outputVec_h != nullptr);
|
||||
HIP_CHECK(hipMalloc(&outputVec_d,
|
||||
(sizeof(testInfoUnion) * arraysize)));
|
||||
HIP_CHECK(hipMalloc(&outputVec_d, (sizeof(testInfoUnion) * arraysize)));
|
||||
// Launch Test Kernel
|
||||
kerTestAccessInAllThreadsForUnion<<<GRIDSIZE, BLOCKSIZE>>>(outputVec_d,
|
||||
test_type);
|
||||
kerTestAccessInAllThreadsForUnion<<<GRIDSIZE, BLOCKSIZE>>>(outputVec_d, test_type);
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
// Copy to host buffer
|
||||
HIP_CHECK(hipMemcpy(outputVec_h, outputVec_d,
|
||||
sizeof(testInfoUnion) * arraysize, hipMemcpyDefault));
|
||||
HIP_CHECK(
|
||||
hipMemcpy(outputVec_h, outputVec_d, sizeof(testInfoUnion) * arraysize, hipMemcpyDefault));
|
||||
bool bPassed = true;
|
||||
for (size_t idx = 0; idx < arraysize; idx++) {
|
||||
switch (idx % 5) {
|
||||
@@ -649,19 +626,18 @@ static bool TestMemoryAccessInAllThread_Union(int test_type) {
|
||||
* launches ker_TestDynamicAllocInAllThreads_CodeObj<<<>>> and
|
||||
* copies data back to host to validate.
|
||||
*/
|
||||
static bool TestAlloc_Load_SingleKer_AllocFree(int test_type,
|
||||
int value, size_t sizeBufferPerThread) {
|
||||
static bool TestAlloc_Load_SingleKer_AllocFree(int test_type, int value,
|
||||
size_t sizeBufferPerThread) {
|
||||
int *outputVec_d{nullptr}, *outputVec_h{nullptr};
|
||||
size_t arraysize = (sizeBufferPerThread * BLOCKSIZE * GRIDSIZE);
|
||||
outputVec_h = reinterpret_cast<int*> (malloc(sizeof(int) * arraysize));
|
||||
outputVec_h = reinterpret_cast<int*>(malloc(sizeof(int) * arraysize));
|
||||
REQUIRE(outputVec_h != nullptr);
|
||||
HIP_CHECK(hipMalloc(&outputVec_d, (sizeof(int) * arraysize)));
|
||||
// Launch Test Kernel
|
||||
hipModule_t Module;
|
||||
hipFunction_t Function;
|
||||
HIP_CHECK(hipModuleLoad(&Module, DEV_ALLOC_SINGKER_COBJ));
|
||||
HIP_CHECK(hipModuleGetFunction(&Function, Module,
|
||||
DEV_ALLOC_SINGKER_COBJ_FUNC));
|
||||
HIP_CHECK(hipModuleGetFunction(&Function, Module, DEV_ALLOC_SINGKER_COBJ_FUNC));
|
||||
hipStream_t stream;
|
||||
HIP_CHECK(hipStreamCreate(&stream));
|
||||
|
||||
@@ -677,17 +653,13 @@ static bool TestAlloc_Load_SingleKer_AllocFree(int test_type,
|
||||
args._size = sizeBufferPerThread;
|
||||
size_t size = sizeof(args);
|
||||
|
||||
void* config[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args,
|
||||
HIP_LAUNCH_PARAM_BUFFER_SIZE, &size,
|
||||
void* config[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args, HIP_LAUNCH_PARAM_BUFFER_SIZE, &size,
|
||||
HIP_LAUNCH_PARAM_END};
|
||||
HIP_CHECK(hipModuleLaunchKernel(Function, GRIDSIZE, 1, 1,
|
||||
BLOCKSIZE, 1, 1, 0,
|
||||
stream, NULL,
|
||||
reinterpret_cast<void**>(&config)));
|
||||
HIP_CHECK(hipModuleLaunchKernel(Function, GRIDSIZE, 1, 1, BLOCKSIZE, 1, 1, 0, stream, NULL,
|
||||
reinterpret_cast<void**>(&config)));
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
// Copy to host buffer
|
||||
HIP_CHECK(hipMemcpy(outputVec_h, outputVec_d, sizeof(int) * arraysize,
|
||||
hipMemcpyDefault));
|
||||
HIP_CHECK(hipMemcpy(outputVec_h, outputVec_d, sizeof(int) * arraysize, hipMemcpyDefault));
|
||||
bool bPassed = true;
|
||||
for (size_t idx = 0; idx < arraysize; idx++) {
|
||||
if (outputVec_h[idx] != value) {
|
||||
@@ -707,12 +679,11 @@ static bool TestAlloc_Load_SingleKer_AllocFree(int test_type,
|
||||
* launches ker_Alloc_MultCodeObj<<<>>>, ker_Write_MultCodeObj<<<>>> and
|
||||
* ker_Free_MultCodeObj<<<>>> copies data back to host to validate.
|
||||
*/
|
||||
static bool TestAlloc_Load_MultKernels(int test_type,
|
||||
int value) {
|
||||
static bool TestAlloc_Load_MultKernels(int test_type, int value) {
|
||||
int *outputVec_d{nullptr}, *outputVec_h{nullptr};
|
||||
int **dev_addr{nullptr};
|
||||
int** dev_addr{nullptr};
|
||||
size_t arraysize = (BLOCKSIZE * GRIDSIZE);
|
||||
outputVec_h = reinterpret_cast<int*> (malloc(sizeof(int) * arraysize));
|
||||
outputVec_h = reinterpret_cast<int*>(malloc(sizeof(int) * arraysize));
|
||||
REQUIRE(outputVec_h != nullptr);
|
||||
HIP_CHECK(hipMalloc(&outputVec_d, (sizeof(int) * arraysize)));
|
||||
HIP_CHECK(hipMalloc(&dev_addr, (sizeof(int*))));
|
||||
@@ -723,42 +694,37 @@ static bool TestAlloc_Load_MultKernels(int test_type,
|
||||
HIP_CHECK(hipModuleLoad(&ModuleAlloc, DEV_ALLOC_MULCOBJ));
|
||||
HIP_CHECK(hipModuleLoad(&ModuleWrite, DEV_WRITE_MULCOBJ));
|
||||
HIP_CHECK(hipModuleLoad(&ModuleFree, DEV_FREE_MULCOBJ));
|
||||
HIP_CHECK(hipModuleGetFunction(&FunctionAlloc, ModuleAlloc,
|
||||
DEV_ALLOC_MULCODEOBJ_ALLOC));
|
||||
HIP_CHECK(hipModuleGetFunction(&FunctionAlloc, ModuleAlloc, DEV_ALLOC_MULCODEOBJ_ALLOC));
|
||||
// Load ker_Write_MultCodeObj
|
||||
HIP_CHECK(hipModuleGetFunction(&FunctionAcess, ModuleWrite,
|
||||
DEV_ALLOC_MULCODEOBJ_WRITE));
|
||||
HIP_CHECK(hipModuleGetFunction(&FunctionAcess, ModuleWrite, DEV_ALLOC_MULCODEOBJ_WRITE));
|
||||
// Load ker_Free_MultCodeObj
|
||||
HIP_CHECK(hipModuleGetFunction(&FunctionFree, ModuleFree,
|
||||
DEV_ALLOC_MULCODEOBJ_FREE));
|
||||
HIP_CHECK(hipModuleGetFunction(&FunctionFree, ModuleFree, DEV_ALLOC_MULCODEOBJ_FREE));
|
||||
hipStream_t stream;
|
||||
HIP_CHECK(hipStreamCreate(&stream));
|
||||
|
||||
struct {
|
||||
void **__dev_addr;
|
||||
void** __dev_addr;
|
||||
int _test_type;
|
||||
} args1;
|
||||
args1.__dev_addr = reinterpret_cast<void**>(dev_addr);
|
||||
args1._test_type = test_type;
|
||||
size_t size1 = sizeof(args1);
|
||||
|
||||
void* config1[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args1,
|
||||
HIP_LAUNCH_PARAM_BUFFER_SIZE, &size1,
|
||||
HIP_LAUNCH_PARAM_END};
|
||||
void* config1[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args1, HIP_LAUNCH_PARAM_BUFFER_SIZE, &size1,
|
||||
HIP_LAUNCH_PARAM_END};
|
||||
struct {
|
||||
void **__dev_addr;
|
||||
void** __dev_addr;
|
||||
int _value;
|
||||
} args2;
|
||||
args2.__dev_addr = reinterpret_cast<void**>(dev_addr);
|
||||
args2._value = value;
|
||||
size_t size2 = sizeof(args2);
|
||||
|
||||
void* config2[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args2,
|
||||
HIP_LAUNCH_PARAM_BUFFER_SIZE, &size2,
|
||||
HIP_LAUNCH_PARAM_END};
|
||||
void* config2[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args2, HIP_LAUNCH_PARAM_BUFFER_SIZE, &size2,
|
||||
HIP_LAUNCH_PARAM_END};
|
||||
struct {
|
||||
void* _output;
|
||||
void **__dev_addr;
|
||||
void** __dev_addr;
|
||||
int _test_type;
|
||||
} args3;
|
||||
args3._output = reinterpret_cast<void*>(outputVec_d);
|
||||
@@ -766,28 +732,20 @@ static bool TestAlloc_Load_MultKernels(int test_type,
|
||||
args3._test_type = test_type;
|
||||
size_t size3 = sizeof(args3);
|
||||
|
||||
void* config3[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args3,
|
||||
HIP_LAUNCH_PARAM_BUFFER_SIZE, &size3,
|
||||
HIP_LAUNCH_PARAM_END};
|
||||
void* config3[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args3, HIP_LAUNCH_PARAM_BUFFER_SIZE, &size3,
|
||||
HIP_LAUNCH_PARAM_END};
|
||||
// Launch ker_Alloc_MultCodeObj
|
||||
HIP_CHECK(hipModuleLaunchKernel(FunctionAlloc, GRIDSIZE, 1, 1,
|
||||
BLOCKSIZE, 1, 1, 0,
|
||||
stream, NULL,
|
||||
reinterpret_cast<void**>(&config1)));
|
||||
HIP_CHECK(hipModuleLaunchKernel(FunctionAlloc, GRIDSIZE, 1, 1, BLOCKSIZE, 1, 1, 0, stream, NULL,
|
||||
reinterpret_cast<void**>(&config1)));
|
||||
// Launch ker_Write_MultCodeObj
|
||||
HIP_CHECK(hipModuleLaunchKernel(FunctionAcess, GRIDSIZE, 1, 1,
|
||||
BLOCKSIZE, 1, 1, 0,
|
||||
stream, NULL,
|
||||
reinterpret_cast<void**>(&config2)));
|
||||
HIP_CHECK(hipModuleLaunchKernel(FunctionAcess, GRIDSIZE, 1, 1, BLOCKSIZE, 1, 1, 0, stream, NULL,
|
||||
reinterpret_cast<void**>(&config2)));
|
||||
// Launch ker_Free_MultCodeObj
|
||||
HIP_CHECK(hipModuleLaunchKernel(FunctionFree, GRIDSIZE, 1, 1,
|
||||
BLOCKSIZE, 1, 1, 0,
|
||||
stream, NULL,
|
||||
reinterpret_cast<void**>(&config3)));
|
||||
HIP_CHECK(hipModuleLaunchKernel(FunctionFree, GRIDSIZE, 1, 1, BLOCKSIZE, 1, 1, 0, stream, NULL,
|
||||
reinterpret_cast<void**>(&config3)));
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
// Copy to host buffer
|
||||
HIP_CHECK(hipMemcpy(outputVec_h, outputVec_d, sizeof(int) * arraysize,
|
||||
hipMemcpyDefault));
|
||||
HIP_CHECK(hipMemcpy(outputVec_h, outputVec_d, sizeof(int) * arraysize, hipMemcpyDefault));
|
||||
bool bPassed = true;
|
||||
for (size_t idx = 0; idx < arraysize; idx++) {
|
||||
if (outputVec_h[idx] != value) {
|
||||
@@ -810,12 +768,11 @@ static bool TestAlloc_Load_MultKernels(int test_type,
|
||||
* to test kernel allocated memory access across multiple kernels using
|
||||
* hipGraph.
|
||||
*/
|
||||
template <typename T>
|
||||
static bool TestMemoryAcrossMulKernelsUsingGraph(int test_type) {
|
||||
template <typename T> static bool TestMemoryAcrossMulKernelsUsingGraph(int test_type) {
|
||||
T *outputVec_d{nullptr}, *outputVec_h{nullptr};
|
||||
size_t arraysize = (BLOCKSIZE * GRIDSIZE);
|
||||
T data_value = std::numeric_limits<T>::max();
|
||||
outputVec_h = reinterpret_cast<T*> (malloc(sizeof(T) * arraysize));
|
||||
outputVec_h = reinterpret_cast<T*>(malloc(sizeof(T) * arraysize));
|
||||
REQUIRE(outputVec_h != nullptr);
|
||||
HIP_CHECK(hipMalloc(&outputVec_d, (sizeof(T) * arraysize)));
|
||||
// Launch Test Kernels using graph
|
||||
@@ -827,52 +784,44 @@ static bool TestMemoryAcrossMulKernelsUsingGraph(int test_type) {
|
||||
// Create Allocation Kernel Node
|
||||
hipGraphNode_t kernelnode_1;
|
||||
hipKernelNodeParams kernelNodeParams1{};
|
||||
void* kernelArgs1[] = {reinterpret_cast<void *>(&test_type)};
|
||||
kernelNodeParams1.func = reinterpret_cast<void *>(kerAlloc<T>);
|
||||
void* kernelArgs1[] = {reinterpret_cast<void*>(&test_type)};
|
||||
kernelNodeParams1.func = reinterpret_cast<void*>(kerAlloc<T>);
|
||||
kernelNodeParams1.gridDim = dim3(GRIDSIZE);
|
||||
kernelNodeParams1.blockDim = dim3(BLOCKSIZE);
|
||||
kernelNodeParams1.sharedMemBytes = 0;
|
||||
kernelNodeParams1.kernelParams = reinterpret_cast<void**>(kernelArgs1);
|
||||
kernelNodeParams1.extra = nullptr;
|
||||
HIP_CHECK(hipGraphAddKernelNode(&kernelnode_1, graph, nullptr, 0,
|
||||
&kernelNodeParams1));
|
||||
HIP_CHECK(hipGraphAddKernelNode(&kernelnode_1, graph, nullptr, 0, &kernelNodeParams1));
|
||||
// Create Write Kernel Node
|
||||
hipGraphNode_t kernelnode_2;
|
||||
hipKernelNodeParams kernelNodeParams2{};
|
||||
void* kernelArgs2[] = {reinterpret_cast<void *>(&data_value)};
|
||||
kernelNodeParams2.func = reinterpret_cast<void *>(kerWrite<T>);
|
||||
void* kernelArgs2[] = {reinterpret_cast<void*>(&data_value)};
|
||||
kernelNodeParams2.func = reinterpret_cast<void*>(kerWrite<T>);
|
||||
kernelNodeParams2.gridDim = dim3(GRIDSIZE);
|
||||
kernelNodeParams2.blockDim = dim3(BLOCKSIZE);
|
||||
kernelNodeParams2.sharedMemBytes = 0;
|
||||
kernelNodeParams2.kernelParams = reinterpret_cast<void**>(kernelArgs2);
|
||||
kernelNodeParams2.extra = nullptr;
|
||||
HIP_CHECK(hipGraphAddKernelNode(&kernelnode_2, graph, nullptr, 0,
|
||||
&kernelNodeParams2));
|
||||
HIP_CHECK(hipGraphAddKernelNode(&kernelnode_2, graph, nullptr, 0, &kernelNodeParams2));
|
||||
// Create Free Kernel Node
|
||||
hipGraphNode_t kernelnode_3;
|
||||
hipKernelNodeParams kernelNodeParams3{};
|
||||
void* kernelArgs3[] =
|
||||
{&outputVec_d, reinterpret_cast<void *>(&test_type)};
|
||||
kernelNodeParams3.func = reinterpret_cast<void *>(kerFree<T>);
|
||||
void* kernelArgs3[] = {&outputVec_d, reinterpret_cast<void*>(&test_type)};
|
||||
kernelNodeParams3.func = reinterpret_cast<void*>(kerFree<T>);
|
||||
kernelNodeParams3.gridDim = dim3(GRIDSIZE);
|
||||
kernelNodeParams3.blockDim = dim3(BLOCKSIZE);
|
||||
kernelNodeParams3.sharedMemBytes = 0;
|
||||
kernelNodeParams3.kernelParams = reinterpret_cast<void**>(kernelArgs3);
|
||||
kernelNodeParams3.extra = nullptr;
|
||||
HIP_CHECK(hipGraphAddKernelNode(&kernelnode_3, graph, nullptr, 0,
|
||||
&kernelNodeParams3));
|
||||
HIP_CHECK(hipGraphAddKernelNode(&kernelnode_3, graph, nullptr, 0, &kernelNodeParams3));
|
||||
// Create Memcpy Node
|
||||
hipGraphNode_t memcpyD2H;
|
||||
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H, graph, nullptr, 0,
|
||||
outputVec_h, outputVec_d, (sizeof(T) * arraysize),
|
||||
hipMemcpyDeviceToHost));
|
||||
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H, graph, nullptr, 0, outputVec_h, outputVec_d,
|
||||
(sizeof(T) * arraysize), hipMemcpyDeviceToHost));
|
||||
// Create dependencies for graph
|
||||
HIP_CHECK(hipGraphAddDependencies(graph, &kernelnode_1,
|
||||
&kernelnode_2, 1));
|
||||
HIP_CHECK(hipGraphAddDependencies(graph, &kernelnode_2,
|
||||
&kernelnode_3, 1));
|
||||
HIP_CHECK(hipGraphAddDependencies(graph, &kernelnode_3,
|
||||
&memcpyD2H, 1));
|
||||
HIP_CHECK(hipGraphAddDependencies(graph, &kernelnode_1, &kernelnode_2, 1));
|
||||
HIP_CHECK(hipGraphAddDependencies(graph, &kernelnode_2, &kernelnode_3, 1));
|
||||
HIP_CHECK(hipGraphAddDependencies(graph, &kernelnode_3, &memcpyD2H, 1));
|
||||
// Instantiate and launch the graphs
|
||||
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
|
||||
HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph));
|
||||
@@ -898,16 +847,14 @@ static bool TestMemoryAcrossMulKernelsUsingGraph(int test_type) {
|
||||
static bool TestAllocInDeviceFunc(int test_type) {
|
||||
int *outputVec_d{nullptr}, *outputVec_h{nullptr};
|
||||
size_t arraysize = (INTERNAL_BUFFER_SIZE * BLOCKSIZE * GRIDSIZE);
|
||||
outputVec_h = reinterpret_cast<int*> (malloc(sizeof(int) * arraysize));
|
||||
outputVec_h = reinterpret_cast<int*>(malloc(sizeof(int) * arraysize));
|
||||
REQUIRE(outputVec_h != nullptr);
|
||||
HIP_CHECK(hipMalloc(&outputVec_d, (sizeof(int) * arraysize)));
|
||||
// Launch Test Kernel
|
||||
kerTestAllocationUsingDevFunc<<<GRIDSIZE, BLOCKSIZE>>>(outputVec_d,
|
||||
test_type);
|
||||
kerTestAllocationUsingDevFunc<<<GRIDSIZE, BLOCKSIZE>>>(outputVec_d, test_type);
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
// Copy to host buffer
|
||||
HIP_CHECK(hipMemcpy(outputVec_h, outputVec_d, sizeof(int) * arraysize,
|
||||
hipMemcpyDefault));
|
||||
HIP_CHECK(hipMemcpy(outputVec_h, outputVec_d, sizeof(int) * arraysize, hipMemcpyDefault));
|
||||
bool bPassed = true;
|
||||
for (size_t idx = 0; idx < arraysize; idx++) {
|
||||
if (outputVec_h[idx] != (idx / INTERNAL_BUFFER_SIZE)) {
|
||||
@@ -936,28 +883,23 @@ TEST_CASE("Unit_deviceAllocation_Malloc_PerThread_PrimitiveDataType") {
|
||||
|
||||
// malloc()/free() tests
|
||||
SECTION("Test char datatype allocation with malloc") {
|
||||
REQUIRE(true == TestAllocInAllThread<char>(TEST_MALLOC_FREE,
|
||||
SCHAR_MAX, sizePerThread));
|
||||
REQUIRE(true == TestAllocInAllThread<char>(TEST_MALLOC_FREE, SCHAR_MAX, sizePerThread));
|
||||
}
|
||||
|
||||
SECTION("Test short datatype allocation with malloc") {
|
||||
REQUIRE(true == TestAllocInAllThread<int16_t>(TEST_MALLOC_FREE,
|
||||
SHRT_MAX, sizePerThread));
|
||||
REQUIRE(true == TestAllocInAllThread<int16_t>(TEST_MALLOC_FREE, SHRT_MAX, sizePerThread));
|
||||
}
|
||||
|
||||
SECTION("Test int datatype allocation with malloc") {
|
||||
REQUIRE(true == TestAllocInAllThread<int32_t>(TEST_MALLOC_FREE,
|
||||
INT_MAX, sizePerThread));
|
||||
REQUIRE(true == TestAllocInAllThread<int32_t>(TEST_MALLOC_FREE, INT_MAX, sizePerThread));
|
||||
}
|
||||
|
||||
SECTION("Test float datatype allocation with malloc") {
|
||||
REQUIRE(true == TestAllocInAllThread<float>(TEST_MALLOC_FREE,
|
||||
FLT_MAX, sizePerThread));
|
||||
REQUIRE(true == TestAllocInAllThread<float>(TEST_MALLOC_FREE, FLT_MAX, sizePerThread));
|
||||
}
|
||||
|
||||
SECTION("Test double datatype allocation with malloc") {
|
||||
REQUIRE(true == TestAllocInAllThread<double>(TEST_MALLOC_FREE,
|
||||
DBL_MAX, sizePerThread));
|
||||
REQUIRE(true == TestAllocInAllThread<double>(TEST_MALLOC_FREE, DBL_MAX, sizePerThread));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -977,28 +919,23 @@ TEST_CASE("Unit_deviceAllocation_New_PerThread_PrimitiveDataType") {
|
||||
|
||||
// new/delete tests
|
||||
SECTION("Test char datatype allocation with new") {
|
||||
REQUIRE(true == TestAllocInAllThread<char>(TEST_NEW_DELETE,
|
||||
SCHAR_MAX, sizePerThread));
|
||||
REQUIRE(true == TestAllocInAllThread<char>(TEST_NEW_DELETE, SCHAR_MAX, sizePerThread));
|
||||
}
|
||||
|
||||
SECTION("Test short datatype allocation with new") {
|
||||
REQUIRE(true == TestAllocInAllThread<int16_t>(TEST_NEW_DELETE,
|
||||
SHRT_MAX, sizePerThread));
|
||||
REQUIRE(true == TestAllocInAllThread<int16_t>(TEST_NEW_DELETE, SHRT_MAX, sizePerThread));
|
||||
}
|
||||
|
||||
SECTION("Test int datatype allocation with new") {
|
||||
REQUIRE(true == TestAllocInAllThread<int32_t>(TEST_NEW_DELETE,
|
||||
INT_MAX, sizePerThread));
|
||||
REQUIRE(true == TestAllocInAllThread<int32_t>(TEST_NEW_DELETE, INT_MAX, sizePerThread));
|
||||
}
|
||||
|
||||
SECTION("Test float datatype allocation with new") {
|
||||
REQUIRE(true == TestAllocInAllThread<float>(TEST_NEW_DELETE,
|
||||
FLT_MAX, sizePerThread));
|
||||
REQUIRE(true == TestAllocInAllThread<float>(TEST_NEW_DELETE, FLT_MAX, sizePerThread));
|
||||
}
|
||||
|
||||
SECTION("Test double datatype allocation with new") {
|
||||
REQUIRE(true == TestAllocInAllThread<double>(TEST_NEW_DELETE,
|
||||
DBL_MAX, sizePerThread));
|
||||
REQUIRE(true == TestAllocInAllThread<double>(TEST_NEW_DELETE, DBL_MAX, sizePerThread));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1014,10 +951,10 @@ TEST_CASE("Unit_deviceAllocation_Malloc_PerThread_StructDataType") {
|
||||
return;
|
||||
}
|
||||
constexpr size_t sizePerThread = 64;
|
||||
struct simpleStruct sampleStr{INT_MAX, DBL_MAX, FLT_MAX, SHRT_MAX,
|
||||
SCHAR_MAX, {1, 2, 3, 4, 5, 6, 7, 8}};
|
||||
REQUIRE(true == TestAllocInAllThread<struct simpleStruct>(TEST_MALLOC_FREE,
|
||||
sampleStr, sizePerThread));
|
||||
struct simpleStruct sampleStr{INT_MAX, DBL_MAX, FLT_MAX,
|
||||
SHRT_MAX, SCHAR_MAX, {1, 2, 3, 4, 5, 6, 7, 8}};
|
||||
REQUIRE(true ==
|
||||
TestAllocInAllThread<struct simpleStruct>(TEST_MALLOC_FREE, sampleStr, sizePerThread));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1032,10 +969,10 @@ TEST_CASE("Unit_deviceAllocation_New_PerThread_StructDataType") {
|
||||
return;
|
||||
}
|
||||
constexpr size_t sizePerThread = 64;
|
||||
struct simpleStruct sampleStr{INT_MAX, DBL_MAX, FLT_MAX, SHRT_MAX,
|
||||
SCHAR_MAX, {1, 2, 3, 4, 5, 6, 7, 8}};
|
||||
REQUIRE(true == TestAllocInAllThread<struct simpleStruct>(TEST_NEW_DELETE,
|
||||
sampleStr, sizePerThread));
|
||||
struct simpleStruct sampleStr{INT_MAX, DBL_MAX, FLT_MAX,
|
||||
SHRT_MAX, SCHAR_MAX, {1, 2, 3, 4, 5, 6, 7, 8}};
|
||||
REQUIRE(true ==
|
||||
TestAllocInAllThread<struct simpleStruct>(TEST_NEW_DELETE, sampleStr, sizePerThread));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1243,8 +1180,7 @@ TEST_CASE("Unit_deviceAllocation_Malloc_SingleCodeObj") {
|
||||
}
|
||||
constexpr size_t sizePerThread = 128;
|
||||
|
||||
REQUIRE(true == TestAlloc_Load_SingleKer_AllocFree(TEST_MALLOC_FREE,
|
||||
INT_MAX, sizePerThread));
|
||||
REQUIRE(true == TestAlloc_Load_SingleKer_AllocFree(TEST_MALLOC_FREE, INT_MAX, sizePerThread));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1261,8 +1197,7 @@ TEST_CASE("Unit_deviceAllocation_New_SingleCodeObj") {
|
||||
}
|
||||
constexpr size_t sizePerThread = 128;
|
||||
|
||||
REQUIRE(true == TestAlloc_Load_SingleKer_AllocFree(TEST_NEW_DELETE,
|
||||
INT_MAX, sizePerThread));
|
||||
REQUIRE(true == TestAlloc_Load_SingleKer_AllocFree(TEST_NEW_DELETE, INT_MAX, sizePerThread));
|
||||
}
|
||||
|
||||
#if HT_NVIDIA
|
||||
@@ -1273,28 +1208,23 @@ TEST_CASE("Unit_deviceAllocation_New_SingleCodeObj") {
|
||||
TEST_CASE("Unit_deviceAllocation_Malloc_PerThread_MultKerMultStrm") {
|
||||
// malloc()/free() tests
|
||||
SECTION("Test char datatype allocation with malloc") {
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<char>(TEST_MALLOC_FREE,
|
||||
true));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<char>(TEST_MALLOC_FREE, true));
|
||||
}
|
||||
|
||||
SECTION("Test short datatype allocation with malloc") {
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<int16_t>(TEST_MALLOC_FREE,
|
||||
true));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<int16_t>(TEST_MALLOC_FREE, true));
|
||||
}
|
||||
|
||||
SECTION("Test int datatype allocation with malloc") {
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<int32_t>(TEST_MALLOC_FREE,
|
||||
true));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<int32_t>(TEST_MALLOC_FREE, true));
|
||||
}
|
||||
|
||||
SECTION("Test float datatype allocation with malloc") {
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<float>(TEST_MALLOC_FREE,
|
||||
true));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<float>(TEST_MALLOC_FREE, true));
|
||||
}
|
||||
|
||||
SECTION("Test double datatype allocation with malloc") {
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<double>(TEST_MALLOC_FREE,
|
||||
true));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<double>(TEST_MALLOC_FREE, true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1305,28 +1235,23 @@ TEST_CASE("Unit_deviceAllocation_Malloc_PerThread_MultKerMultStrm") {
|
||||
TEST_CASE("Unit_deviceAllocation_New_PerThread_MultKerMultStrm") {
|
||||
// new/delete tests
|
||||
SECTION("Test char datatype allocation with new") {
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<char>(TEST_NEW_DELETE,
|
||||
true));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<char>(TEST_NEW_DELETE, true));
|
||||
}
|
||||
|
||||
SECTION("Test short datatype allocation with new") {
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<int16_t>(TEST_NEW_DELETE,
|
||||
true));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<int16_t>(TEST_NEW_DELETE, true));
|
||||
}
|
||||
|
||||
SECTION("Test int datatype allocation with new") {
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<int32_t>(TEST_NEW_DELETE,
|
||||
true));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<int32_t>(TEST_NEW_DELETE, true));
|
||||
}
|
||||
|
||||
SECTION("Test float datatype allocation with new") {
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<float>(TEST_NEW_DELETE,
|
||||
true));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<float>(TEST_NEW_DELETE, true));
|
||||
}
|
||||
|
||||
SECTION("Test double datatype allocation with new") {
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<double>(TEST_NEW_DELETE,
|
||||
true));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernels<double>(TEST_NEW_DELETE, true));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1344,28 +1269,23 @@ TEST_CASE("Unit_deviceAllocation_Malloc_PerThread_Graph") {
|
||||
}
|
||||
// malloc()/free() tests
|
||||
SECTION("Test char datatype allocation with malloc") {
|
||||
REQUIRE(true ==
|
||||
TestMemoryAcrossMulKernelsUsingGraph<char>(TEST_MALLOC_FREE));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernelsUsingGraph<char>(TEST_MALLOC_FREE));
|
||||
}
|
||||
|
||||
SECTION("Test short datatype allocation with malloc") {
|
||||
REQUIRE(true ==
|
||||
TestMemoryAcrossMulKernelsUsingGraph<int16_t>(TEST_MALLOC_FREE));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernelsUsingGraph<int16_t>(TEST_MALLOC_FREE));
|
||||
}
|
||||
|
||||
SECTION("Test int datatype allocation with malloc") {
|
||||
REQUIRE(true ==
|
||||
TestMemoryAcrossMulKernelsUsingGraph<int32_t>(TEST_MALLOC_FREE));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernelsUsingGraph<int32_t>(TEST_MALLOC_FREE));
|
||||
}
|
||||
|
||||
SECTION("Test float datatype allocation with malloc") {
|
||||
REQUIRE(true ==
|
||||
TestMemoryAcrossMulKernelsUsingGraph<float>(TEST_MALLOC_FREE));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernelsUsingGraph<float>(TEST_MALLOC_FREE));
|
||||
}
|
||||
|
||||
SECTION("Test double datatype allocation with malloc") {
|
||||
REQUIRE(true ==
|
||||
TestMemoryAcrossMulKernelsUsingGraph<double>(TEST_MALLOC_FREE));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernelsUsingGraph<double>(TEST_MALLOC_FREE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1382,28 +1302,23 @@ TEST_CASE("Unit_deviceAllocation_New_PerThread_Graph") {
|
||||
}
|
||||
// new/delete tests
|
||||
SECTION("Test char datatype allocation with new") {
|
||||
REQUIRE(true ==
|
||||
TestMemoryAcrossMulKernelsUsingGraph<char>(TEST_NEW_DELETE));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernelsUsingGraph<char>(TEST_NEW_DELETE));
|
||||
}
|
||||
|
||||
SECTION("Test short datatype allocation with new") {
|
||||
REQUIRE(true ==
|
||||
TestMemoryAcrossMulKernelsUsingGraph<int16_t>(TEST_NEW_DELETE));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernelsUsingGraph<int16_t>(TEST_NEW_DELETE));
|
||||
}
|
||||
|
||||
SECTION("Test int datatype allocation with new") {
|
||||
REQUIRE(true ==
|
||||
TestMemoryAcrossMulKernelsUsingGraph<int32_t>(TEST_NEW_DELETE));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernelsUsingGraph<int32_t>(TEST_NEW_DELETE));
|
||||
}
|
||||
|
||||
SECTION("Test float datatype allocation with new") {
|
||||
REQUIRE(true ==
|
||||
TestMemoryAcrossMulKernelsUsingGraph<float>(TEST_NEW_DELETE));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernelsUsingGraph<float>(TEST_NEW_DELETE));
|
||||
}
|
||||
|
||||
SECTION("Test double datatype allocation with new") {
|
||||
REQUIRE(true ==
|
||||
TestMemoryAcrossMulKernelsUsingGraph<double>(TEST_NEW_DELETE));
|
||||
REQUIRE(true == TestMemoryAcrossMulKernelsUsingGraph<double>(TEST_NEW_DELETE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1450,16 +1365,14 @@ TEST_CASE("Unit_deviceAllocation_VirtualFunction") {
|
||||
int *outputVec_d{nullptr}, *outputVec_h{nullptr};
|
||||
constexpr size_t sizeBufferPerThread = 8;
|
||||
size_t arraysize = (sizeBufferPerThread * BLOCKSIZE * GRIDSIZE);
|
||||
outputVec_h = reinterpret_cast<int*> (malloc(sizeof(int) * arraysize));
|
||||
outputVec_h = reinterpret_cast<int*>(malloc(sizeof(int) * arraysize));
|
||||
REQUIRE(outputVec_h != nullptr);
|
||||
HIP_CHECK(hipMalloc(&outputVec_d, (sizeof(int) * arraysize)));
|
||||
// Launch Test Kernel
|
||||
kerTestDynamicAllocVirtualFunc<<<GRIDSIZE, BLOCKSIZE>>>(
|
||||
outputVec_d, sizeBufferPerThread);
|
||||
kerTestDynamicAllocVirtualFunc<<<GRIDSIZE, BLOCKSIZE>>>(outputVec_d, sizeBufferPerThread);
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
// Copy to host buffer
|
||||
HIP_CHECK(hipMemcpy(outputVec_h, outputVec_d, sizeof(int) * arraysize,
|
||||
hipMemcpyDefault));
|
||||
HIP_CHECK(hipMemcpy(outputVec_h, outputVec_d, sizeof(int) * arraysize, hipMemcpyDefault));
|
||||
bool bPassed = true;
|
||||
for (size_t idx = 0; idx < arraysize; idx++) {
|
||||
if (outputVec_h[idx] != (idx / sizeBufferPerThread)) {
|
||||
@@ -1557,11 +1470,10 @@ TEST_CASE("Unit_deviceAllocation_Malloc_SingKernels_MulThreads") {
|
||||
// Spawn the test threads
|
||||
for (int idx = 0; idx < num_threads; idx++) {
|
||||
thread_results[idx] = false;
|
||||
tests.push_back(std::thread(runTestMemoryAccessInAllThread<int32_t>,
|
||||
TEST_MALLOC_FREE, idx));
|
||||
tests.push_back(std::thread(runTestMemoryAccessInAllThread<int32_t>, TEST_MALLOC_FREE, idx));
|
||||
}
|
||||
// Wait for all threads to complete
|
||||
for (std::thread &t : tests) {
|
||||
for (std::thread& t : tests) {
|
||||
t.join();
|
||||
}
|
||||
// Verify All Results
|
||||
@@ -1586,11 +1498,10 @@ TEST_CASE("Unit_deviceAllocation_New_SingKernels_MulThreads") {
|
||||
// Spawn the test threads
|
||||
for (int idx = 0; idx < num_threads; idx++) {
|
||||
thread_results[idx] = false;
|
||||
tests.push_back(std::thread(runTestMemoryAccessInAllThread<int32_t>,
|
||||
TEST_NEW_DELETE, idx));
|
||||
tests.push_back(std::thread(runTestMemoryAccessInAllThread<int32_t>, TEST_NEW_DELETE, idx));
|
||||
}
|
||||
// Wait for all threads to complete
|
||||
for (std::thread &t : tests) {
|
||||
for (std::thread& t : tests) {
|
||||
t.join();
|
||||
}
|
||||
// Verify All Results
|
||||
@@ -1611,8 +1522,7 @@ TEST_CASE("Unit_deviceAllocation_Malloc_MulCodeObj") {
|
||||
HipTest::HIP_SKIP_TEST("Device doesn't support pcie atomic, Skipped");
|
||||
return;
|
||||
}
|
||||
REQUIRE(true == TestAlloc_Load_MultKernels(TEST_MALLOC_FREE,
|
||||
INT_MAX));
|
||||
REQUIRE(true == TestAlloc_Load_MultKernels(TEST_MALLOC_FREE, INT_MAX));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1626,6 +1536,5 @@ TEST_CASE("Unit_deviceAllocation_New_MulCodeObj") {
|
||||
HipTest::HIP_SKIP_TEST("Device doesn't support pcie atomic, Skipped");
|
||||
return;
|
||||
}
|
||||
REQUIRE(true == TestAlloc_Load_MultKernels(TEST_NEW_DELETE,
|
||||
INT_MAX));
|
||||
REQUIRE(true == TestAlloc_Load_MultKernels(TEST_NEW_DELETE, INT_MAX));
|
||||
}
|
||||
|
||||
مرجع در شماره جدید
Block a user