SWDEV-470698 - fix formatting, add format check workflow (#657)
This commit is contained in:
committed by
GitHub
parent
5840940caa
commit
f7338717ae
@@ -27,7 +27,7 @@ static __device__ int devArr[N];
|
||||
//------------------------------------------------------------------------------
|
||||
// Kernel using hipLaunchKernelEx
|
||||
//------------------------------------------------------------------------------
|
||||
__global__ void cooperativeKernelEx(int *output, int totalThreads) {
|
||||
__global__ void cooperativeKernelEx(int* output, int totalThreads) {
|
||||
cooperative_groups::grid_group grid = cooperative_groups::this_grid();
|
||||
int tid = threadIdx.x + blockDim.x * blockIdx.x;
|
||||
if (tid < totalThreads) {
|
||||
@@ -41,7 +41,7 @@ __global__ void cooperativeKernelEx(int *output, int totalThreads) {
|
||||
//------------------------------------------------------------------------------
|
||||
// Kernel using hipLaunchKernelExC
|
||||
//------------------------------------------------------------------------------
|
||||
__global__ void cooperativeKernelExC(int *output, int totalThreads) {
|
||||
__global__ void cooperativeKernelExC(int* output, int totalThreads) {
|
||||
cooperative_groups::grid_group grid = cooperative_groups::this_grid();
|
||||
int tid = threadIdx.x + blockDim.x * blockIdx.x;
|
||||
if (tid < totalThreads) {
|
||||
@@ -61,7 +61,7 @@ static __global__ void emptyKernel() {}
|
||||
* Kernel which doesn't use cooperative groups and takes an argument
|
||||
* and updates the value with 100
|
||||
*/
|
||||
static __global__ void argKernel(int *val) { *val = 100; }
|
||||
static __global__ void argKernel(int* val) { *val = 100; }
|
||||
|
||||
/*
|
||||
* Kernel which uses cooperative groups and without any arguments
|
||||
@@ -79,7 +79,7 @@ static __global__ void coopEmptykernel() {
|
||||
* 2) Wait for all the blocks completes it's operations
|
||||
* 3) Fill each element in the output array with sum of elements in devArr
|
||||
*/
|
||||
static __global__ void coopFillArrayKernel(int *output) {
|
||||
static __global__ void coopFillArrayKernel(int* output) {
|
||||
cooperative_groups::grid_group grid = cooperative_groups::this_grid();
|
||||
|
||||
if (blockIdx.x == 0)
|
||||
@@ -110,7 +110,7 @@ static __global__ void coopFillArrayKernel(int *output) {
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void normalKernel(int *output, int totalThreads) {
|
||||
__global__ void normalKernel(int* output, int totalThreads) {
|
||||
int tid = threadIdx.x + blockDim.x * blockIdx.x;
|
||||
if (tid < totalThreads) {
|
||||
output[tid] = tid * 3;
|
||||
@@ -157,10 +157,10 @@ TEST_CASE("Unit_hipLaunchKernelExC_NegetiveTsts") {
|
||||
config.attrs = &attr;
|
||||
config.numAttrs = 1;
|
||||
|
||||
int *d_output = nullptr;
|
||||
int* d_output = nullptr;
|
||||
HIP_CHECK(hipMalloc(&d_output, totalThreads * sizeof(int)));
|
||||
HIP_CHECK(hipMemset(d_output, 0, totalThreads * sizeof(int)));
|
||||
void *kernelArgs[] = {&d_output, (void *)&totalThreads};
|
||||
void* kernelArgs[] = {&d_output, (void*)&totalThreads};
|
||||
|
||||
SECTION("Kernel function as nullptr") {
|
||||
HIP_CHECK_ERROR(hipLaunchKernelExC(&config, nullptr, kernelArgs),
|
||||
@@ -168,15 +168,12 @@ TEST_CASE("Unit_hipLaunchKernelExC_NegetiveTsts") {
|
||||
}
|
||||
|
||||
SECTION("Kernel args as nullptr") {
|
||||
HIP_CHECK_ERROR(
|
||||
hipLaunchKernelExC(&config, (void *)cooperativeKernelExC, nullptr),
|
||||
hipErrorInvalidValue);
|
||||
HIP_CHECK_ERROR(hipLaunchKernelExC(&config, (void*)cooperativeKernelExC, nullptr),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("Non Cooparative Kernel") {
|
||||
HIP_CHECK_ERROR(
|
||||
hipLaunchKernelExC(&config, (void *)normalKernel, kernelArgs),
|
||||
hipSuccess);
|
||||
HIP_CHECK_ERROR(hipLaunchKernelExC(&config, (void*)normalKernel, kernelArgs), hipSuccess);
|
||||
}
|
||||
|
||||
hipLaunchConfig_t invalidConfig = {};
|
||||
@@ -192,9 +189,7 @@ TEST_CASE("Unit_hipLaunchKernelExC_NegetiveTsts") {
|
||||
invalidConfig.numAttrs = 1;
|
||||
|
||||
SECTION("Invalid Kernel Config") {
|
||||
HIP_CHECK_ERROR(hipLaunchKernelExC(&invalidConfig,
|
||||
(void *)cooperativeKernelExC,
|
||||
kernelArgs),
|
||||
HIP_CHECK_ERROR(hipLaunchKernelExC(&invalidConfig, (void*)cooperativeKernelExC, kernelArgs),
|
||||
hipErrorInvalidConfiguration);
|
||||
}
|
||||
}
|
||||
@@ -231,7 +226,7 @@ TEST_CASE("Unit_hipLaunchKernelEx_NegetiveTsts") {
|
||||
config.attrs = &attr;
|
||||
config.numAttrs = 1;
|
||||
|
||||
int *d_output = nullptr;
|
||||
int* d_output = nullptr;
|
||||
HIP_CHECK(hipMalloc(&d_output, totalThreads * sizeof(int)));
|
||||
HIP_CHECK(hipMemset(d_output, 0, totalThreads * sizeof(int)));
|
||||
|
||||
@@ -240,10 +235,9 @@ TEST_CASE("Unit_hipLaunchKernelEx_NegetiveTsts") {
|
||||
}
|
||||
|
||||
SECTION("Non Cooparative Kernel") {
|
||||
HIP_CHECK_ERROR(hipLaunchKernelEx(&config,
|
||||
(void (*)(int *, int))normalKernel,
|
||||
d_output, totalThreads),
|
||||
hipSuccess);
|
||||
HIP_CHECK_ERROR(
|
||||
hipLaunchKernelEx(&config, (void (*)(int*, int))normalKernel, d_output, totalThreads),
|
||||
hipSuccess);
|
||||
}
|
||||
|
||||
hipLaunchConfig_t invalidConfig = {};
|
||||
@@ -259,18 +253,17 @@ TEST_CASE("Unit_hipLaunchKernelEx_NegetiveTsts") {
|
||||
invalidConfig.numAttrs = 1;
|
||||
|
||||
SECTION("Invalid Kernel Config") {
|
||||
HIP_CHECK_ERROR(hipLaunchKernelEx(&invalidConfig,
|
||||
(void (*)(int *, int))cooperativeKernelEx,
|
||||
HIP_CHECK_ERROR(hipLaunchKernelEx(&invalidConfig, (void (*)(int*, int))cooperativeKernelEx,
|
||||
d_output, totalThreads),
|
||||
hipErrorInvalidConfiguration);
|
||||
}
|
||||
}
|
||||
|
||||
bool runTest(const char *testName, const void *kernelFunc, int totalThreads,
|
||||
int blockSize, int flagValue, bool useTemplate) {
|
||||
bool runTest(const char* testName, const void* kernelFunc, int totalThreads, int blockSize,
|
||||
int flagValue, bool useTemplate) {
|
||||
const int numBlocks = (totalThreads + blockSize - 1) / blockSize;
|
||||
|
||||
int *d_output = nullptr;
|
||||
int* d_output = nullptr;
|
||||
HIP_CHECK(hipMalloc(&d_output, totalThreads * sizeof(int)));
|
||||
HIP_CHECK(hipMemset(d_output, 0, totalThreads * sizeof(int)));
|
||||
|
||||
@@ -288,33 +281,31 @@ bool runTest(const char *testName, const void *kernelFunc, int totalThreads,
|
||||
|
||||
// For a kernel parameter declared as "int* output", pass the address of the
|
||||
// device pointer.
|
||||
void *kernelArgs[] = {&d_output, (void *)&totalThreads};
|
||||
void* kernelArgs[] = {&d_output, (void*)&totalThreads};
|
||||
|
||||
if (useTemplate) {
|
||||
HIP_CHECK(hipLaunchKernelEx(&config, (void (*)(int *, int))kernelFunc,
|
||||
d_output, totalThreads));
|
||||
HIP_CHECK(hipLaunchKernelEx(&config, (void (*)(int*, int))kernelFunc, d_output, totalThreads));
|
||||
} else {
|
||||
HIP_CHECK(hipLaunchKernelExC(&config, kernelFunc, kernelArgs));
|
||||
}
|
||||
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
|
||||
int *h_output = (int *)malloc(totalThreads * sizeof(int));
|
||||
HIP_CHECK(hipMemcpy(h_output, d_output, totalThreads * sizeof(int),
|
||||
hipMemcpyDeviceToHost));
|
||||
int* h_output = (int*)malloc(totalThreads * sizeof(int));
|
||||
HIP_CHECK(hipMemcpy(h_output, d_output, totalThreads * sizeof(int), hipMemcpyDeviceToHost));
|
||||
|
||||
// Verify results.
|
||||
bool success = true;
|
||||
if (h_output[0] != flagValue) {
|
||||
printf("%s test failed: Expected flag %d at index 0, got %d\n", testName,
|
||||
flagValue, h_output[0]);
|
||||
printf("%s test failed: Expected flag %d at index 0, got %d\n", testName, flagValue,
|
||||
h_output[0]);
|
||||
success = false;
|
||||
}
|
||||
for (int i = 1; i < totalThreads; i++) {
|
||||
int expectedValue = (flagValue == 1111) ? i : (i * 3);
|
||||
if (h_output[i] != expectedValue) {
|
||||
printf("%s test failed at index %d: Expected %d, got %d\n", testName, i,
|
||||
expectedValue, h_output[i]);
|
||||
printf("%s test failed at index %d: Expected %d, got %d\n", testName, i, expectedValue,
|
||||
h_output[i]);
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
@@ -344,12 +335,10 @@ TEST_CASE("Unit_hipLaunchKernelEx_Functional") {
|
||||
}
|
||||
std::string api_type = GENERATE("hipLaunchKernelEx", "hipLaunchKernelExC");
|
||||
if (api_type == "hipLaunchKernelEx") {
|
||||
REQUIRE(runTest(api_type.c_str(), (void *)cooperativeKernelEx, 64, 16, 2222,
|
||||
true) == true);
|
||||
REQUIRE(runTest(api_type.c_str(), (void*)cooperativeKernelEx, 64, 16, 2222, true) == true);
|
||||
}
|
||||
if (api_type == "hipLaunchKernelExC") {
|
||||
REQUIRE(runTest(api_type.c_str(), (void *)cooperativeKernelExC, 64, 16,
|
||||
1111, false) == true);
|
||||
REQUIRE(runTest(api_type.c_str(), (void*)cooperativeKernelExC, 64, 16, 1111, false) == true);
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -391,13 +380,10 @@ TEST_CASE("Unit_hipLaunchKernelEx_With_Different_Kernels") {
|
||||
config.numAttrs = 1;
|
||||
|
||||
SECTION("Normal kernel with no arguments") {
|
||||
SECTION("hipLaunchKernelEx") {
|
||||
HIP_CHECK(hipLaunchKernelEx(&config, emptyKernel));
|
||||
}
|
||||
SECTION("hipLaunchKernelEx") { HIP_CHECK(hipLaunchKernelEx(&config, emptyKernel)); }
|
||||
|
||||
SECTION("hipLaunchKernelExC") {
|
||||
HIP_CHECK(hipLaunchKernelExC(
|
||||
&config, reinterpret_cast<void *>(emptyKernel), nullptr));
|
||||
HIP_CHECK(hipLaunchKernelExC(&config, reinterpret_cast<void*>(emptyKernel), nullptr));
|
||||
}
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
}
|
||||
@@ -406,17 +392,14 @@ TEST_CASE("Unit_hipLaunchKernelEx_With_Different_Kernels") {
|
||||
config.gridDim = dim3{1, 1, 1};
|
||||
config.blockDim = dim3{1, 1, 1};
|
||||
|
||||
int *devMem = nullptr;
|
||||
int* devMem = nullptr;
|
||||
HIP_CHECK(hipMalloc(&devMem, sizeof(int)));
|
||||
|
||||
SECTION("hipLaunchKernelEx") {
|
||||
HIP_CHECK(hipLaunchKernelEx(&config, argKernel, devMem));
|
||||
}
|
||||
SECTION("hipLaunchKernelEx") { HIP_CHECK(hipLaunchKernelEx(&config, argKernel, devMem)); }
|
||||
|
||||
SECTION("hipLaunchKernelExC") {
|
||||
void *kernel_args[1] = {&devMem};
|
||||
HIP_CHECK(hipLaunchKernelExC(&config, reinterpret_cast<void *>(argKernel),
|
||||
kernel_args));
|
||||
void* kernel_args[1] = {&devMem};
|
||||
HIP_CHECK(hipLaunchKernelExC(&config, reinterpret_cast<void*>(argKernel), kernel_args));
|
||||
}
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
|
||||
@@ -426,13 +409,10 @@ TEST_CASE("Unit_hipLaunchKernelEx_With_Different_Kernels") {
|
||||
}
|
||||
|
||||
SECTION("Cooperative kernel with no arguments") {
|
||||
SECTION("hipLaunchKernelEx") {
|
||||
HIP_CHECK(hipLaunchKernelEx(&config, coopEmptykernel));
|
||||
}
|
||||
SECTION("hipLaunchKernelEx") { HIP_CHECK(hipLaunchKernelEx(&config, coopEmptykernel)); }
|
||||
|
||||
SECTION("hipLaunchKernelExC") {
|
||||
HIP_CHECK(hipLaunchKernelExC(
|
||||
&config, reinterpret_cast<void *>(coopEmptykernel), nullptr));
|
||||
HIP_CHECK(hipLaunchKernelExC(&config, reinterpret_cast<void*>(coopEmptykernel), nullptr));
|
||||
}
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
}
|
||||
@@ -475,7 +455,7 @@ TEST_CASE("Unit_hipLaunchKernelEx_With_CooperativeKernelWithArgs") {
|
||||
hostMem[i] = 0;
|
||||
}
|
||||
|
||||
int *devMem = nullptr;
|
||||
int* devMem = nullptr;
|
||||
HIP_CHECK(hipMalloc(&devMem, N * sizeof(int)));
|
||||
HIP_CHECK(hipMemcpy(devMem, hostMem, N * sizeof(int), hipMemcpyDefault));
|
||||
|
||||
@@ -484,9 +464,9 @@ TEST_CASE("Unit_hipLaunchKernelEx_With_CooperativeKernelWithArgs") {
|
||||
}
|
||||
|
||||
SECTION("hipLaunchKernelExC") {
|
||||
void *kernel_args[1] = {&devMem};
|
||||
HIP_CHECK(hipLaunchKernelExC(
|
||||
&config, reinterpret_cast<void *>(coopFillArrayKernel), kernel_args));
|
||||
void* kernel_args[1] = {&devMem};
|
||||
HIP_CHECK(
|
||||
hipLaunchKernelExC(&config, reinterpret_cast<void*>(coopFillArrayKernel), kernel_args));
|
||||
}
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
HIP_CHECK(hipMemcpy(hostMem, devMem, N * sizeof(int), hipMemcpyDefault));
|
||||
@@ -534,47 +514,35 @@ TEST_CASE("Unit_hipLaunchKernelEx_With_MaxBlockDims") {
|
||||
config.numAttrs = 1;
|
||||
|
||||
SECTION("blockDim.x == maxBlockDimX") {
|
||||
const unsigned int x =
|
||||
GetDeviceAttribute(hipDeviceAttributeMaxBlockDimX, 0);
|
||||
const unsigned int x = GetDeviceAttribute(hipDeviceAttributeMaxBlockDimX, 0);
|
||||
config.blockDim = dim3{x, 1, 1};
|
||||
|
||||
SECTION("hipLaunchKernelEx") {
|
||||
HIP_CHECK(hipLaunchKernelEx(&config, emptyKernel));
|
||||
}
|
||||
SECTION("hipLaunchKernelEx") { HIP_CHECK(hipLaunchKernelEx(&config, emptyKernel)); }
|
||||
|
||||
SECTION("hipLaunchKernelExC") {
|
||||
HIP_CHECK(hipLaunchKernelExC(
|
||||
&config, reinterpret_cast<void *>(emptyKernel), nullptr));
|
||||
HIP_CHECK(hipLaunchKernelExC(&config, reinterpret_cast<void*>(emptyKernel), nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("blockDim.y == maxBlockDimY") {
|
||||
const unsigned int y =
|
||||
GetDeviceAttribute(hipDeviceAttributeMaxBlockDimY, 0);
|
||||
const unsigned int y = GetDeviceAttribute(hipDeviceAttributeMaxBlockDimY, 0);
|
||||
config.blockDim = dim3{1, y, 1};
|
||||
|
||||
SECTION("hipLaunchKernelEx") {
|
||||
HIP_CHECK(hipLaunchKernelEx(&config, emptyKernel));
|
||||
}
|
||||
SECTION("hipLaunchKernelEx") { HIP_CHECK(hipLaunchKernelEx(&config, emptyKernel)); }
|
||||
|
||||
SECTION("hipLaunchKernelExC") {
|
||||
HIP_CHECK(hipLaunchKernelExC(
|
||||
&config, reinterpret_cast<void *>(emptyKernel), nullptr));
|
||||
HIP_CHECK(hipLaunchKernelExC(&config, reinterpret_cast<void*>(emptyKernel), nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("blockDim.z == maxBlockDimZ") {
|
||||
const unsigned int z =
|
||||
GetDeviceAttribute(hipDeviceAttributeMaxBlockDimZ, 0);
|
||||
const unsigned int z = GetDeviceAttribute(hipDeviceAttributeMaxBlockDimZ, 0);
|
||||
config.blockDim = dim3{1, 1, z};
|
||||
|
||||
SECTION("hipLaunchKernelEx") {
|
||||
HIP_CHECK(hipLaunchKernelEx(&config, emptyKernel));
|
||||
}
|
||||
SECTION("hipLaunchKernelEx") { HIP_CHECK(hipLaunchKernelEx(&config, emptyKernel)); }
|
||||
|
||||
SECTION("hipLaunchKernelExC") {
|
||||
HIP_CHECK(hipLaunchKernelExC(
|
||||
&config, reinterpret_cast<void *>(emptyKernel), nullptr));
|
||||
HIP_CHECK(hipLaunchKernelExC(&config, reinterpret_cast<void*>(emptyKernel), nullptr));
|
||||
}
|
||||
}
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
|
||||
Reference in New Issue
Block a user