SWDEV-312831 - Adding device side malloc/new tests (#2635)
Following tests are added in this patch 1) Functional Tests 2) Stress Tests 3) Multiprocess Tests Change-Id: Ifd2310fe8f5d555a9af9b87c296fdf6dd4a0a552
This commit is contained in:
committed by
GitHub
parent
908988924a
commit
de0eb21023
@@ -13,6 +13,7 @@ set(TEST_SRC
|
||||
syncthreadsand.cc
|
||||
syncthreadscount.cc
|
||||
syncthreadsor.cc
|
||||
deviceAllocation.cc
|
||||
)
|
||||
|
||||
# AMD only tests
|
||||
@@ -43,6 +44,11 @@ set(AMD_ARCH_SPEC_TEST_SRC
|
||||
unsafeAtomicAdd_NonCoherent_withunsafeflag.cc
|
||||
)
|
||||
|
||||
add_custom_target(kerDevAllocMultCO.code COMMAND ${CMAKE_CXX_COMPILER} --genco ${CMAKE_CURRENT_SOURCE_DIR}/kerDevAllocMultCO.cc -o ${CMAKE_CURRENT_BINARY_DIR}/../../unit/deviceLib/kerDevAllocMultCO.code -I${CMAKE_CURRENT_SOURCE_DIR}/../../../../include/ -I${CMAKE_CURRENT_SOURCE_DIR}/../../include)
|
||||
add_custom_target(kerDevWriteMultCO.code COMMAND ${CMAKE_CXX_COMPILER} --genco ${CMAKE_CURRENT_SOURCE_DIR}/kerDevWriteMultCO.cc -o ${CMAKE_CURRENT_BINARY_DIR}/../../unit/deviceLib/kerDevWriteMultCO.code -I${CMAKE_CURRENT_SOURCE_DIR}/../../../../include/ -I${CMAKE_CURRENT_SOURCE_DIR}/../../include)
|
||||
add_custom_target(kerDevFreeMultCO.code COMMAND ${CMAKE_CXX_COMPILER} --genco ${CMAKE_CURRENT_SOURCE_DIR}/kerDevFreeMultCO.cc -o ${CMAKE_CURRENT_BINARY_DIR}/../../unit/deviceLib/kerDevFreeMultCO.code -I${CMAKE_CURRENT_SOURCE_DIR}/../../../../include/ -I${CMAKE_CURRENT_SOURCE_DIR}/../../include)
|
||||
add_custom_target(kerDevAllocSingleKer.code COMMAND ${CMAKE_CXX_COMPILER} --genco ${CMAKE_CURRENT_SOURCE_DIR}/kerDevAllocSingleKer.cc -o ${CMAKE_CURRENT_BINARY_DIR}/../../unit/deviceLib/kerDevAllocSingleKer.code -I${CMAKE_CURRENT_SOURCE_DIR}/../../../../include/ -I${CMAKE_CURRENT_SOURCE_DIR}/../../include)
|
||||
|
||||
if(HIP_PLATFORM MATCHES "amd")
|
||||
if (DEFINED OFFLOAD_ARCH_STR)
|
||||
string(FIND ${OFFLOAD_ARCH_STR} "gfx90a" ARCH_CHECK)
|
||||
@@ -78,3 +84,4 @@ elseif(HIP_PLATFORM MATCHES "nvidia")
|
||||
TEST_TARGET_NAME build_tests
|
||||
COMPILE_OPTIONS --Wno-deprecated-declarations)
|
||||
endif()
|
||||
add_dependencies(build_tests kerDevAllocMultCO.code kerDevWriteMultCO.code kerDevFreeMultCO.code kerDevAllocSingleKer.code)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#define INTERNAL_BUFFER_SIZE 8
|
||||
// Test Type
|
||||
#define TEST_MALLOC_FREE 1
|
||||
#define TEST_NEW_DELETE 2
|
||||
// Kernel Params
|
||||
#define BLOCKSIZE 64
|
||||
#define GRIDSIZE 32
|
||||
// Code Obj
|
||||
#define DEV_ALLOC_SINGKER_COBJ "kerDevAllocSingleKer.code"
|
||||
#define DEV_ALLOC_SINGKER_COBJ_FUNC "ker_TestDynamicAllocInAllThreads_CodeObj"
|
||||
#define DEV_ALLOC_MULCOBJ "kerDevAllocMultCO.code"
|
||||
#define DEV_WRITE_MULCOBJ "kerDevWriteMultCO.code"
|
||||
#define DEV_FREE_MULCOBJ "kerDevFreeMultCO.code"
|
||||
#define DEV_ALLOC_MULCODEOBJ_ALLOC "ker_Alloc_MultCodeObj"
|
||||
#define DEV_ALLOC_MULCODEOBJ_WRITE "ker_Write_MultCodeObj"
|
||||
#define DEV_ALLOC_MULCODEOBJ_FREE "ker_Free_MultCodeObj"
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <hip_test_common.hh>
|
||||
#include <hip_test_kernels.hh>
|
||||
#include <hip_test_checkers.hh>
|
||||
#include <cfloat>
|
||||
#include <atomic>
|
||||
#include "./defs.h"
|
||||
|
||||
static __device__ int* deviceAlloc(int test_type);
|
||||
static __device__ void deviceWrite(int myId, int *devmem);
|
||||
static __device__ void deviceFree(int *outputBuf, int *devmem,
|
||||
int test_type, int myId);
|
||||
|
||||
/**
|
||||
* Allocation base and derived class to test dynamic allocation.
|
||||
*/
|
||||
class baseAlloc{
|
||||
public:
|
||||
virtual __device__ int* alloc(size_t size) = 0;
|
||||
virtual __device__ void free(int* ptr) = 0;
|
||||
};
|
||||
|
||||
class derivedAlloc: public baseAlloc{
|
||||
public:
|
||||
virtual __device__ int* alloc(size_t size) {
|
||||
return new int[size];
|
||||
}
|
||||
virtual __device__ void free(int* ptr) {
|
||||
delete ptr;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Allocation Structure to test dynamic allocation.
|
||||
*/
|
||||
struct deviceAllocFunc{
|
||||
int* (*alloc)(int);
|
||||
void (*write)(int, int*);
|
||||
void (*free)(int*, int*, int, int);
|
||||
};
|
||||
|
||||
/**
|
||||
* Simple Structure to test dynamic allocation.
|
||||
*/
|
||||
struct simpleStruct{
|
||||
int32_t i;
|
||||
double d;
|
||||
float f;
|
||||
int16_t s;
|
||||
char c;
|
||||
int32_t iarr[INTERNAL_BUFFER_SIZE];
|
||||
bool operator!=(const struct simpleStruct &inpStr) {
|
||||
if ((i != inpStr.i) || (d != inpStr.d) ||
|
||||
(f != inpStr.f) || (s != inpStr.s) || (c != inpStr.c)) {
|
||||
return true;
|
||||
}
|
||||
for (int32_t idx = 0; idx < INTERNAL_BUFFER_SIZE; idx++) {
|
||||
if (iarr[idx] != inpStr.iarr[idx]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Simple Structure containing thread information
|
||||
*/
|
||||
struct threadInfo{
|
||||
int threadid;
|
||||
int blockid;
|
||||
int32_t ival;
|
||||
double dval;
|
||||
float fval;
|
||||
int16_t sval;
|
||||
char cval;
|
||||
};
|
||||
|
||||
/**
|
||||
* C/C++ Union
|
||||
*/
|
||||
union testInfoUnion{
|
||||
int32_t ival;
|
||||
double dval;
|
||||
float fval;
|
||||
int16_t sval;
|
||||
char cval;
|
||||
};
|
||||
|
||||
/**
|
||||
* Complex (nested) Structure to test dynamic allocation using malloc.
|
||||
*/
|
||||
struct complexStructure{
|
||||
struct threadInfo *sthreadInfo;
|
||||
__device__ void alloc_internal_members(int test_type, size_t size) {
|
||||
sthreadInfo = nullptr;
|
||||
if (test_type == TEST_MALLOC_FREE) {
|
||||
sthreadInfo = reinterpret_cast<struct threadInfo*>(
|
||||
malloc(size*sizeof(struct threadInfo)));
|
||||
} else {
|
||||
sthreadInfo = new struct threadInfo[size];
|
||||
}
|
||||
}
|
||||
|
||||
__device__ void free_internal_members(int test_type) {
|
||||
if (test_type == TEST_MALLOC_FREE) {
|
||||
free(sthreadInfo);
|
||||
} else {
|
||||
delete[] sthreadInfo;
|
||||
}
|
||||
sthreadInfo = nullptr;
|
||||
}
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "./defs.h"
|
||||
|
||||
/**
|
||||
* This kernel allocates memory in thread 0.
|
||||
*/
|
||||
extern "C" __global__ void ker_Alloc_MultCodeObj(int **dev_mem,
|
||||
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 =
|
||||
reinterpret_cast<int*> (malloc(blockDim.x*gridDim.x*sizeof(int)));
|
||||
} else {
|
||||
*dev_mem =
|
||||
reinterpret_cast<int*> (new int[blockDim.x*gridDim.x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "./defs.h"
|
||||
/**
|
||||
* This kernel allocates and deallocates memory in every thread.
|
||||
*/
|
||||
extern "C" __global__ void ker_TestDynamicAllocInAllThreads_CodeObj(
|
||||
int *outputBuf, int test_type, int value,
|
||||
size_t perThreadSize) {
|
||||
int myId = threadIdx.x + blockDim.x * blockIdx.x;
|
||||
// Allocate
|
||||
size_t size = 0;
|
||||
int* ptr = nullptr;
|
||||
if (test_type == TEST_MALLOC_FREE) {
|
||||
size = perThreadSize * sizeof(int);
|
||||
ptr = reinterpret_cast<int*> (malloc(size));
|
||||
} else {
|
||||
size = perThreadSize;
|
||||
ptr = new int[perThreadSize];
|
||||
}
|
||||
if (ptr == nullptr) {
|
||||
printf("Device Allocation in thread %d Failed! \n", myId);
|
||||
return;
|
||||
}
|
||||
// Set memory
|
||||
for (size_t idx = 0; idx < perThreadSize; idx++) {
|
||||
ptr[idx] = value;
|
||||
}
|
||||
// Copy to output buffer
|
||||
for (size_t idx = 0; idx < perThreadSize; idx++) {
|
||||
outputBuf[myId*perThreadSize + idx] = ptr[idx];
|
||||
}
|
||||
// Free memory
|
||||
if (test_type == TEST_MALLOC_FREE) {
|
||||
free(ptr);
|
||||
} else {
|
||||
delete[] ptr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "./defs.h"
|
||||
|
||||
/**
|
||||
* This kernel copies the contents of memory allocated in
|
||||
* ker_Alloc_MultCodeObj<<<>>> to host and deletes the memory
|
||||
* from thread 0.
|
||||
*/
|
||||
extern "C" __global__ void ker_Free_MultCodeObj(int *outputBuf,
|
||||
int **dev_mem, int test_type) {
|
||||
int myId = threadIdx.x + blockDim.x * blockIdx.x;
|
||||
// Check allocated memory in all threads in block before access
|
||||
if (*dev_mem == nullptr) {
|
||||
printf("Device Allocation Failed in thread = %d \n", myId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (0 == myId) {
|
||||
for (size_t idx = 0; idx < (blockDim.x*gridDim.x); idx++) {
|
||||
outputBuf[idx] = (*dev_mem)[idx];
|
||||
}
|
||||
if (test_type == TEST_MALLOC_FREE) {
|
||||
free(*dev_mem);
|
||||
} else {
|
||||
delete[] (*dev_mem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "./defs.h"
|
||||
|
||||
/**
|
||||
* This kernel writes to memory allocated in ker_Alloc_MultCodeObj<<<>>>.
|
||||
*/
|
||||
extern "C" __global__ void ker_Write_MultCodeObj(int **dev_mem,
|
||||
int value) {
|
||||
int myId = threadIdx.x + blockDim.x * blockIdx.x;
|
||||
// Check allocated memory in all threads in block before access
|
||||
if (*dev_mem == nullptr) {
|
||||
printf("Device Allocation Failed in thread = %d \n", myId);
|
||||
return;
|
||||
}
|
||||
// Copy to buffer
|
||||
(*dev_mem)[myId] = value;
|
||||
}
|
||||
Reference in New Issue
Block a user