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

此提交包含在:
Danylo Lytovchenko
2025-08-20 16:28:06 +02:00
提交者 GitHub
父節點 5840940caa
當前提交 f7338717ae
共有 1574 個檔案被更改,包括 162972 行新增199346 行删除
檔案差異因為檔案過大而無法顯示 載入差異
+176 -227
查看文件
@@ -30,34 +30,33 @@ THE SOFTWARE.
namespace cg = cooperative_groups;
namespace DefltStrmPT {
int64_t N = 1024 * 1024 * 100;
int64_t Sz = N * sizeof(int64_t);
int64_t *DevA, *HstA, *HstRes;
int64_t OneMB = 1024 * 1024;
int64_t OneMBSz = OneMB * sizeof(int64_t);
hipStream_t Strm;
int clockrate, CONST = 123;
size_t numH = 1024, numW = 1024;
size_t pitch_A, width = numW * sizeof(int64_t);
size_t sizeElements = width * numH;
size_t elements = numW * numH;
int64_t N = 1024 * 1024 * 100;
int64_t Sz = N * sizeof(int64_t);
int64_t *DevA, *HstA, *HstRes;
int64_t OneMB = 1024 * 1024;
int64_t OneMBSz = OneMB * sizeof(int64_t);
hipStream_t Strm;
int clockrate, CONST = 123;
size_t numH = 1024, numW = 1024;
size_t pitch_A, width = numW * sizeof(int64_t);
size_t sizeElements = width * numH;
size_t elements = numW * numH;
} // namespace DefltStrmPT
__device__ int64_t globalInDStrmPT[1024 * 1024];
__managed__ int SigComplte = 0;
// Kernel codes
__global__ void DefltStrmPT_Square(int64_t *C_d, int64_t N) {
int64_t offset = (hipBlockIdx_x * hipBlockDim_x + hipThreadIdx_x);
int64_t stride = hipBlockDim_x * hipGridDim_x;
__global__ void DefltStrmPT_Square(int64_t* C_d, int64_t N) {
int64_t offset = (hipBlockIdx_x * hipBlockDim_x + hipThreadIdx_x);
int64_t stride = hipBlockDim_x * hipGridDim_x;
for (int64_t i = offset; i < N; i += stride) {
C_d[i] = C_d[i] * C_d[i];
}
for (int64_t i = offset; i < N; i += stride) {
C_d[i] = C_d[i] * C_d[i];
}
}
__global__ void Wait_Kernel3(int clockrate, uint64_t WaitSecs,
int PassSignal = 0) {
__global__ void Wait_Kernel3(int clockrate, uint64_t WaitSecs, int PassSignal = 0) {
uint64_t num_cycles = WaitSecs * clockrate * 1000;
uint64_t start = clock64(), cycles = 0;
while (cycles < num_cycles) {
@@ -68,88 +67,83 @@ __global__ void Wait_Kernel3(int clockrate, uint64_t WaitSecs,
}
}
static __global__ void notifiedKernel(volatile unsigned int *notified, int PassSignal = 0) {
while (*notified == 0) {} // wait until notified to exit.
static __global__ void notifiedKernel(volatile unsigned int* notified, int PassSignal = 0) {
while (*notified == 0) {
} // wait until notified to exit.
if (PassSignal) {
SigComplte = 1;
}
}
__global__ void DefltStrmPT_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;
cg::grid_group gg = cg::this_grid();
__global__ void DefltStrmPT_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;
cg::grid_group gg = cg::this_grid();
int64_t sum = 0;
for (uint i = offset; i < bufSize; i += stride) {
sum += buf[i];
int64_t sum = 0;
for (uint i = offset; i < bufSize; i += stride) {
sum += buf[i];
}
tmp[threadIdx.x] = sum;
__syncthreads();
if (threadIdx.x == 0) {
sum = 0;
for (uint i = 0; i < blockDim.x; i++) {
sum += tmp[i];
}
tmp[threadIdx.x] = sum;
tmpBuf[blockIdx.x] = sum;
}
__syncthreads();
gg.sync();
if (threadIdx.x == 0) {
sum = 0;
for (uint i = 0; i < blockDim.x; i++) {
sum += tmp[i];
}
tmpBuf[blockIdx.x] = sum;
}
gg.sync();
if (offset == 0) {
for (uint i = 1; i < gridDim.x; ++i) {
sum += tmpBuf[i];
}
*result = sum;
if (offset == 0) {
for (uint i = 1; i < gridDim.x; ++i) {
sum += tmpBuf[i];
}
*result = sum;
}
}
float DefaultPT2_Memcpy_MemSet(int CpyAsync, int MemSetAsync) {
bool IfTstPassed = true;
DefltStrmPT::HstA = reinterpret_cast<int64_t*> (malloc(DefltStrmPT::Sz));
DefltStrmPT::HstRes = reinterpret_cast<int64_t*> (malloc(DefltStrmPT::Sz));
HIP_CHECK(hipDeviceGetAttribute(&(DefltStrmPT::clockrate),
hipDeviceAttributeMemoryClockRate, 0));
DefltStrmPT::HstA = reinterpret_cast<int64_t*>(malloc(DefltStrmPT::Sz));
DefltStrmPT::HstRes = reinterpret_cast<int64_t*>(malloc(DefltStrmPT::Sz));
HIP_CHECK(hipDeviceGetAttribute(&(DefltStrmPT::clockrate), hipDeviceAttributeMemoryClockRate, 0));
HIP_CHECK(hipMalloc(&(DefltStrmPT::DevA), DefltStrmPT::Sz));
for (int64_t i = 0; i < DefltStrmPT::N; ++i) {
DefltStrmPT::HstA[i] = DefltStrmPT::CONST;
}
HIP_CHECK(hipStreamCreate(&(DefltStrmPT::Strm)));
if (CpyAsync) {
HIP_CHECK(hipMemcpyAsync(DefltStrmPT::DevA, DefltStrmPT::HstA,
DefltStrmPT::Sz, hipMemcpyHostToDevice,
DefltStrmPT::Strm));
HIP_CHECK(hipMemcpyAsync(DefltStrmPT::DevA, DefltStrmPT::HstA, DefltStrmPT::Sz,
hipMemcpyHostToDevice, DefltStrmPT::Strm));
HIP_CHECK(hipStreamSynchronize(DefltStrmPT::Strm));
} else {
HIP_CHECK(hipMemcpy(DefltStrmPT::DevA, DefltStrmPT::HstA,
DefltStrmPT::Sz, hipMemcpyHostToDevice));
HIP_CHECK(
hipMemcpy(DefltStrmPT::DevA, DefltStrmPT::HstA, DefltStrmPT::Sz, hipMemcpyHostToDevice));
}
DefltStrmPT_Square<<<(DefltStrmPT::N/256 + 1), 256, 0, DefltStrmPT::Strm>>>
(DefltStrmPT::DevA, DefltStrmPT::N);
DefltStrmPT_Square<<<(DefltStrmPT::N / 256 + 1), 256, 0, DefltStrmPT::Strm>>>(DefltStrmPT::DevA,
DefltStrmPT::N);
HIP_CHECK(hipStreamSynchronize(DefltStrmPT::Strm));
HIP_CHECK(hipMemcpy(DefltStrmPT::HstRes, DefltStrmPT::DevA,
DefltStrmPT::Sz, hipMemcpyDeviceToHost));
HIP_CHECK(
hipMemcpy(DefltStrmPT::HstRes, DefltStrmPT::DevA, DefltStrmPT::Sz, hipMemcpyDeviceToHost));
// Verifying the result
for (int64_t i = 0; i < DefltStrmPT::N; ++i) {
if (DefltStrmPT::HstRes[i] !=
(DefltStrmPT::HstA[i] * DefltStrmPT::HstA[i])) {
if (DefltStrmPT::HstRes[i] != (DefltStrmPT::HstA[i] * DefltStrmPT::HstA[i])) {
IfTstPassed = false;
}
}
if (MemSetAsync) {
HIP_CHECK(hipMemsetAsync(DefltStrmPT::DevA, 0, DefltStrmPT::Sz,
DefltStrmPT::Strm));
HIP_CHECK(hipMemsetAsync(DefltStrmPT::DevA, 0, DefltStrmPT::Sz, DefltStrmPT::Strm));
HIP_CHECK(hipStreamSynchronize(DefltStrmPT::Strm));
} else {
HIP_CHECK(hipMemset(DefltStrmPT::DevA, 0,
DefltStrmPT::Sz));
HIP_CHECK(hipMemset(DefltStrmPT::DevA, 0, DefltStrmPT::Sz));
}
// Copying the device memory to host to check if Memset is successful
HIP_CHECK(hipMemcpy(DefltStrmPT::HstA, DefltStrmPT::DevA,
DefltStrmPT::Sz, hipMemcpyDeviceToHost));
HIP_CHECK(
hipMemcpy(DefltStrmPT::HstA, DefltStrmPT::DevA, DefltStrmPT::Sz, hipMemcpyDeviceToHost));
// verifying if memset was successful
for (int64_t i = 0; i < DefltStrmPT::N; ++i) {
if (DefltStrmPT::HstA[i] != 0) {
@@ -173,8 +167,7 @@ void DefaultPT2_Memset2D(int Async) {
size_t elements = numW * numH;
char *A_d, *A_h;
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d), &pitch_A, width,
numH));
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d), &pitch_A, width, numH));
A_h = reinterpret_cast<char*>(malloc(sizeElements));
REQUIRE(A_h != nullptr);
@@ -191,13 +184,12 @@ void DefaultPT2_Memset2D(int Async) {
} else {
HIP_CHECK(hipMemset2D(A_d, pitch_A, memsetval, numW, numH));
}
HIP_CHECK(hipMemcpy2D(A_h, width, A_d, pitch_A, numW, numH,
hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy2D(A_h, width, A_d, pitch_A, numW, numH, hipMemcpyDeviceToHost));
for (size_t i = 0; i < elements; i++) {
if (A_h[i] != memsetval) {
INFO("Memset2D mismatch at index:" << i << " computed:"
<< A_h[i] << " memsetval:" << memsetval);
INFO("Memset2D mismatch at index:" << i << " computed:" << A_h[i]
<< " memsetval:" << memsetval);
REQUIRE(false);
}
}
@@ -215,17 +207,17 @@ void PerThrdDefltStrm_Memset3D(int Async) {
size_t width = numW * sizeof(char);
size_t sizeElements = width * numH * depth;
size_t elements = numW * numH * depth;
char *A_h;
char* A_h;
hipExtent extent = make_hipExtent(width, numH, depth);
hipPitchedPtr devPitchedPtr;
HIP_CHECK(hipMalloc3D(&devPitchedPtr, extent));
A_h = reinterpret_cast<char *>(malloc(sizeElements));
A_h = reinterpret_cast<char*>(malloc(sizeElements));
if (A_h == nullptr) REQUIRE(false);
for (size_t i = 0; i < elements; i++) {
A_h[i] = 1;
A_h[i] = 1;
}
if (Async) {
@@ -240,7 +232,7 @@ void PerThrdDefltStrm_Memset3D(int Async) {
hipMemcpy3DParms myparms{};
myparms.srcPos = make_hipPos(0, 0, 0);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.dstPtr = make_hipPitchedPtr(A_h, width , numW, numH);
myparms.dstPtr = make_hipPitchedPtr(A_h, width, numW, numH);
myparms.srcPtr = devPitchedPtr;
myparms.extent = extent;
#if HT_NVIDIA
@@ -251,11 +243,11 @@ void PerThrdDefltStrm_Memset3D(int Async) {
HIP_CHECK(hipMemcpy3D(&myparms));
for (size_t i = 0; i < elements; i++) {
if (A_h[i] != memsetval) {
INFO("Memset3D mismatch at index:" << i << " computed:"
<< A_h[i] << " memsetval:" << memsetval);
REQUIRE(false);
}
if (A_h[i] != memsetval) {
INFO("Memset3D mismatch at index:" << i << " computed:" << A_h[i]
<< " memsetval:" << memsetval);
REQUIRE(false);
}
}
HIP_CHECK(hipFree(devPitchedPtr.ptr));
free(A_h);
@@ -263,7 +255,7 @@ void PerThrdDefltStrm_Memset3D(int Async) {
void DefaultPT2_StrmQuery() {
unsigned int *notified = nullptr;
unsigned int* notified = nullptr;
HIP_CHECK(hipHostMalloc(&notified, sizeof(unsigned int)));
*notified = 0;
HIP_CHECK(hipStreamCreate(&(DefltStrmPT::Strm)));
@@ -279,8 +271,7 @@ void DefaultPT2_StrmQuery() {
void DefaultPT2_StreamSync() {
HIP_CHECK(hipDeviceGetAttribute(&(DefltStrmPT::clockrate),
hipDeviceAttributeMemoryClockRate, 0));
HIP_CHECK(hipDeviceGetAttribute(&(DefltStrmPT::clockrate), hipDeviceAttributeMemoryClockRate, 0));
HIP_CHECK(hipStreamCreate(&(DefltStrmPT::Strm)));
// Calling hipStreamSync on user created stream object
Wait_Kernel3<<<1, 1, 0, DefltStrmPT::Strm>>>(DefltStrmPT::clockrate, 1);
@@ -302,7 +293,7 @@ void DefaultPT2_StrmWaitEvent() {
hipEvent_t evt;
hipStream_t Strm1;
unsigned int *notified = nullptr;
unsigned int* notified = nullptr;
HIP_CHECK(hipHostMalloc(&notified, sizeof(unsigned int)));
*notified = 0;
HIP_CHECK(hipStreamCreate(&(DefltStrmPT::Strm)));
@@ -332,7 +323,7 @@ void DefaultPT2_StrmWaitEvent() {
void DefaultPT2_EvtQuery() {
hipEvent_t evt, evt1;
hipError_t err;
unsigned int *notified = nullptr;
unsigned int* notified = nullptr;
HIP_CHECK(hipHostMalloc(&notified, sizeof(unsigned int)));
*notified = 0;
HIP_CHECK(hipStreamCreate(&(DefltStrmPT::Strm)));
@@ -348,7 +339,7 @@ void DefaultPT2_EvtQuery() {
HIP_CHECK(hipEventRecord(evt1, 0));
int Got_hipSuccess = 0; // 0 for no, 1 for yes
std::this_thread::sleep_for(std::chrono::milliseconds(500));
*notified = 1; // notify to exit
*notified = 1; // notify to exit
std::chrono::time_point start = std::chrono::steady_clock::now();
while (true) {
err = hipEventQuery(evt1);
@@ -371,33 +362,31 @@ void DefaultPT2_EvtQuery() {
void Default_LaunchKernel(int NullStrm) {
DefltStrmPT::N = DefltStrmPT::N/4;
DefltStrmPT::N = DefltStrmPT::N / 4;
DefltStrmPT::Sz = DefltStrmPT::N * sizeof(int64_t);
DefltStrmPT::HstA = reinterpret_cast<int64_t*> (malloc(DefltStrmPT::Sz));
DefltStrmPT::HstA = reinterpret_cast<int64_t*>(malloc(DefltStrmPT::Sz));
HIP_CHECK(hipMalloc(&(DefltStrmPT::DevA), DefltStrmPT::Sz));
for (int64_t i = 0; i < DefltStrmPT::N; ++i) {
DefltStrmPT::HstA[i] = DefltStrmPT::CONST;
}
HIP_CHECK(hipMemcpy(DefltStrmPT::DevA, DefltStrmPT::HstA, DefltStrmPT::Sz,
hipMemcpyHostToDevice));
HIP_CHECK(
hipMemcpy(DefltStrmPT::DevA, DefltStrmPT::HstA, DefltStrmPT::Sz, hipMemcpyHostToDevice));
HIP_CHECK(hipStreamCreate(&(DefltStrmPT::Strm)));
unsigned ThrdsPerBlk = 32;
unsigned Blocks = ((DefltStrmPT::N + ThrdsPerBlk - 1)/ThrdsPerBlk);
void *Args[] = {&(DefltStrmPT::DevA), &(DefltStrmPT::N)};
unsigned Blocks = ((DefltStrmPT::N + ThrdsPerBlk - 1) / ThrdsPerBlk);
void* Args[] = {&(DefltStrmPT::DevA), &(DefltStrmPT::N)};
// launch Kernel
if (NullStrm) {
HIP_CHECK(hipLaunchKernel((const void*)DefltStrmPT_Square,
dim3(Blocks, 1, 1), dim3(ThrdsPerBlk, 1, 1), Args, 0,
0));
HIP_CHECK(hipLaunchKernel((const void*)DefltStrmPT_Square, dim3(Blocks, 1, 1),
dim3(ThrdsPerBlk, 1, 1), Args, 0, 0));
HIP_CHECK(hipStreamSynchronize(0));
} else {
HIP_CHECK(hipLaunchKernel((const void*)DefltStrmPT_Square,
dim3(Blocks, 1, 1), dim3(ThrdsPerBlk, 1, 1), Args, 0,
DefltStrmPT::Strm));
HIP_CHECK(hipLaunchKernel((const void*)DefltStrmPT_Square, dim3(Blocks, 1, 1),
dim3(ThrdsPerBlk, 1, 1), Args, 0, DefltStrmPT::Strm));
HIP_CHECK(hipStreamSynchronize(DefltStrmPT::Strm));
}
HIP_CHECK(hipMemcpy(DefltStrmPT::HstA, DefltStrmPT::DevA, DefltStrmPT::Sz,
hipMemcpyDeviceToHost));
HIP_CHECK(
hipMemcpy(DefltStrmPT::HstA, DefltStrmPT::DevA, DefltStrmPT::Sz, hipMemcpyDeviceToHost));
for (int64_t i = 0; i < DefltStrmPT::N; ++i) {
if (DefltStrmPT::HstA[i] != (DefltStrmPT::CONST * DefltStrmPT::CONST)) {
REQUIRE(false);
@@ -411,7 +400,7 @@ void Default_LaunchKernel(int NullStrm) {
void DefaultPT2_LaunchCooperativeKernel(int NullStrm) {
bool IfTestPassed = true;
uint32_t *dA;
uint32_t* dA;
int64_t *dB, *dC;
uint32_t BufferSizeInDwords = 448 * 1024 * 1024;
uint32_t* init = new uint32_t[BufferSizeInDwords];
@@ -427,49 +416,45 @@ void DefaultPT2_LaunchCooperativeKernel(int NullStrm) {
HIPCHECK(hipMemcpy(dA, init, SIZE, hipMemcpyHostToDevice));
dim3 dimBlock = dim3(1);
dim3 dimGrid = dim3(1);
dim3 dimGrid = dim3(1);
int numBlocks = 0;
dimBlock.x = 32;
// Calculate the device occupancy to know how many blocks can be run
// concurrently
HIP_CHECK(hipOccupancyMaxActiveBlocksPerMultiprocessor(&numBlocks,
DefltStrmPT_Test_gws,
dimBlock.x * dimBlock.y * dimBlock.z,
dimBlock.x * sizeof(int64_t)));
HIP_CHECK(hipOccupancyMaxActiveBlocksPerMultiprocessor(&numBlocks, DefltStrmPT_Test_gws,
dimBlock.x * dimBlock.y * dimBlock.z,
dimBlock.x * sizeof(int64_t)));
dimGrid.x = deviceProp.multiProcessorCount * std::min(numBlocks, 32);
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&dB),
dimGrid.x * sizeof(int64_t)));
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&dB), dimGrid.x * sizeof(int64_t)));
void *params[4];
void* params[4];
params[0] = reinterpret_cast<void*>(&dA);
params[1] = reinterpret_cast<void*>(&BufferSizeInDwords);
params[2] = reinterpret_cast<void*>(&dB);
params[3] = reinterpret_cast<void*>(&dC);
if (NullStrm) {
HIPCHECK(hipLaunchCooperativeKernel(
reinterpret_cast<void*>(DefltStrmPT_Test_gws),
dimGrid, dimBlock, params, dimBlock.x * sizeof(int64_t), 0));
HIPCHECK(hipLaunchCooperativeKernel(reinterpret_cast<void*>(DefltStrmPT_Test_gws), dimGrid,
dimBlock, params, dimBlock.x * sizeof(int64_t), 0));
HIP_CHECK(hipStreamSynchronize(0));
} else {
HIPCHECK(hipLaunchCooperativeKernel(
reinterpret_cast<void*>(DefltStrmPT_Test_gws),
dimGrid, dimBlock, params, dimBlock.x * sizeof(int64_t),
DefltStrmPT::Strm));
HIPCHECK(hipLaunchCooperativeKernel(reinterpret_cast<void*>(DefltStrmPT_Test_gws), dimGrid,
dimBlock, params, dimBlock.x * sizeof(int64_t),
DefltStrmPT::Strm));
HIP_CHECK(hipStreamSynchronize(DefltStrmPT::Strm));
}
HIPCHECK(hipMemcpy(init, dC, sizeof(int64_t), hipMemcpyDeviceToHost));
if (*dC != (((int64_t)(BufferSizeInDwords) * (BufferSizeInDwords - 1)) / 2)) {
std::cout << "Data validation failed for grid size = " << dimGrid.x <<
" and block size = " << dimBlock.x << "\n";
std::cout << "Test failed! \n";
IfTestPassed = false;
std::cout << "Data validation failed for grid size = " << dimGrid.x
<< " and block size = " << dimBlock.x << "\n";
std::cout << "Test failed! \n";
IfTestPassed = false;
}
HIPCHECK(hipStreamDestroy(DefltStrmPT::Strm));
HIPCHECK(hipHostFree(dC));
HIPCHECK(hipFree(dB));
HIPCHECK(hipFree(dA));
delete [] init;
delete[] init;
REQUIRE(IfTestPassed);
}
@@ -483,8 +468,7 @@ void DefaultPT2_StrmGetFlag() {
REQUIRE(false);
}
HIP_CHECK(hipStreamDestroy(DefltStrmPT::Strm));
HIP_CHECK(hipStreamCreateWithFlags(&(DefltStrmPT::Strm),
hipStreamNonBlocking));
HIP_CHECK(hipStreamCreateWithFlags(&(DefltStrmPT::Strm), hipStreamNonBlocking));
flag = 9999;
HIP_CHECK(hipStreamGetFlags(DefltStrmPT::Strm, &flag));
if (flag != 1) {
@@ -505,16 +489,14 @@ void DefaultPT2_StrmGetPriority() {
for (int hipStrmFlg = 0; hipStrmFlg < 2; ++hipStrmFlg) {
for (int Priority = low; Priority <= high; ++Priority) {
if (hipStrmFlg == 0) {
HIP_CHECK(hipStreamCreateWithPriority(&(DefltStrmPT::Strm),
hipStreamDefault, Priority));
HIP_CHECK(hipStreamCreateWithPriority(&(DefltStrmPT::Strm), hipStreamDefault, Priority));
} else {
HIP_CHECK(hipStreamCreateWithPriority(&(DefltStrmPT::Strm),
hipStreamNonBlocking, Priority));
HIP_CHECK(
hipStreamCreateWithPriority(&(DefltStrmPT::Strm), hipStreamNonBlocking, Priority));
}
HIP_CHECK(hipStreamGetPriority(DefltStrmPT::Strm, &ObsrvdPriority));
if (ObsrvdPriority != Priority) {
INFO("Expected priority: %d" << Priority << " Observed Priority: %d\n"
<< ObsrvdPriority);
INFO("Expected priority: %d" << Priority << " Observed Priority: %d\n" << ObsrvdPriority);
INFO("Test Failed!\n\n");
REQUIRE(false);
}
@@ -524,28 +506,27 @@ void DefaultPT2_StrmGetPriority() {
INFO("Checking priority on null stream!!\n");
HIP_CHECK(hipStreamGetPriority(0, &ObsrvdPriority));
if (ObsrvdPriority != 0) {
INFO("Expected priority: 0, Observed Priority: %d\n"
<< ObsrvdPriority);
INFO("Test Failed!\n\n");
REQUIRE(false);
INFO("Expected priority: 0, Observed Priority: %d\n" << ObsrvdPriority);
INFO("Test Failed!\n\n");
REQUIRE(false);
}
}
void DefaultPT2_hipMemcpyFromSymbol() {
int64_t *Hst = nullptr;
int64_t* Hst = nullptr;
HIP_CHECK(hipHostMalloc(&(Hst), DefltStrmPT::OneMBSz));
HIP_CHECK(hipStreamCreate(&(DefltStrmPT::Strm)));
for (int i = 0; i < DefltStrmPT::OneMB; ++i) {
Hst[i] = DefltStrmPT::CONST;
}
HIP_CHECK(hipMemcpyToSymbol(HIP_SYMBOL(globalInDStrmPT), Hst,
DefltStrmPT::OneMBSz, 0, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpyToSymbol(HIP_SYMBOL(globalInDStrmPT), Hst, DefltStrmPT::OneMBSz, 0,
hipMemcpyHostToDevice));
for (int i = 0; i < DefltStrmPT::OneMB; ++i) {
Hst[i] = 0;
}
HIP_CHECK(hipMemcpyFromSymbol(Hst, HIP_SYMBOL(globalInDStrmPT),
DefltStrmPT::OneMBSz, 0, hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpyFromSymbol(Hst, HIP_SYMBOL(globalInDStrmPT), DefltStrmPT::OneMBSz, 0,
hipMemcpyDeviceToHost));
for (int i = 0; i < DefltStrmPT::OneMB; ++i) {
if (Hst[i] != DefltStrmPT::CONST) {
REQUIRE(false);
@@ -560,46 +541,42 @@ void DefaultPT2_hipMemcpy2D(int Async) {
DefltStrmPT::numW = 1024;
DefltStrmPT::width = DefltStrmPT::numW * sizeof(int64_t);
HIP_CHECK(hipHostMalloc(&(DefltStrmPT::HstA),
(DefltStrmPT::numH * DefltStrmPT::numW * sizeof(int64_t))));
(DefltStrmPT::numH * DefltStrmPT::numW * sizeof(int64_t))));
HIP_CHECK(hipHostMalloc(&(DefltStrmPT::HstRes),
(DefltStrmPT::numH * DefltStrmPT::numW * sizeof(int64_t))));
(DefltStrmPT::numH * DefltStrmPT::numW * sizeof(int64_t))));
DefltStrmPT::width = DefltStrmPT::numW * sizeof(int64_t);
for (size_t row = 0; row < DefltStrmPT::numH; ++row) {
for (size_t column = 0; column < DefltStrmPT::numW; ++column) {
DefltStrmPT::HstA[(row * DefltStrmPT::numW) + column] =
DefltStrmPT::CONST;
DefltStrmPT::HstA[(row * DefltStrmPT::numW) + column] = DefltStrmPT::CONST;
DefltStrmPT::HstRes[(row * DefltStrmPT::numW) + column] = 0;
}
}
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&(DefltStrmPT::DevA)),
&(DefltStrmPT::pitch_A), DefltStrmPT::width, DefltStrmPT::numH));
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&(DefltStrmPT::DevA)), &(DefltStrmPT::pitch_A),
DefltStrmPT::width, DefltStrmPT::numH));
if (Async) {
HIP_CHECK(hipStreamCreate(&(DefltStrmPT::Strm)));
HIP_CHECK(hipMemcpy2DAsync(DefltStrmPT::DevA, DefltStrmPT::pitch_A,
DefltStrmPT::HstA, DefltStrmPT::numW*sizeof(int64_t),
DefltStrmPT::numW*sizeof(int64_t), DefltStrmPT::numH,
hipMemcpyHostToDevice, DefltStrmPT::Strm));
HIP_CHECK(hipMemcpy2DAsync(DefltStrmPT::HstRes,
DefltStrmPT::numW*sizeof(int64_t),
DefltStrmPT::DevA, DefltStrmPT::pitch_A,
DefltStrmPT::numW*sizeof(int64_t), DefltStrmPT::numH,
hipMemcpyDeviceToHost, DefltStrmPT::Strm));
HIP_CHECK(hipMemcpy2DAsync(DefltStrmPT::DevA, DefltStrmPT::pitch_A, DefltStrmPT::HstA,
DefltStrmPT::numW * sizeof(int64_t),
DefltStrmPT::numW * sizeof(int64_t), DefltStrmPT::numH,
hipMemcpyHostToDevice, DefltStrmPT::Strm));
HIP_CHECK(hipMemcpy2DAsync(DefltStrmPT::HstRes, DefltStrmPT::numW * sizeof(int64_t),
DefltStrmPT::DevA, DefltStrmPT::pitch_A,
DefltStrmPT::numW * sizeof(int64_t), DefltStrmPT::numH,
hipMemcpyDeviceToHost, DefltStrmPT::Strm));
HIP_CHECK(hipStreamSynchronize(DefltStrmPT::Strm));
HIP_CHECK(hipStreamDestroy(DefltStrmPT::Strm));
} else {
HIP_CHECK(hipMemcpy2D(DefltStrmPT::DevA, DefltStrmPT::pitch_A,
DefltStrmPT::HstA, DefltStrmPT::numW*sizeof(int64_t),
DefltStrmPT::numW*sizeof(int64_t), DefltStrmPT::numH,
hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy2D(DefltStrmPT::HstRes,
DefltStrmPT::numW*sizeof(int64_t), DefltStrmPT::DevA,
DefltStrmPT::pitch_A, DefltStrmPT::numW*sizeof(int64_t),
DefltStrmPT::numH, hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy2D(DefltStrmPT::DevA, DefltStrmPT::pitch_A, DefltStrmPT::HstA,
DefltStrmPT::numW * sizeof(int64_t), DefltStrmPT::numW * sizeof(int64_t),
DefltStrmPT::numH, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy2D(DefltStrmPT::HstRes, DefltStrmPT::numW * sizeof(int64_t),
DefltStrmPT::DevA, DefltStrmPT::pitch_A,
DefltStrmPT::numW * sizeof(int64_t), DefltStrmPT::numH,
hipMemcpyDeviceToHost));
}
for (size_t row = 0; row < DefltStrmPT::numH; ++row) {
for (size_t column = 0; column < DefltStrmPT::numW; ++column) {
if (DefltStrmPT::HstRes[(row * DefltStrmPT::numW) + column]
!= DefltStrmPT::CONST) {
if (DefltStrmPT::HstRes[(row * DefltStrmPT::numW) + column] != DefltStrmPT::CONST) {
REQUIRE(false);
}
}
@@ -621,13 +598,11 @@ void DefaultPT2_hipMemcpy2DToArray() {
Hptr[i] = DefltStrmPT::CONST;
}
hipChannelFormatDesc desc = hipCreateChannelDesc<float>();
HIP_CHECK(hipMallocArray(&(Dptr), &desc, DefltStrmPT::numW,
DefltStrmPT::numH, hipArrayDefault));
HIP_CHECK(hipMemcpy2DToArray(Dptr, 0, 0, Hptr, DefltStrmPT::width,
DefltStrmPT::width, DefltStrmPT::numH,
hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy2DFromArray(HRes, DefltStrmPT::width, Dptr, 0, 0,
DefltStrmPT::width, DefltStrmPT::numH, hipMemcpyDeviceToHost));
HIP_CHECK(hipMallocArray(&(Dptr), &desc, DefltStrmPT::numW, DefltStrmPT::numH, hipArrayDefault));
HIP_CHECK(hipMemcpy2DToArray(Dptr, 0, 0, Hptr, DefltStrmPT::width, DefltStrmPT::width,
DefltStrmPT::numH, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy2DFromArray(HRes, DefltStrmPT::width, Dptr, 0, 0, DefltStrmPT::width,
DefltStrmPT::numH, hipMemcpyDeviceToHost));
// verifying the result
for (size_t i = 0; i < DefltStrmPT::numW * DefltStrmPT::numH; ++i) {
if (HRes[i] != DefltStrmPT::CONST) {
@@ -646,26 +621,20 @@ float DefaultPT2_hipMemcpy2DFromArray() {
DefltStrmPT::numH = 1024;
DefltStrmPT::numW = 1024;
DefltStrmPT::width = DefltStrmPT::numW * sizeof(float);
HIP_CHECK(hipDeviceGetAttribute(&(DefltStrmPT::clockrate),
hipDeviceAttributeMemoryClockRate, 0));
HIP_CHECK(hipHostMalloc(&(Hptr_A),
(DefltStrmPT::width * DefltStrmPT::numH * sizeof(float))));
HIP_CHECK(hipHostMalloc(&(Hptr_B),
(DefltStrmPT::width * DefltStrmPT::numH * sizeof(float))));
HIP_CHECK(hipDeviceGetAttribute(&(DefltStrmPT::clockrate), hipDeviceAttributeMemoryClockRate, 0));
HIP_CHECK(hipHostMalloc(&(Hptr_A), (DefltStrmPT::width * DefltStrmPT::numH * sizeof(float))));
HIP_CHECK(hipHostMalloc(&(Hptr_B), (DefltStrmPT::width * DefltStrmPT::numH * sizeof(float))));
for (size_t i = 0; i < (DefltStrmPT::width * DefltStrmPT::numH); ++i) {
Hptr_A[i] = DefltStrmPT::CONST;
}
hipChannelFormatDesc desc = hipCreateChannelDesc<float>();
HIP_CHECK(hipMallocArray(&(Dptr), &desc, DefltStrmPT::numW,
DefltStrmPT::numH, hipArrayDefault));
HIP_CHECK(hipMallocArray(&(Dptr), &desc, DefltStrmPT::numW, DefltStrmPT::numH, hipArrayDefault));
HIP_CHECK(hipStreamCreate(&(DefltStrmPT::Strm)));
HIP_CHECK(hipMemcpy2DToArray(Dptr, 0, 0, Hptr_A, DefltStrmPT::width,
DefltStrmPT::width, DefltStrmPT::numH,
hipMemcpyHostToDevice));
Wait_Kernel3 <<< 1, 1, 0, DefltStrmPT::Strm >>> (DefltStrmPT::clockrate,
1);
HIP_CHECK(hipMemcpy2DFromArray(Hptr_B, DefltStrmPT::width, Dptr, 0, 0,
DefltStrmPT::width, DefltStrmPT::numH, hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy2DToArray(Dptr, 0, 0, Hptr_A, DefltStrmPT::width, DefltStrmPT::width,
DefltStrmPT::numH, hipMemcpyHostToDevice));
Wait_Kernel3<<<1, 1, 0, DefltStrmPT::Strm>>>(DefltStrmPT::clockrate, 1);
HIP_CHECK(hipMemcpy2DFromArray(Hptr_B, DefltStrmPT::width, Dptr, 0, 0, DefltStrmPT::width,
DefltStrmPT::numH, hipMemcpyDeviceToHost));
HIP_CHECK(hipStreamDestroy(DefltStrmPT::Strm));
HIP_CHECK(hipFreeArray(Dptr));
HIP_CHECK(hipHostFree(Hptr_A));
@@ -685,22 +654,21 @@ void DefaultPT2_hipMemcpy3D() {
for (int i = 0; i < depth; i++) {
for (int j = 0; j < height; j++) {
for (int k = 0; k < width; k++) {
Hptr[i*width*height + j*width +k] = i*width*height + j*width + k;
Hptr[i * width * height + j * width + k] = i * width * height + j * width + k;
}
}
}
hipChannelFormatDesc channelDesc = hipCreateChannelDesc(sizeof(float)*8, 0,
0, 0, hipChannelFormatKindFloat);
hipChannelFormatDesc channelDesc =
hipCreateChannelDesc(sizeof(float) * 8, 0, 0, 0, hipChannelFormatKindFloat);
hipArray_t arr;
HIP_CHECK(hipMalloc3DArray(&arr, &channelDesc,
make_hipExtent(width, height, depth), hipArrayDefault));
hipMemcpy3DParms myparms{0, {0, 0, 0}, {0, 0, 0, 0}, 0, {0, 0, 0},
{0, 0, 0, 0}, {0, 0, 0}, hipMemcpyDefault};
HIP_CHECK(
hipMalloc3DArray(&arr, &channelDesc, make_hipExtent(width, height, depth), hipArrayDefault));
hipMemcpy3DParms myparms{0, {0, 0, 0}, {0, 0, 0, 0}, 0,
{0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0}, hipMemcpyDefault};
myparms.srcPos = make_hipPos(0, 0, 0);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.srcPtr = make_hipPitchedPtr(Hptr, width * sizeof(float), width,
height);
myparms.srcPtr = make_hipPitchedPtr(Hptr, width * sizeof(float), width, height);
myparms.dstArray = arr;
myparms.extent = extent;
@@ -716,8 +684,7 @@ void DefaultPT2_hipMemcpy3D() {
memset(&myparms, 0x0, sizeof(hipMemcpy3DParms));
myparms.srcPos = make_hipPos(0, 0, 0);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.dstPtr = make_hipPitchedPtr(HRes, width * sizeof(float), width,
height);
myparms.dstPtr = make_hipPitchedPtr(HRes, width * sizeof(float), width, height);
myparms.srcArray = arr;
myparms.extent = extent;
#ifdef __HIP_PLATFORM_NVIDIA__
@@ -730,7 +697,7 @@ void DefaultPT2_hipMemcpy3D() {
for (int i = 0; i < depth; i++) {
for (int j = 0; j < height; j++) {
for (int k = 0; k < width; k++) {
if (HRes[i*width*height + j*width +k] != i*width*height + j*width + k) {
if (HRes[i * width * height + j * width + k] != i * width * height + j * width + k) {
REQUIRE(false);
}
}
@@ -761,13 +728,9 @@ TEST_CASE("Unit_hipStrmPerThrdDefault") {
PerThrdDefltStrm_Memset3D(1);
}
SECTION("Testing_hipStreamQuery()") {
DefaultPT2_StrmQuery();
}
SECTION("Testing_hipStreamQuery()") { DefaultPT2_StrmQuery(); }
SECTION("Testing_hipStreamSynchronize()") {
DefaultPT2_StreamSync();
}
SECTION("Testing_hipStreamSynchronize()") { DefaultPT2_StreamSync(); }
SECTION("Testing_hipLaunchKernel()") {
// launch with null stream
@@ -790,36 +753,22 @@ TEST_CASE("Unit_hipStrmPerThrdDefault") {
INFO(" the test Testing_hipLaunchCooperativeKernel()");
}
SECTION("Testing_StrmWaitEvent()") {
DefaultPT2_StrmWaitEvent();
}
SECTION("Testing_StrmWaitEvent()") { DefaultPT2_StrmWaitEvent(); }
SECTION("Testing_hipStreamGetFlag()") {
DefaultPT2_StrmGetFlag();
}
SECTION("Testing_hipStreamGetFlag()") { DefaultPT2_StrmGetFlag(); }
SECTION("Testing_hipStreamGetPriority()") {
DefaultPT2_StrmGetPriority();
}
SECTION("Testing_hipStreamGetPriority()") { DefaultPT2_StrmGetPriority(); }
SECTION("Testing_hipMemcpyFrom/To/Symbol()") {
DefaultPT2_hipMemcpyFromSymbol();
}
SECTION("Testing_hipMemcpyFrom/To/Symbol()") { DefaultPT2_hipMemcpyFromSymbol(); }
SECTION("Testing_hipMemcpy2D() & its Async version") {
DefaultPT2_hipMemcpy2D(0);
DefaultPT2_hipMemcpy2D(1);
}
SECTION("Testing_hipMemcpy2DToArray()") {
DefaultPT2_hipMemcpy2DToArray();
}
SECTION("Testing_hipMemcpy2DToArray()") { DefaultPT2_hipMemcpy2DToArray(); }
SECTION("Testing_hipMemcpy3D()") {
DefaultPT2_hipMemcpy3D();
}
SECTION("Testing_hipMemcpy3D()") { DefaultPT2_hipMemcpy3D(); }
SECTION("Testing_hipEventQuery()") {
DefaultPT2_EvtQuery();
}
SECTION("Testing_hipEventQuery()") { DefaultPT2_EvtQuery(); }
}
+91 -102
查看文件
@@ -37,13 +37,13 @@ THE SOFTWARE.
#include <thread>
#include <chrono>
#ifdef _WIN32
#include <Windows.h>
#define sleep(x) _sleep(x)
#include <Windows.h>
#define sleep(x) _sleep(x)
#endif
#ifdef __linux__
#include <unistd.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/wait.h>
#endif
#include <hip_test_common.hh>
@@ -57,8 +57,7 @@ using namespace cooperative_groups;
static bool IfTestPassed = false;
// kernel
__global__ void StreamPerThrd(int *Ad, int *Ad1, size_t n, int Pk_Clk,
int Wait, int WaitEvnt = 0) {
__global__ void StreamPerThrd(int* Ad, int* Ad1, size_t n, int Pk_Clk, int Wait, int WaitEvnt = 0) {
size_t index = blockIdx.x * blockDim.x + threadIdx.x;
if (index < n) {
Ad[index] = Ad[index] + 10;
@@ -70,9 +69,9 @@ __global__ void StreamPerThrd(int *Ad, int *Ad1, size_t n, int Pk_Clk,
// The following while loop holds the execution for ~2 seconds.
// Busy sleep on nvidia
while ((clock64() - StrtTck) <= (2 * GpuFrq)) {
#if HT_AMD
__builtin_amdgcn_s_sleep(10);
#endif
#if HT_AMD
__builtin_amdgcn_s_sleep(10);
#endif
}
if (WaitEvnt == 1) {
*Ad1 = 1;
@@ -82,21 +81,21 @@ __global__ void StreamPerThrd(int *Ad, int *Ad1, size_t n, int Pk_Clk,
}
__global__ void StreamPerThrd1(int *A, int Pk_Clk) {
__global__ void StreamPerThrd1(int* A, int Pk_Clk) {
int64_t GpuFrq = (Pk_Clk * 1000);
int64_t StrtTck = clock64();
// The following while loop holds the execution for ~1 second
// Busy sleep on nvidia
while ((clock64() - StrtTck) <= (GpuFrq)) {
#if HT_AMD
__builtin_amdgcn_s_sleep(10);
#endif
#if HT_AMD
__builtin_amdgcn_s_sleep(10);
#endif
}
*A = 1;
}
__global__ void StreamPerThrd_gfx11(int *Ad, int *Ad1, size_t n, int Pk_Clk,
int Wait, int WaitEvnt = 0) {
__global__ void StreamPerThrd_gfx11(int* Ad, int* Ad1, size_t n, int Pk_Clk, int Wait,
int WaitEvnt = 0) {
#if HT_AMD
size_t index = blockIdx.x * blockDim.x + threadIdx.x;
if (index < n) {
@@ -117,7 +116,7 @@ __global__ void StreamPerThrd_gfx11(int *Ad, int *Ad1, size_t n, int Pk_Clk,
#endif
}
__global__ void StreamPerThrd1_gfx11(int *A, int Pk_Clk) {
__global__ void StreamPerThrd1_gfx11(int* A, int Pk_Clk) {
#if HT_AMD
int64_t GpuFrq = (Pk_Clk * 1000);
int64_t StrtTck = clock_function();
@@ -128,17 +127,17 @@ __global__ void StreamPerThrd1_gfx11(int *A, int Pk_Clk) {
#endif
}
__global__ void MiniKernel(int *A) {
__global__ void MiniKernel(int* A) {
if (*A == 0) {
*A = 2; // Fail condition
} else if (*A == 1) {
*A = 3; // Pass condition
} else {
*A = 4; // Garbage value found in A
*A = 4; // Garbage value found in A
}
}
__global__ void StreamPerThrdCoopKrnl(int *Ad, int *n) {
__global__ void StreamPerThrdCoopKrnl(int* Ad, int* n) {
int NumElms = (*n);
int index = blockIdx.x * blockDim.x + threadIdx.x;
if (index < NumElms) {
@@ -147,57 +146,54 @@ __global__ void StreamPerThrdCoopKrnl(int *Ad, int *n) {
}
#if HT_AMD
__global__ void test_gwsPerThrd(uint* buf, uint bufSize, int64_t* tmpBuf,
int64_t* result) {
extern __shared__ int64_t tmp[];
uint groups = gridDim.x;
uint group_id = blockIdx.x;
uint local_id = threadIdx.x;
uint chunk = gridDim.x * blockDim.x;
__global__ void test_gwsPerThrd(uint* buf, uint bufSize, int64_t* tmpBuf, int64_t* result) {
extern __shared__ int64_t tmp[];
uint groups = gridDim.x;
uint group_id = blockIdx.x;
uint local_id = threadIdx.x;
uint chunk = gridDim.x * blockDim.x;
uint i = group_id * blockDim.x + local_id;
int64_t sum = 0;
while (i < bufSize) {
sum += buf[i];
i += chunk;
}
tmp[local_id] = sum;
__syncthreads();
i = 0;
if (local_id == 0) {
sum = 0;
while (i < blockDim.x) {
sum += tmp[i];
i++;
}
tmpBuf[group_id] = sum;
uint i = group_id * blockDim.x + local_id;
int64_t sum = 0;
while (i < bufSize) {
sum += buf[i];
i += chunk;
}
tmp[local_id] = sum;
__syncthreads();
i = 0;
if (local_id == 0) {
sum = 0;
while (i < blockDim.x) {
sum += tmp[i];
i++;
}
tmpBuf[group_id] = sum;
}
// wait
cooperative_groups::this_grid().sync();
// wait
cooperative_groups::this_grid().sync();
if (((blockIdx.x * blockDim.x) + threadIdx.x) == 0) {
for (uint i = 1; i < groups; ++i) {
sum += tmpBuf[i];
}
// *result = sum;
result[1 + cooperative_groups::this_multi_grid().grid_rank()] = sum;
if (((blockIdx.x * blockDim.x) + threadIdx.x) == 0) {
for (uint i = 1; i < groups; ++i) {
sum += tmpBuf[i];
}
cooperative_groups::this_multi_grid().sync();
if (cooperative_groups::this_multi_grid().grid_rank() == 0) {
sum = 0;
for (uint i = 1; i <= cooperative_groups::this_multi_grid().num_grids();
++i) {
sum += result[i];
}
*result = sum;
// *result = sum;
result[1 + cooperative_groups::this_multi_grid().grid_rank()] = sum;
}
cooperative_groups::this_multi_grid().sync();
if (cooperative_groups::this_multi_grid().grid_rank() == 0) {
sum = 0;
for (uint i = 1; i <= cooperative_groups::this_multi_grid().num_grids(); ++i) {
sum += result[i];
}
*result = sum;
}
}
#endif
// callback function
static void HIPRT_CB CallBackFunctn(hipStream_t strm, hipError_t err,
void *ChkVal) {
static void HIPRT_CB CallBackFunctn(hipStream_t strm, hipError_t err, void* ChkVal) {
// The following HIPASSERT() is just to satisfy catch2 framework.
// As it ensures the use of all the variables.
HIPASSERT(strm);
@@ -223,16 +219,15 @@ static void EventSync() {
HIP_CHECK(hipEventCreate(&end));
HIP_CHECK(hipMemcpy(Ad, Ah, NumElms * sizeof(int), hipMemcpyHostToDevice));
dim3 dimBlock(blockSize, 1, 1);
dim3 dimGrid((NumElms + blockSize -1)/blockSize, 1, 1);
dim3 dimGrid((NumElms + blockSize - 1) / blockSize, 1, 1);
HIP_CHECK(hipEventRecord(start, hipStreamPerThread));
if (IsGfx11()) {
HIP_CHECK(hipDeviceGetAttribute(&peak_clk, hipDeviceAttributeWallClockRate, 0));
StreamPerThrd_gfx11<<<dimGrid, dimBlock, 0, hipStreamPerThread>>>(Ad, NULL, NumElms,
peak_clk, 0);
StreamPerThrd_gfx11<<<dimGrid, dimBlock, 0, hipStreamPerThread>>>(Ad, NULL, NumElms, peak_clk,
0);
} else {
HIP_CHECK(hipDeviceGetAttribute(&peak_clk, hipDeviceAttributeClockRate, 0));
StreamPerThrd<<<dimGrid, dimBlock, 0, hipStreamPerThread>>>(Ad, NULL, NumElms,
peak_clk, 0);
StreamPerThrd<<<dimGrid, dimBlock, 0, hipStreamPerThread>>>(Ad, NULL, NumElms, peak_clk, 0);
}
HIP_CHECK(hipEventRecord(end, hipStreamPerThread));
HIP_CHECK(hipEventSynchronize(end));
@@ -269,16 +264,15 @@ TEST_CASE("Unit_hipStreamPerThreadTst_StrmQuery") {
}
HIP_CHECK(hipMemcpy(Ad, Ah, NumElms * sizeof(int), hipMemcpyHostToDevice));
dim3 dimBlock(blockSize, 1, 1);
dim3 dimGrid((NumElms + blockSize -1)/blockSize, 1, 1);
dim3 dimGrid((NumElms + blockSize - 1) / blockSize, 1, 1);
SECTION("Test working of hipStreamQuery") {
if (IsGfx11()) {
HIP_CHECK(hipDeviceGetAttribute(&peak_clk, hipDeviceAttributeWallClockRate, 0));
StreamPerThrd_gfx11<<<dimGrid, dimBlock, 0, hipStreamPerThread>>>(Ad, NULL,
NumElms, peak_clk, 1);
StreamPerThrd_gfx11<<<dimGrid, dimBlock, 0, hipStreamPerThread>>>(Ad, NULL, NumElms, peak_clk,
1);
} else {
HIP_CHECK(hipDeviceGetAttribute(&peak_clk, hipDeviceAttributeClockRate, 0));
StreamPerThrd<<<dimGrid, dimBlock, 0, hipStreamPerThread>>>(Ad, NULL,
NumElms, peak_clk, 1);
StreamPerThrd<<<dimGrid, dimBlock, 0, hipStreamPerThread>>>(Ad, NULL, NumElms, peak_clk, 1);
}
err = hipStreamQuery(hipStreamPerThread);
if (err != hipErrorNotReady) {
@@ -310,8 +304,7 @@ TEST_CASE("Unit_hipStreamPerThreadTst_StrmQuery") {
/* Testing hipStreamPerThread stream object with hipMallocManaged() memory*/
TEST_CASE("Unit_hipStreamPerThread_MangdMem") {
int managed = 0;
HIP_CHECK(hipDeviceGetAttribute(&managed, hipDeviceAttributeManagedMemory,
0));
HIP_CHECK(hipDeviceGetAttribute(&managed, hipDeviceAttributeManagedMemory, 0));
if (managed == 1) {
int *Hmm = nullptr, NumElms = 4096, CONST_NUM = 123, blockSize = 32;
SECTION("Using Managed memory") {
@@ -325,20 +318,18 @@ TEST_CASE("Unit_hipStreamPerThread_MangdMem") {
for (int i = 0; i < NumElms; ++i) {
Hmm[i] = CONST_NUM;
}
HIP_CHECK(hipMemPrefetchAsync(Hmm, NumElms * sizeof(int), 0,
hipStreamPerThread));
HIP_CHECK(hipMemPrefetchAsync(Hmm, NumElms * sizeof(int), 0, hipStreamPerThread));
}
int peak_clk;
dim3 dimBlock(blockSize, 1, 1);
dim3 dimGrid((NumElms + blockSize -1)/blockSize, 1, 1);
dim3 dimGrid((NumElms + blockSize - 1) / blockSize, 1, 1);
if (IsGfx11()) {
HIP_CHECK(hipDeviceGetAttribute(&peak_clk, hipDeviceAttributeWallClockRate, 0));
StreamPerThrd_gfx11<<<dimGrid, dimBlock, 0, hipStreamPerThread>>>(Hmm, NULL,
NumElms, peak_clk, 0);
StreamPerThrd_gfx11<<<dimGrid, dimBlock, 0, hipStreamPerThread>>>(Hmm, NULL, NumElms,
peak_clk, 0);
} else {
HIP_CHECK(hipDeviceGetAttribute(&peak_clk, hipDeviceAttributeClockRate, 0));
StreamPerThrd<<<dimGrid, dimBlock, 0, hipStreamPerThread>>>(Hmm, NULL,
NumElms, peak_clk, 0);
StreamPerThrd<<<dimGrid, dimBlock, 0, hipStreamPerThread>>>(Hmm, NULL, NumElms, peak_clk, 0);
}
HIP_CHECK(hipStreamSynchronize(hipStreamPerThread));
// Validating the result
@@ -354,8 +345,9 @@ TEST_CASE("Unit_hipStreamPerThread_MangdMem") {
REQUIRE(false);
}
} else {
SUCCEED("GPU 0 doesn't support hipDeviceAttributeManagedMemory "
"attribute. Hence skipping the testing with Pass result.\n");
SUCCEED(
"GPU 0 doesn't support hipDeviceAttributeManagedMemory "
"attribute. Hence skipping the testing with Pass result.\n");
}
}
@@ -372,15 +364,14 @@ TEST_CASE("Unit_hipStreamPerThread_ChildProc") {
}
HIP_CHECK(hipMemcpy(Ad, Ah, NumElms * sizeof(int), hipMemcpyHostToDevice));
dim3 dimBlock(blockSize, 1, 1);
dim3 dimGrid((NumElms + blockSize -1)/blockSize, 1, 1);
dim3 dimGrid((NumElms + blockSize - 1) / blockSize, 1, 1);
if (IsGfx11()) {
HIP_CHECK(hipDeviceGetAttribute(&peak_clk, hipDeviceAttributeWallClockRate, 0));
StreamPerThrd_gfx11<<<dimGrid, dimBlock, 0, hipStreamPerThread>>>(Ad, NULL,
NumElms, peak_clk, 0);
} else{
StreamPerThrd_gfx11<<<dimGrid, dimBlock, 0, hipStreamPerThread>>>(Ad, NULL, NumElms, peak_clk,
0);
} else {
HIP_CHECK(hipDeviceGetAttribute(&peak_clk, hipDeviceAttributeClockRate, 0));
StreamPerThrd<<<dimGrid, dimBlock, 0, hipStreamPerThread>>>(Ad, NULL,
NumElms, peak_clk, 0);
StreamPerThrd<<<dimGrid, dimBlock, 0, hipStreamPerThread>>>(Ad, NULL, NumElms, peak_clk, 0);
}
HIP_CHECK(hipStreamSynchronize(hipStreamPerThread));
HIP_CHECK(hipMemcpy(Ah, Ad, NumElms * sizeof(int), hipMemcpyDeviceToHost));
@@ -415,7 +406,7 @@ TEST_CASE("Unit_hipStreamPerThread_EvtRcrdMThrd") {
IfTestPassed = true;
int MAX_THREAD_CNT = 20;
std::vector<std::thread> threads(MAX_THREAD_CNT);
for (auto &th : threads) {
for (auto& th : threads) {
th = std::thread(EventSync);
}
for (auto& th : threads) {
@@ -445,7 +436,7 @@ TEST_CASE("Unit_hipStreamPerThread_StrmWaitEvt") {
HIP_CHECK(hipMemset(Ad1, 0, sizeof(int)));
int peak_clk;
dim3 dimBlock(blockSize, 1, 1);
dim3 dimGrid((NumElms + blockSize -1)/blockSize, 1, 1);
dim3 dimGrid((NumElms + blockSize - 1) / blockSize, 1, 1);
hipEvent_t e1;
HIPCHECK(hipEventCreate(&e1));
if (IsGfx11()) {
@@ -460,7 +451,7 @@ TEST_CASE("Unit_hipStreamPerThread_StrmWaitEvt") {
MiniKernel<<<1, 1, 0, hipStreamPerThread>>>(Ad1);
sleep(1);
HIP_CHECK(hipMemcpy(Ah1, Ad1, sizeof(int), hipMemcpyDeviceToHost));
if (*Ah1 != 3) {
if (*Ah1 != 3) {
IfTestPassed = false;
if (*Ah1 == 2) {
WARN("hipStreamPerThread didn't honour hipStreamWaitEvent()");
@@ -504,8 +495,7 @@ TEST_CASE("Unit_hipStreamPerThread_CoopLaunch") {
// long long totalTicks = device_properties.clockRate ;
int max_blocks_per_sm = 0;
// Calculate the device occupancy to know how many blocks can be run.
HIPCHECK(hipOccupancyMaxActiveBlocksPerMultiprocessor(&max_blocks_per_sm,
StreamPerThrdCoopKrnl,
HIPCHECK(hipOccupancyMaxActiveBlocksPerMultiprocessor(&max_blocks_per_sm, StreamPerThrdCoopKrnl,
warp_size, 0));
int max_active_blocks = max_blocks_per_sm * num_sms;
int *Ad = nullptr, *Ah = nullptr, *DNumElms = nullptr, NumElms = 4096;
@@ -517,19 +507,18 @@ TEST_CASE("Unit_hipStreamPerThread_CoopLaunch") {
}
HIP_CHECK(hipMalloc(&Ad, sizeof(int) * NumElms));
HIP_CHECK(hipMalloc(&DNumElms, sizeof(int)));
HIP_CHECK(hipMemcpyAsync(Ad, Ah, sizeof(int) * NumElms,
hipMemcpyHostToDevice, hipStreamPerThread));
HIP_CHECK(hipMemcpyAsync(DNumElms, &NumElms, sizeof(int),
hipMemcpyHostToDevice, hipStreamPerThread));
HIP_CHECK(
hipMemcpyAsync(Ad, Ah, sizeof(int) * NumElms, hipMemcpyHostToDevice, hipStreamPerThread));
HIP_CHECK(
hipMemcpyAsync(DNumElms, &NumElms, sizeof(int), hipMemcpyHostToDevice, hipStreamPerThread));
HIP_CHECK(hipStreamSynchronize(hipStreamPerThread));
void *coop_params[2];
void* coop_params[2];
coop_params[0] = reinterpret_cast<void*>(&Ad);
coop_params[1] = reinterpret_cast<void*>(&DNumElms);
HIP_CHECK(hipLaunchCooperativeKernel(
reinterpret_cast<void*>(StreamPerThrdCoopKrnl),
max_active_blocks, warp_size,
coop_params, 0, hipStreamPerThread));
HIP_CHECK(hipLaunchCooperativeKernel(reinterpret_cast<void*>(StreamPerThrdCoopKrnl),
max_active_blocks, warp_size, coop_params, 0,
hipStreamPerThread));
HIP_CHECK(hipMemcpy(Ah, Ad, sizeof(int) * NumElms, hipMemcpyDeviceToHost));
// Verifying the result
int DataMismatch = 0;
+11 -12
查看文件
@@ -19,14 +19,14 @@ THE SOFTWARE.
#include <hip_test_common.hh>
#define MEM_SIZE (1024*1024*32)
#define MEM_SIZE (1024 * 1024 * 32)
#define SEED 5
constexpr unsigned int MAX_THREAD_CNT = 10;
__global__ void copy_kernl(int* devPtr) {
for (int i = 0; i < MEM_SIZE; ++i) {
devPtr[i] = (i+1) + SEED;
devPtr[i] = (i + 1) + SEED;
}
}
@@ -46,8 +46,8 @@ TEST_CASE("Unit_hipStreamPerThread_Basic") {
/*
hipStreamPerThread is an implicit stream which works independent of null stream.
Null stream synchronize will account hipStreamPerThread into account.
test scenario: Launch kernel + Async mem copy on hipStreamPerThread and call synchronize on null stream.
Result : Null stream synchronize should sync hipStreamPerThread as well
test scenario: Launch kernel + Async mem copy on hipStreamPerThread and call synchronize on null
stream. Result : Null stream synchronize should sync hipStreamPerThread as well
*/
copy_kernl<<<1, 1, 0, hipStreamPerThread>>>(devMem);
@@ -56,21 +56,20 @@ TEST_CASE("Unit_hipStreamPerThread_Basic") {
HIP_CHECK(hipStreamSynchronize(0));
// validate result
for (int i = MEM_SIZE-1; i >= 0; --i) {
CHECK(hostMem[i] == (i+1+SEED));
for (int i = MEM_SIZE - 1; i >= 0; --i) {
CHECK(hostMem[i] == (i + 1 + SEED));
}
// Clean-up
HIP_CHECK(hipHostFree(hostMem));
HIP_CHECK(hipFree(devMem));
}
TEST_CASE("Unit_hipStreamPerThread_StreamQuery") {
std::vector<std::thread> threads(MAX_THREAD_CNT);
for (auto &th : threads) {
th = std::thread([](){HIP_CHECK(hipStreamQuery(hipStreamPerThread));});
for (auto& th : threads) {
th = std::thread([]() { HIP_CHECK(hipStreamQuery(hipStreamPerThread)); });
}
for (auto& th : threads) {
@@ -113,7 +112,7 @@ TEST_CASE("Unit_hipStreamPerThread_MemcpyAsync") {
int* A_h = nullptr;
int* A_d = nullptr;
HIP_CHECK(hipHostMalloc(&A_h, ele_size*sizeof(int)));
HIP_CHECK(hipHostMalloc(&A_h, ele_size * sizeof(int)));
HIP_CHECK(hipMalloc(&A_d, ele_size * sizeof(int)));
for (unsigned int i = 0; i < ele_size; ++i) {
@@ -127,8 +126,8 @@ TEST_CASE("Unit_hipStreamPerThread_MemcpyAsync") {
A_h[i] = 0;
}
HIP_CHECK(hipMemcpyAsync(A_h, A_d, ele_size * sizeof(int), hipMemcpyDeviceToHost,
hipStreamPerThread));
HIP_CHECK(
hipMemcpyAsync(A_h, A_d, ele_size * sizeof(int), hipMemcpyDeviceToHost, hipStreamPerThread));
HIP_CHECK(hipStreamSynchronize(hipStreamPerThread));
// Verify result
+12 -12
查看文件
@@ -32,17 +32,17 @@ static void Copy_to_device() {
int* A_h = nullptr;
int* A_d = nullptr;
hipError_t status = hipHostMalloc(&A_h, ele_size*sizeof(int));
hipError_t status = hipHostMalloc(&A_h, ele_size * sizeof(int));
if (status != hipSuccess) return;
status = hipMalloc(&A_d, ele_size * sizeof(int));
if (status != hipSuccess) return;
for(unsigned int i = 0; i < ele_size; ++i) {
for (unsigned int i = 0; i < ele_size; ++i) {
A_h[i] = 123;
}
HIP_CHECK(hipMemcpyAsync(A_d, A_h, ele_size * sizeof(int), hipMemcpyHostToDevice,
hipStreamPerThread));
HIP_CHECK(
hipMemcpyAsync(A_d, A_h, ele_size * sizeof(int), hipMemcpyHostToDevice, hipStreamPerThread));
// Clean up
HIP_CHECK(hipHostFree(A_h));
HIP_CHECK(hipFree(A_d));
@@ -52,10 +52,10 @@ TEST_CASE("Unit_hipStreamPerThread_DeviceReset_1") {
constexpr unsigned int MAX_THREAD_CNT = 10;
std::vector<std::thread> threads(MAX_THREAD_CNT);
for (auto &th : threads) {
for (auto& th : threads) {
th = std::thread(Copy_to_device);
}
for (auto &th : threads) {
for (auto& th : threads) {
th.join();
}
@@ -75,7 +75,7 @@ TEST_CASE("Unit_hipStreamPerThread_DeviceReset_2") {
int* A_h = nullptr;
int* A_d = nullptr;
hipError_t status = hipHostMalloc(&A_h, ele_size*sizeof(int));
hipError_t status = hipHostMalloc(&A_h, ele_size * sizeof(int));
if (status != hipSuccess) return;
status = hipMalloc(&A_d, ele_size * sizeof(int));
if (status != hipSuccess) return;
@@ -83,8 +83,8 @@ TEST_CASE("Unit_hipStreamPerThread_DeviceReset_2") {
for (unsigned int i = 0; i < ele_size; ++i) {
A_h[i] = 123;
}
status = hipMemcpyAsync(A_d, A_h, ele_size * sizeof(int), hipMemcpyHostToDevice,
hipStreamPerThread);
status =
hipMemcpyAsync(A_d, A_h, ele_size * sizeof(int), hipMemcpyHostToDevice, hipStreamPerThread);
if (status != hipSuccess) return;
HIP_CHECK(hipStreamSynchronize(hipStreamPerThread));
@@ -96,13 +96,13 @@ TEST_CASE("Unit_hipStreamPerThread_DeviceReset_2") {
// After reset all memory objects will be destroyed hence allocating them again
// Intention is to use hipStreamPerThread successfully after reset hence not validating
// values after copy
status = hipHostMalloc(&A_h, ele_size*sizeof(int));
status = hipHostMalloc(&A_h, ele_size * sizeof(int));
if (status != hipSuccess) return;
status = hipMalloc(&A_d, ele_size * sizeof(int));
if (status != hipSuccess) return;
status = hipMemcpyAsync(A_d, A_h, ele_size * sizeof(int), hipMemcpyHostToDevice,
hipStreamPerThread);
status =
hipMemcpyAsync(A_d, A_h, ele_size * sizeof(int), hipMemcpyHostToDevice, hipStreamPerThread);
if (status != hipSuccess) return;
HIP_CHECK(hipStreamSynchronize(hipStreamPerThread));
+5 -5
查看文件
@@ -28,7 +28,7 @@ TEST_CASE("Unit_hipStreamPerThread_EventRecord") {
__global__ void update_even_odd(unsigned int N, int* out) {
for (unsigned int i = 0; i < N; ++i) {
if (i%2 == 0) {
if (i % 2 == 0) {
out[i] = 2;
} else {
out[i] = 3;
@@ -40,7 +40,7 @@ TEST_CASE("Unit_hipStreamPerThread_EventSynchronize") {
int* A_d = nullptr;
unsigned int size = 1000;
HIP_CHECK(hipHostMalloc(&A_h, size*sizeof(int)));
HIP_CHECK(hipHostMalloc(&A_h, size * sizeof(int)));
HIP_CHECK(hipMalloc(&A_d, size * sizeof(int)));
hipEvent_t start, end;
@@ -52,13 +52,13 @@ TEST_CASE("Unit_hipStreamPerThread_EventSynchronize") {
HIP_CHECK(hipEventRecord(end, hipStreamPerThread));
HIP_CHECK(hipEventSynchronize(end));
HIP_CHECK(hipMemcpy(A_h, A_d, size*sizeof(int), hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy(A_h, A_d, size * sizeof(int), hipMemcpyDeviceToHost));
// Verify result
for (unsigned int i = 0; i < size; ++i) {
if (i%2 == 0 && A_h[i] != 2)
if (i % 2 == 0 && A_h[i] != 2)
REQUIRE(false);
else if (i%2 != 0 && A_h[i] != 3) {
else if (i % 2 != 0 && A_h[i] != 3) {
REQUIRE(false);
}
}
+4 -4
查看文件
@@ -26,14 +26,14 @@ static void Copy_to_device() {
int* A_h = nullptr;
int* A_d = nullptr;
HIP_CHECK(hipHostMalloc(&A_h, ele_size*sizeof(int)));
HIP_CHECK(hipHostMalloc(&A_h, ele_size * sizeof(int)));
HIP_CHECK(hipMalloc(&A_d, ele_size * sizeof(int)));
for (unsigned int i = 0; i < ele_size; ++i) {
A_h[i] = 123;
}
HIP_CHECK(hipMemcpyAsync(A_d, A_h, ele_size * sizeof(int), hipMemcpyHostToDevice,
hipStreamPerThread));
HIP_CHECK(
hipMemcpyAsync(A_d, A_h, ele_size * sizeof(int), hipMemcpyHostToDevice, hipStreamPerThread));
// Clean up
HIP_CHECK(hipHostFree(A_h));
HIP_CHECK(hipFree(A_d));
@@ -48,7 +48,7 @@ TEST_CASE("Unit_hipStreamPerThread_MultiThread") {
constexpr unsigned int MAX_THREAD_CNT = 10;
std::vector<std::thread> threads(MAX_THREAD_CNT);
for (auto &th : threads) {
for (auto& th : threads) {
th = std::thread(Copy_to_device);
}