SWDEV-470698 - fix formatting, add format check workflow (#657)

Dieser Commit ist enthalten in:
Danylo Lytovchenko verfasst und GitHub committed 2025-08-20 19:58:06 +05:30
1 Ursprung 5840940caa
Commit f7338717ae
1574 Dateien geändert
+162903 -199277

Keine Dateien entsprechen Ihrer Suche

@@ -17,16 +17,14 @@ OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip/hip_runtime.h>
extern "C" __global__ void bit_extract_kernel(uint32_t* C_d, const uint32_t*
A_d, size_t N) {
extern "C" __global__ void bit_extract_kernel(uint32_t* C_d, const uint32_t* A_d, size_t N) {
size_t offset = (blockIdx.x * blockDim.x + threadIdx.x);
size_t stride = blockDim.x * gridDim.x;
for (size_t i = offset; i < N; i += stride) {
#if HT_AMD
C_d[i] = __bitextract_u32(A_d[i], 8, 4);
#else /* defined __HIP_PLATFORM_NVIDIA__ or other path */
#else /* defined __HIP_PLATFORM_NVIDIA__ or other path */
C_d[i] = ((A_d[i] & 0xf00) >> 8);
#endif
}
}
@@ -18,7 +18,7 @@ THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <dlfcn.h>
/**
* @addtogroup hipLaunchKernelGGL hipLaunchCooperativeKernel
* @{
@@ -87,11 +87,10 @@ static bool launch_local_kernel() {
const unsigned blocks = 512;
const unsigned threadsPerBlock = 256;
hipLaunchKernelGGL(vector_add, dim3(blocks), dim3(threadsPerBlock),
0, 0, C_d, A_d, B_d, N);
hipLaunchKernelGGL(vector_add, dim3(blocks), dim3(threadsPerBlock), 0, 0, C_d, A_d, B_d, N);
HIPCHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
for (size_t i=0; i < N ; i++) {
for (size_t i = 0; i < N; i++) {
if (C_h[i] != (A_h[i] + B_h[i])) {
testResult = false;
break;
@@ -126,7 +125,7 @@ static bool launch_dynamically_loaded_kernel() {
return testResult;
}
int(*fp)() = reinterpret_cast<int(*)()>(sym);
int (*fp)() = reinterpret_cast<int (*)()>(sym);
ret = fp();
if (ret == 0) {
@@ -147,6 +146,6 @@ TEST_CASE("Unit_dynamic_loading_device_kernels_from_library") {
}
/**
* End doxygen group DynamicLoading.
* @}
*/
* End doxygen group DynamicLoading.
* @}
*/
@@ -17,7 +17,7 @@ OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <stdio.h>
#include <dlfcn.h>
#include <vector>
@@ -63,103 +63,94 @@ THE SOFTWARE.
* - HIP_VERSION >= 5.6
*/
void test_dynamicLoading(void* sym_hipGetDevice,
void* sym_hipMalloc,
void* sym_hipMemcpyHtoD,
void* sym_hipMemcpyDtoH,
void* sym_hipModuleLoad,
void* sym_hipGetDeviceProperties,
void* sym_hipModuleGetFunction,
void* sym_hipModuleLaunchKernel){
uint32_t *A_d, *C_d;
uint32_t *A_h, *C_h;
size_t N = 1000000;
size_t Nbytes = N * sizeof(uint32_t);
hipError_t (*dyn_hipGetDevice)(hipDevice_t*, int) = reinterpret_cast
<hipError_t (*)(hipDevice_t*, int)>(sym_hipGetDevice);
void test_dynamicLoading(void* sym_hipGetDevice, void* sym_hipMalloc, void* sym_hipMemcpyHtoD,
void* sym_hipMemcpyDtoH, void* sym_hipModuleLoad,
void* sym_hipGetDeviceProperties, void* sym_hipModuleGetFunction,
void* sym_hipModuleLaunchKernel) {
uint32_t *A_d, *C_d;
uint32_t *A_h, *C_h;
size_t N = 1000000;
size_t Nbytes = N * sizeof(uint32_t);
hipError_t (*dyn_hipGetDevice)(hipDevice_t*, int) =
reinterpret_cast<hipError_t (*)(hipDevice_t*, int)>(sym_hipGetDevice);
hipError_t (*dyn_hipMalloc)(void**, uint32_t) = reinterpret_cast
<hipError_t (*)(void**, uint32_t)>(sym_hipMalloc);
hipError_t (*dyn_hipMalloc)(void**, uint32_t) =
reinterpret_cast<hipError_t (*)(void**, uint32_t)>(sym_hipMalloc);
hipError_t (*dyn_hipMemcpyHtoD)(hipDeviceptr_t, void*, size_t) =
reinterpret_cast<hipError_t (*)(hipDeviceptr_t, void*,
size_t)>(sym_hipMemcpyHtoD);
hipError_t (*dyn_hipMemcpyHtoD)(hipDeviceptr_t, void*, size_t) =
reinterpret_cast<hipError_t (*)(hipDeviceptr_t, void*, size_t)>(sym_hipMemcpyHtoD);
hipError_t (*dyn_hipMemcpyDtoH)(void*, hipDeviceptr_t, size_t) =
reinterpret_cast<hipError_t (*)(void*, hipDeviceptr_t,
size_t)>(sym_hipMemcpyDtoH);
hipError_t (*dyn_hipMemcpyDtoH)(void*, hipDeviceptr_t, size_t) =
reinterpret_cast<hipError_t (*)(void*, hipDeviceptr_t, size_t)>(sym_hipMemcpyDtoH);
hipError_t (*dyn_hipModuleLoad)(hipModule_t*, const char*) = reinterpret_cast
<hipError_t (*)(hipModule_t*, const char*)>(sym_hipModuleLoad);
hipError_t (*dyn_hipModuleLoad)(hipModule_t*, const char*) =
reinterpret_cast<hipError_t (*)(hipModule_t*, const char*)>(sym_hipModuleLoad);
hipError_t (*dyn_hipGetDeviceProperties)(hipDeviceProp_t*, int) =
reinterpret_cast<hipError_t (*)(hipDeviceProp_t*, int)>
(sym_hipGetDeviceProperties);
hipError_t (*dyn_hipGetDeviceProperties)(hipDeviceProp_t*, int) =
reinterpret_cast<hipError_t (*)(hipDeviceProp_t*, int)>(sym_hipGetDeviceProperties);
hipError_t (*dyn_hipModuleGetFunction)(hipFunction_t*, hipModule_t,
const char*) = reinterpret_cast < hipError_t (*)(hipFunction_t*,
hipModule_t, const char*)>(sym_hipModuleGetFunction);
hipError_t (*dyn_hipModuleGetFunction)(hipFunction_t*, hipModule_t, const char*) =
reinterpret_cast<hipError_t (*)(hipFunction_t*, hipModule_t, const char*)>(
sym_hipModuleGetFunction);
hipError_t (*dyn_hipModuleLaunchKernel)(hipFunction_t, unsigned int,
unsigned int, unsigned int, unsigned int, unsigned int,
unsigned int, unsigned int, hipStream_t, void**, void**)
= reinterpret_cast<hipError_t(*) (hipFunction_t,
unsigned int, unsigned int, unsigned int, unsigned int,
unsigned int, unsigned int, unsigned int, hipStream_t,
void**, void**)>(sym_hipModuleLaunchKernel);
hipError_t (*dyn_hipModuleLaunchKernel)(hipFunction_t, unsigned int, unsigned int, unsigned int,
unsigned int, unsigned int, unsigned int, unsigned int,
hipStream_t, void**, void**) =
reinterpret_cast<hipError_t (*)(hipFunction_t, unsigned int, unsigned int, unsigned int,
unsigned int, unsigned int, unsigned int, unsigned int,
hipStream_t, void**, void**)>(sym_hipModuleLaunchKernel);
hipDevice_t device;
HIPCHECK(dyn_hipGetDevice(&device, 0));
hipDevice_t device;
HIPCHECK(dyn_hipGetDevice(&device, 0));
hipDeviceProp_t props;
HIPCHECK(dyn_hipGetDeviceProperties(&props, device));
A_h = reinterpret_cast<uint32_t*>(malloc(Nbytes));
REQUIRE(A_h != NULL);
C_h = reinterpret_cast<uint32_t*>(malloc(Nbytes));
REQUIRE(C_h != NULL);
hipDeviceProp_t props;
HIPCHECK(dyn_hipGetDeviceProperties(&props, device));
A_h = reinterpret_cast<uint32_t*>(malloc(Nbytes));
REQUIRE(A_h != NULL);
C_h = reinterpret_cast<uint32_t*>(malloc(Nbytes));
REQUIRE(C_h != NULL);
for (size_t i = 0; i < N; i++) {
A_h[i] = i;
}
for (size_t i = 0; i < N; i++) {
A_h[i] = i;
}
HIPCHECK(dyn_hipMalloc(reinterpret_cast<void**>(&A_d), Nbytes));
HIPCHECK(dyn_hipMalloc(reinterpret_cast<void**>(&C_d), Nbytes));
HIPCHECK(dyn_hipMalloc(reinterpret_cast<void**>(&A_d), Nbytes));
HIPCHECK(dyn_hipMalloc(reinterpret_cast<void**>(&C_d), Nbytes));
HIPCHECK(dyn_hipMemcpyHtoD((hipDeviceptr_t)(A_d), A_h, Nbytes));
HIPCHECK(dyn_hipMemcpyHtoD((hipDeviceptr_t)(A_d), A_h, Nbytes));
struct {
void* _Cd;
void* _Ad;
size_t _N;
} args;
args._Cd = reinterpret_cast<void**> (C_d);
args._Ad = reinterpret_cast<void**> (A_d);
args._N = static_cast<size_t> (N);
size_t size = sizeof(args);
struct {
void* _Cd;
void* _Ad;
size_t _N;
} args;
args._Cd = reinterpret_cast<void**>(C_d);
args._Ad = reinterpret_cast<void**>(A_d);
args._N = static_cast<size_t>(N);
size_t size = sizeof(args);
void* config[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args,
HIP_LAUNCH_PARAM_BUFFER_SIZE, &size, HIP_LAUNCH_PARAM_END};
void* config[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args, HIP_LAUNCH_PARAM_BUFFER_SIZE, &size,
HIP_LAUNCH_PARAM_END};
hipModule_t Module;
HIPCHECK(dyn_hipModuleLoad(&Module, fileName));
hipModule_t Module;
HIPCHECK(dyn_hipModuleLoad(&Module, fileName));
hipFunction_t Function;
HIPCHECK(dyn_hipModuleGetFunction(&Function, Module, "bit_extract_kernel"));
hipFunction_t Function;
HIPCHECK(dyn_hipModuleGetFunction(&Function, Module, "bit_extract_kernel"));
HIPCHECK(dyn_hipModuleLaunchKernel(Function, 1, 1, 1, LEN, 1, 1, 0, 0, NULL,
reinterpret_cast<void**>(&config)));
HIPCHECK(dyn_hipModuleLaunchKernel(Function, 1, 1, 1, LEN, 1, 1, 0, 0, NULL,
reinterpret_cast<void**>(&config)));
HIPCHECK(dyn_hipMemcpyDtoH(C_h, (hipDeviceptr_t)(C_d), Nbytes));
for (size_t i = 0; i < N; i++) {
unsigned Agold = ((A_h[i] & 0xf00) >> 8);
REQUIRE(C_h[i] == Agold);
}
HIPCHECK(hipFree(A_d));
HIPCHECK(hipFree(C_d));
free(A_h);
free(C_h);
HIPCHECK(dyn_hipMemcpyDtoH(C_h, (hipDeviceptr_t)(C_d), Nbytes));
for (size_t i = 0; i < N; i++) {
unsigned Agold = ((A_h[i] & 0xf00) >> 8);
REQUIRE(C_h[i] == Agold);
}
HIPCHECK(hipFree(A_d));
HIPCHECK(hipFree(C_d));
free(A_h);
free(C_h);
}
TEST_CASE("Unit_hipApiDynamicLoad_hipGetProcAddress") {
void* sym_hipGetDevice;
@@ -173,23 +164,21 @@ TEST_CASE("Unit_hipApiDynamicLoad_hipGetProcAddress") {
int currentHipVersion = 0;
HIPCHECK(hipRuntimeGetVersion(&currentHipVersion));
HIPCHECK(hipGetProcAddress("hipGetDevice", &sym_hipGetDevice, currentHipVersion, 0, nullptr));
HIPCHECK(hipGetProcAddress("hipMalloc", &sym_hipMalloc, currentHipVersion, 0, nullptr));
HIPCHECK(hipGetProcAddress("hipMemcpyHtoD", &sym_hipMemcpyHtoD, currentHipVersion, 0, nullptr));
HIPCHECK(hipGetProcAddress("hipMemcpyDtoH", &sym_hipMemcpyDtoH, currentHipVersion, 0, nullptr));
HIPCHECK(hipGetProcAddress("hipModuleLoad", &sym_hipModuleLoad, currentHipVersion, 0, nullptr));
HIPCHECK(hipGetProcAddress("hipGetDeviceProperties", &sym_hipGetDeviceProperties, currentHipVersion, 0, nullptr));
HIPCHECK(hipGetProcAddress("hipModuleGetFunction", &sym_hipModuleGetFunction, currentHipVersion, 0, nullptr));
HIPCHECK(hipGetProcAddress("hipModuleLaunchKernel", &sym_hipModuleLaunchKernel, currentHipVersion, 0, nullptr));
HIPCHECK(hipGetProcAddress("hipGetDeviceProperties", &sym_hipGetDeviceProperties,
currentHipVersion, 0, nullptr));
HIPCHECK(hipGetProcAddress("hipModuleGetFunction", &sym_hipModuleGetFunction, currentHipVersion,
0, nullptr));
HIPCHECK(hipGetProcAddress("hipModuleLaunchKernel", &sym_hipModuleLaunchKernel, currentHipVersion,
0, nullptr));
test_dynamicLoading(sym_hipGetDevice,
sym_hipMalloc,
sym_hipMemcpyHtoD,
sym_hipMemcpyDtoH,
sym_hipModuleLoad,
sym_hipGetDeviceProperties,
sym_hipModuleGetFunction,
test_dynamicLoading(sym_hipGetDevice, sym_hipMalloc, sym_hipMemcpyHtoD, sym_hipMemcpyDtoH,
sym_hipModuleLoad, sym_hipGetDeviceProperties, sym_hipModuleGetFunction,
sym_hipModuleLaunchKernel);
}
@@ -209,17 +198,12 @@ TEST_CASE("Unit_hipApiDynamicLoad") {
dlclose(handle);
test_dynamicLoading(sym_hipGetDevice,
sym_hipMalloc,
sym_hipMemcpyHtoD,
sym_hipMemcpyDtoH,
sym_hipModuleLoad,
sym_hipGetDeviceProperties,
sym_hipModuleGetFunction,
test_dynamicLoading(sym_hipGetDevice, sym_hipMalloc, sym_hipMemcpyHtoD, sym_hipMemcpyDtoH,
sym_hipModuleLoad, sym_hipGetDeviceProperties, sym_hipModuleGetFunction,
sym_hipModuleLaunchKernel);
}
/**
* End doxygen group DynamicLoading.
* @}
*/
* End doxygen group DynamicLoading.
* @}
*/
@@ -19,17 +19,17 @@ THE SOFTWARE.
#include <hip/hip_runtime.h>
#include <hip/hip_runtime_api.h>
#include <algorithm> // std::min
#include <algorithm> // std::min
#define CHECK_RET_VAL(cmd) \
{ \
hipError_t error = cmd;\
if (error != hipSuccess) {\
fprintf(stderr, "error: '%s'(%d) at %s:%d\n", hipGetErrorString(error), \
error, __FILE__, __LINE__);\
exit(EXIT_FAILURE);\
}\
}
#define CHECK_RET_VAL(cmd) \
{ \
hipError_t error = cmd; \
if (error != hipSuccess) { \
fprintf(stderr, "error: '%s'(%d) at %s:%d\n", hipGetErrorString(error), error, __FILE__, \
__LINE__); \
exit(EXIT_FAILURE); \
} \
}
__global__ static void addition(float* C, float* A, float* B, size_t N) {
size_t offset = hipBlockIdx_x * hipBlockDim_x + hipThreadIdx_x;
@@ -72,11 +72,10 @@ static int vectorAddKernelTest() {
const unsigned blocks = 512;
const unsigned threadsPerBlock = 256;
hipLaunchKernelGGL(addition, dim3(blocks), dim3(threadsPerBlock),
0, 0, C_d, A_d, B_d, N);
hipLaunchKernelGGL(addition, dim3(blocks), dim3(threadsPerBlock), 0, 0, C_d, A_d, B_d, N);
CHECK_RET_VAL(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
for (size_t i=0; i < N ; i++) {
for (size_t i = 0; i < N; i++) {
if (C_h[i] != (A_h[i] + B_h[i])) {
testResult = 0;
break;
@@ -99,17 +98,16 @@ namespace cg = cooperative_groups;
static const uint BufferSizeInDwords = 448 * 1024 * 1024;
__global__ static void test_gws(uint* buf, uint bufSize,
int64_t* tmpBuf, int64_t* result) {
__global__ static void test_gws(uint* buf, uint bufSize, int64_t* tmpBuf, int64_t* result) {
extern __shared__ int64_t tmp[];
uint offset = blockIdx.x * blockDim.x + threadIdx.x;
uint stride = gridDim.x * blockDim.x;
uint stride = gridDim.x * blockDim.x;
cg::grid_group gg = cg::this_grid();
int64_t sum = 0;
for (uint i = offset; i < bufSize; i += stride) {
sum += buf[i];
sum += buf[i];
}
tmp[threadIdx.x] = sum;
@@ -163,7 +161,7 @@ static int cooperativeKernelTest() {
CHECK_RET_VAL(hipStreamCreate(&stream));
dim3 dimBlock = dim3(1);
dim3 dimGrid = dim3(1);
dim3 dimGrid = dim3(1);
int numBlocks = 0;
uint workgroups[4] = {32, 64, 128, 256};
@@ -172,27 +170,23 @@ static int cooperativeKernelTest() {
dimBlock.x = workgroups[i];
/* Calculate the device occupancy to know how many blocks can be
run concurrently */
hipOccupancyMaxActiveBlocksPerMultiprocessor(&numBlocks,
test_gws, dimBlock.x * dimBlock.y * dimBlock.z, dimBlock.x *
sizeof(int64_t));
hipOccupancyMaxActiveBlocksPerMultiprocessor(
&numBlocks, test_gws, dimBlock.x * dimBlock.y * dimBlock.z, dimBlock.x * sizeof(int64_t));
dimGrid.x = deviceProp.multiProcessorCount * std::min(numBlocks, 32);
CHECK_RET_VAL(hipMalloc(reinterpret_cast<void**>(&dB),
dimGrid.x * sizeof(int64_t)));
CHECK_RET_VAL(hipMalloc(reinterpret_cast<void**>(&dB), dimGrid.x * sizeof(int64_t)));
void *params[4];
void* params[4];
params[0] = reinterpret_cast<void*>(&dA);
params[1] = (void*)(&BufferSizeInDwords); // NOLINT
params[2] = reinterpret_cast<void*>(&dB);
params[3] = reinterpret_cast<void*>(&dC);
CHECK_RET_VAL(hipLaunchCooperativeKernel(reinterpret_cast<void*>(test_gws),
dimGrid, dimBlock, params,
dimBlock.x * sizeof(int64_t), stream));
CHECK_RET_VAL(hipLaunchCooperativeKernel(reinterpret_cast<void*>(test_gws), dimGrid, dimBlock,
params, dimBlock.x * sizeof(int64_t), stream));
CHECK_RET_VAL(hipMemcpy(Ah, dC, sizeof(int64_t), hipMemcpyDeviceToHost));
if (*Ah != (((int64_t)(BufferSizeInDwords) * (BufferSizeInDwords - 1))
/ 2)) {
if (*Ah != (((int64_t)(BufferSizeInDwords) * (BufferSizeInDwords - 1)) / 2)) {
CHECK_RET_VAL(hipFree(dB));
testResult = 0;
break;
@@ -204,11 +198,9 @@ static int cooperativeKernelTest() {
CHECK_RET_VAL(hipStreamDestroy(stream));
CHECK_RET_VAL(hipFree(dC));
CHECK_RET_VAL(hipFree(dA));
delete [] init;
delete[] init;
free(Ah);
return testResult;
}
extern "C" int lazyLoad() {
return vectorAddKernelTest() & cooperativeKernelTest();
}
extern "C" int lazyLoad() { return vectorAddKernelTest() & cooperativeKernelTest(); }
@@ -18,7 +18,7 @@ THE SOFTWARE.
*/
#include <hip/hip_runtime.h>
__global__ void kerAdd(int *in_a, int *in_b, int *out_c, int nelem) {
__global__ void kerAdd(int* in_a, int* in_b, int* out_c, int nelem) {
int id = blockIdx.x * blockDim.x + threadIdx.x;
if (id >= nelem) {
return;