From a139e0489684b79d56ec116a48e3739fb57e5a67 Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Wed, 6 Nov 2019 14:42:50 -0500 Subject: [PATCH] kfdtest: Adapt the CWSR test for emulators The original test takes forever to run on emulators because emulators are much slower than Asic. So intelligently detect the emulator scenarios and reduce the run time by slashing the iteration times. Change-Id: I087f43c04c2b23b5ab2ecaad07533b767c337e94 Signed-off-by: Yong Zhao [ROCm/ROCR-Runtime commit: 21cda69ba9dd2ef47a9c125f5820878ee1f0f9d2] --- .../tests/kfdtest/src/KFDCWSRTest.cpp | 16 ++++++++++++ .../tests/kfdtest/src/KFDTestUtil.cpp | 25 +++++++++++++++++++ .../tests/kfdtest/src/KFDTestUtil.hpp | 1 + 3 files changed, 42 insertions(+) diff --git a/projects/rocr-runtime/tests/kfdtest/src/KFDCWSRTest.cpp b/projects/rocr-runtime/tests/kfdtest/src/KFDCWSRTest.cpp index bc9b9698f9..5a4dbb4340 100644 --- a/projects/rocr-runtime/tests/kfdtest/src/KFDCWSRTest.cpp +++ b/projects/rocr-runtime/tests/kfdtest/src/KFDCWSRTest.cpp @@ -114,6 +114,14 @@ void KFDCWSRTest::TearDown() { ROUTINE_END } +bool isOnEmulator() { + uint32_t isEmuMode = 0; + + fscanf_dec("/sys/module/amdgpu/parameters/emu_mode", &isEmuMode); + + return isEmuMode; +} + /** * KFDCWSRTest.BasicTest * @@ -135,6 +143,14 @@ TEST_F(KFDCWSRTest, BasicTest) { int count1 = 40000000; int count2 = 20000000; + if (isOnEmulator()) { + // Divide the iterator times by 1000 so that the test can + // finish in a reasonable time. + count1 /= 1000; + count2 /= 1000; + LOG() << "On Emulators" << std::endl; + } + unsigned int* result1 = resultBuf1.As(); unsigned int* result2 = resultBuf2.As(); const char *pIterateIsa; diff --git a/projects/rocr-runtime/tests/kfdtest/src/KFDTestUtil.cpp b/projects/rocr-runtime/tests/kfdtest/src/KFDTestUtil.cpp index f8743cb020..b55cd80247 100644 --- a/projects/rocr-runtime/tests/kfdtest/src/KFDTestUtil.cpp +++ b/projects/rocr-runtime/tests/kfdtest/src/KFDTestUtil.cpp @@ -39,6 +39,31 @@ void WaitUntilInput() { } while (dummy != 10); // enter key's ascii value is 10 } +/* fscanf_dec - read a file whose content is a decimal number + * @file [IN ] file to read + * @num [OUT] number in the file + * + * It is copied from the same function in libhsakmt + */ +HSAKMT_STATUS fscanf_dec(const char *file, uint32_t *num) +{ + FILE *fd; + HSAKMT_STATUS ret = HSAKMT_STATUS_SUCCESS; + + fd = fopen(file, "r"); + if (!fd) { + LOG() << "Failed to open " << file << std::endl; + return HSAKMT_STATUS_INVALID_PARAMETER; + } + if (fscanf(fd, "%u", num) != 1) { + LOG() << "Failed to parse as a decimal: " << file << std::endl;; + ret = HSAKMT_STATUS_ERROR; + } + + fclose(fd); + return ret; +} + uint64_t RoundToPowerOf2(uint64_t val) { int bytes = sizeof(uint64_t); diff --git a/projects/rocr-runtime/tests/kfdtest/src/KFDTestUtil.hpp b/projects/rocr-runtime/tests/kfdtest/src/KFDTestUtil.hpp index 139fbd1513..28847f370e 100644 --- a/projects/rocr-runtime/tests/kfdtest/src/KFDTestUtil.hpp +++ b/projects/rocr-runtime/tests/kfdtest/src/KFDTestUtil.hpp @@ -36,6 +36,7 @@ class BaseQueue; #define CounterToNanoSec(x) ((x) * 1000 / (is_dgpu() ? 27 : 100)) void WaitUntilInput(); +HSAKMT_STATUS fscanf_dec(const char *file, uint32_t *num); uint64_t RoundToPowerOf2(uint64_t val); // @brief: waits until the value is written to the buffer or until time out if received through args