SWDEV-408958 - Use LaunchDelayKernel and modify it to use same kernel based on real time clock for gfx10 and gfx11. (#370)
Change-Id: Iea8a48e8cbfa1745c7d5535dc5820133a4104087
这个提交包含在:
14 个文件已更改
+79
-209
没有与搜索条件相匹配的文件
@@ -25,6 +25,7 @@ multiple Threads.
|
||||
|
||||
#include <hip_test_common.hh>
|
||||
#include <atomic>
|
||||
#include <utils.hh>
|
||||
|
||||
static constexpr size_t N = 4096;
|
||||
static constexpr int numThreads = 1000;
|
||||
@@ -43,33 +44,6 @@ static __global__ void device_function(float* C_d, float* A_d, size_t Num) {
|
||||
for (size_t i = gputhread; i < Num; i += stride) {
|
||||
C_d[i] = A_d[i] * A_d[i];
|
||||
}
|
||||
|
||||
// Delay thread 1 only in the GPU
|
||||
if (gputhread == 1) {
|
||||
uint64_t wait_t = 3200000000, start = clock64(), cur;
|
||||
do {
|
||||
cur = clock64() - start;
|
||||
} while (cur < wait_t);
|
||||
}
|
||||
}
|
||||
|
||||
static __global__ void device_function_gfx11(float* C_d, float* A_d, size_t Num) {
|
||||
#if HT_AMD
|
||||
size_t gputhread = (blockIdx.x * blockDim.x + threadIdx.x);
|
||||
size_t stride = blockDim.x * gridDim.x;
|
||||
|
||||
for (size_t i = gputhread; i < Num; i += stride) {
|
||||
C_d[i] = A_d[i] * A_d[i];
|
||||
}
|
||||
|
||||
// Delay thread 1 only in the GPU
|
||||
if (gputhread == 1) {
|
||||
uint64_t wait_t = 3200000000, start = wall_clock64(), cur;
|
||||
do {
|
||||
cur = wall_clock64() - start;
|
||||
} while (cur < wait_t);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void HIPRT_CB Thread1_Callback(hipStream_t stream, hipError_t status,
|
||||
@@ -146,10 +120,10 @@ TEST_CASE("Unit_hipStreamAddCallback_MultipleThreads") {
|
||||
constexpr unsigned threadsPerBlock = 256;
|
||||
constexpr unsigned blocks = (N + 255)/threadsPerBlock;
|
||||
|
||||
auto device_function_used = IsGfx11() ? device_function_gfx11 : device_function;
|
||||
hipLaunchKernelGGL((device_function_used), dim3(blocks),
|
||||
hipLaunchKernelGGL((device_function), dim3(blocks),
|
||||
dim3(threadsPerBlock), 0,
|
||||
mystream, C_d, A_d, N);
|
||||
LaunchDelayKernel(std::chrono::milliseconds(2000), mystream);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
HIP_CHECK(
|
||||
hipMemcpyAsync(C1_h, C_d, Nbytes,
|
||||
|
||||
@@ -19,6 +19,7 @@ THE SOFTWARE.
|
||||
|
||||
#include <chrono>
|
||||
#include <hip_test_common.hh>
|
||||
#include <utils.hh>
|
||||
|
||||
namespace hipStreamCreateWithFlagsTests {
|
||||
|
||||
@@ -69,11 +70,11 @@ TEST_CASE("Unit_hipStreamCreateWithFlags_DefaultStreamInteraction") {
|
||||
constexpr auto delay = std::chrono::milliseconds(500);
|
||||
|
||||
SECTION("default stream waiting for created stream") {
|
||||
HipTest::runKernelForDuration(delay, stream);
|
||||
LaunchDelayKernel(delay, stream);
|
||||
REQUIRE(hipStreamQuery(defaultStream) == expectedError);
|
||||
}
|
||||
SECTION("created stream waiting for default stream") {
|
||||
HipTest::runKernelForDuration(delay, defaultStream);
|
||||
LaunchDelayKernel(delay, defaultStream);
|
||||
REQUIRE(hipStreamQuery(stream) == expectedError);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ THE SOFTWARE.
|
||||
*/
|
||||
#include <chrono>
|
||||
#include <hip_test_common.hh>
|
||||
#include <utils.hh>
|
||||
|
||||
namespace hipStreamDestroyTests {
|
||||
|
||||
@@ -80,7 +81,7 @@ TEST_CASE("Unit_hipStreamDestroy_WithPendingWork") {
|
||||
HIP_CHECK(hipMalloc(&deviceData, sizeof(int) * numDataPoints));
|
||||
HIP_CHECK(hipMemset(deviceData, 0, sizeof(int) * numDataPoints));
|
||||
|
||||
HipTest::runKernelForDuration(std::chrono::milliseconds(500), stream);
|
||||
LaunchDelayKernel(std::chrono::milliseconds(500), stream);
|
||||
setToOne<<<1, numDataPoints, 0, stream>>>(deviceData, numDataPoints);
|
||||
HIP_CHECK_ERROR(hipStreamQuery(stream), hipErrorNotReady);
|
||||
HIP_CHECK_ERROR(hipStreamQuery(nullptr), hipErrorNotReady);
|
||||
|
||||
@@ -19,7 +19,7 @@ THE SOFTWARE.
|
||||
|
||||
#include <hip_test_common.hh>
|
||||
#include "streamCommon.hh"
|
||||
|
||||
#include <utils.hh>
|
||||
/**
|
||||
* @brief Check that querying a stream with no work returns hipSuccess
|
||||
*
|
||||
@@ -101,7 +101,7 @@ TEST_CASE("Unit_hipStreamQuery_SubmitWorkOnStreamAndQueryNullStream") {
|
||||
HIP_CHECK(hipStreamCreate(&stream));
|
||||
|
||||
HIP_CHECK(hipStreamQuery(hip::nullStream));
|
||||
HipTest::runKernelForDuration(std::chrono::milliseconds(500), stream);
|
||||
LaunchDelayKernel(std::chrono::milliseconds(500), stream);
|
||||
HIP_CHECK_ERROR(hipStreamQuery(hip::nullStream), hipErrorNotReady);
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
|
||||
@@ -116,7 +116,7 @@ TEST_CASE("Unit_hipStreamQuery_SubmitWorkOnStreamAndQueryNullStream") {
|
||||
*/
|
||||
TEST_CASE("Unit_hipStreamQuery_NullStreamQuery") {
|
||||
HIP_CHECK(hipStreamQuery(hip::nullStream));
|
||||
HipTest::runKernelForDuration(std::chrono::milliseconds(500), hip::nullStream);
|
||||
LaunchDelayKernel(std::chrono::milliseconds(500), hip::nullStream);
|
||||
HIP_CHECK_ERROR(hipStreamQuery(hip::nullStream), hipErrorNotReady);
|
||||
|
||||
HIP_CHECK(hipStreamSynchronize(hip::nullStream));
|
||||
@@ -130,8 +130,7 @@ TEST_CASE("Unit_hipStreamQuery_WithPendingWork") {
|
||||
hipStream_t waitingStream{nullptr};
|
||||
HIP_CHECK(hipStreamCreate(&waitingStream));
|
||||
|
||||
HipTest::runKernelForDuration(std::chrono::milliseconds(500), waitingStream);
|
||||
|
||||
LaunchDelayKernel(std::chrono::milliseconds(500), waitingStream);
|
||||
HIP_CHECK_ERROR(hipStreamQuery(waitingStream), hipErrorNotReady);
|
||||
HIP_CHECK(hipStreamSynchronize(waitingStream));
|
||||
HIP_CHECK(hipStreamQuery(waitingStream));
|
||||
|
||||
@@ -19,7 +19,7 @@ THE SOFTWARE.
|
||||
|
||||
#include <hip_test_common.hh>
|
||||
#include "streamCommon.hh"
|
||||
|
||||
#include <utils.hh>
|
||||
namespace hipStreamSynchronizeTest {
|
||||
|
||||
/**
|
||||
@@ -62,7 +62,7 @@ TEST_CASE("Unit_hipStreamSynchronize_FinishWork") {
|
||||
HIP_CHECK(hipStreamCreate(&stream));
|
||||
}
|
||||
|
||||
HipTest::runKernelForDuration(std::chrono::milliseconds(500), stream);
|
||||
LaunchDelayKernel(std::chrono::milliseconds(500), stream);
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
HIP_CHECK(hipStreamQuery(stream));
|
||||
|
||||
@@ -86,15 +86,15 @@ TEST_CASE("Unit_hipStreamSynchronize_NullStreamSynchronization") {
|
||||
}
|
||||
|
||||
for (int i = 0; i < totalStreams; ++i) {
|
||||
HipTest::runKernelForDuration(std::chrono::milliseconds(1000), streams[i]);
|
||||
LaunchDelayKernel(std::chrono::milliseconds(1000), streams[i]);
|
||||
}
|
||||
|
||||
HIP_CHECK_ERROR(hipStreamQuery(hip::nullStream), hipErrorNotReady);
|
||||
|
||||
for (int i = 0; i < totalStreams; ++i) {
|
||||
HIP_CHECK_ERROR(hipStreamQuery(streams[i]), hipErrorNotReady);
|
||||
}
|
||||
|
||||
HIP_CHECK_ERROR(hipStreamQuery(hip::nullStream), hipErrorNotReady);
|
||||
|
||||
HIP_CHECK(hipStreamSynchronize(hip::nullStream));
|
||||
HIP_CHECK(hipStreamQuery(hip::nullStream));
|
||||
|
||||
@@ -123,8 +123,8 @@ TEST_CASE("Unit_hipStreamSynchronize_SynchronizeStreamAndQueryNullStream") {
|
||||
HIP_CHECK(hipStreamCreate(&stream1));
|
||||
HIP_CHECK(hipStreamCreate(&stream2));
|
||||
|
||||
HipTest::runKernelForDuration(std::chrono::milliseconds(500), stream1);
|
||||
HipTest::runKernelForDuration(std::chrono::milliseconds(2000), stream2);
|
||||
LaunchDelayKernel(std::chrono::milliseconds(500), stream1);
|
||||
LaunchDelayKernel(std::chrono::milliseconds(2000), stream2);
|
||||
|
||||
SECTION("Do not use NullStream") {}
|
||||
SECTION("Submit Kernel to NullStream") {
|
||||
@@ -157,10 +157,10 @@ TEST_CASE("Unit_hipStreamSynchronize_SynchronizeStreamAndQueryNullStream") {
|
||||
*
|
||||
*/
|
||||
TEST_CASE("Unit_hipStreamSynchronize_NullStreamAndStreamPerThread") {
|
||||
HipTest::runKernelForDuration(std::chrono::milliseconds(500), hip::streamPerThread);
|
||||
LaunchDelayKernel(std::chrono::milliseconds(500), hip::streamPerThread);
|
||||
HIP_CHECK_ERROR(hipStreamQuery(hip::nullStream), hipErrorNotReady);
|
||||
HIP_CHECK_ERROR(hipStreamQuery(hip::streamPerThread), hipErrorNotReady);
|
||||
HipTest::runKernelForDuration(std::chrono::milliseconds(500), hip::nullStream);
|
||||
LaunchDelayKernel(std::chrono::milliseconds(500), hip::nullStream);
|
||||
HIP_CHECK(hipStreamSynchronize(hip::nullStream))
|
||||
HIP_CHECK_ERROR(hipStreamQuery(hip::streamPerThread), hipSuccess);
|
||||
HIP_CHECK_ERROR(hipStreamQuery(hip::nullStream), hipSuccess);
|
||||
|
||||
@@ -25,7 +25,7 @@ Unit_hipStreamWaitEvent_DifferentStreams - Test waiting for an event on a differ
|
||||
*/
|
||||
|
||||
#include <hip_test_common.hh>
|
||||
|
||||
#include <utils.hh>
|
||||
TEST_CASE("Unit_hipStreamWaitEvent_Negative") {
|
||||
enum class StreamTestType { NullStream = 0, StreamPerThread, CreatedStream };
|
||||
|
||||
@@ -79,35 +79,6 @@ TEST_CASE("Unit_hipStreamWaitEvent_UninitializedStream_Negative") {
|
||||
}
|
||||
#endif
|
||||
|
||||
// Since we can not use atomic*_system on every gpu, we will use wait based on clock rate.
|
||||
// This wont be accurate since clock rate of a GPU varies depending on many variables including
|
||||
// thermals, load, utilization
|
||||
__global__ void waitKernel(int clockRate, int seconds) {
|
||||
auto start = clock();
|
||||
auto ms = seconds * 1000;
|
||||
long long waitTill = clockRate * (long long)ms;
|
||||
while (1) {
|
||||
auto end = clock();
|
||||
if ((end - start) > waitTill) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void waitKernel_gfx11(int clockRate, int seconds) {
|
||||
#if HT_AMD
|
||||
auto start = wall_clock64();
|
||||
auto ms = seconds * 1000;
|
||||
long long waitTill = clockRate * (long long)ms;
|
||||
while (1) {
|
||||
auto end = wall_clock64();
|
||||
if ((end - start) > waitTill) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("Unit_hipStreamWaitEvent_Default") {
|
||||
hipStream_t stream{nullptr};
|
||||
hipEvent_t waitEvent{nullptr};
|
||||
@@ -118,15 +89,7 @@ TEST_CASE("Unit_hipStreamWaitEvent_Default") {
|
||||
REQUIRE(stream != nullptr);
|
||||
REQUIRE(waitEvent != nullptr);
|
||||
|
||||
int deviceId {};
|
||||
HIP_CHECK(hipGetDevice(&deviceId));
|
||||
|
||||
hipDeviceProp_t prop{};
|
||||
HIP_CHECK(hipGetDeviceProperties(&prop, deviceId));
|
||||
auto clockRate = prop.clockRate;
|
||||
|
||||
auto waitKernel_used = IsGfx11() ? waitKernel_gfx11 : waitKernel;
|
||||
waitKernel_used<<<1, 1, 0, stream>>>(clockRate, 2); // Wait for 2 seconds
|
||||
LaunchDelayKernel(std::chrono::milliseconds(2000), stream);
|
||||
|
||||
HIP_CHECK(hipEventRecord(waitEvent, stream));
|
||||
|
||||
@@ -154,15 +117,8 @@ TEST_CASE("Unit_hipStreamWaitEvent_DifferentStreams") {
|
||||
REQUIRE(streamBlockedOnStreamA != nullptr);
|
||||
REQUIRE(waitEvent != nullptr);
|
||||
|
||||
int deviceId {};
|
||||
HIP_CHECK(hipGetDevice(&deviceId));
|
||||
LaunchDelayKernel(std::chrono::milliseconds(3000), blockedStreamA);
|
||||
|
||||
hipDeviceProp_t prop{};
|
||||
HIP_CHECK(hipGetDeviceProperties(&prop, deviceId));
|
||||
auto clockRate = prop.clockRate;
|
||||
auto waitKernel_used = IsGfx11() ? waitKernel_gfx11 : waitKernel;
|
||||
waitKernel_used<<<1, 1, 0, blockedStreamA>>>(clockRate,
|
||||
3); // wait for 3 seconds
|
||||
HIP_CHECK(hipEventRecord(waitEvent, blockedStreamA));
|
||||
|
||||
// Make sure stream is waiting for data to be set
|
||||
@@ -170,7 +126,7 @@ TEST_CASE("Unit_hipStreamWaitEvent_DifferentStreams") {
|
||||
|
||||
HIP_CHECK(hipStreamWaitEvent(streamBlockedOnStreamA, waitEvent, 0));
|
||||
|
||||
waitKernel_used<<<1, 1, 0, streamBlockedOnStreamA>>>(clockRate, 2); // Wait for 2 seconds
|
||||
LaunchDelayKernel(std::chrono::milliseconds(2000), streamBlockedOnStreamA);
|
||||
|
||||
HIP_CHECK(hipStreamSynchronize(unblockingStream));
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户