SWDEV-277697 - [CatchTest] Fix Documentation, Add test to AMD specific, Add HIP Macros, New Binary for multiproc tests

Change-Id: I3783caf85c694b724ed55b778220b8ef9a39f84b
This commit is contained in:
Jatin Chaudhary
2021-05-21 02:31:28 -07:00
committed by Jatin Chaudhary
parent f088812b6f
commit da360c2aab
17 changed files with 603 additions and 130 deletions
+8 -10
View File
@@ -1,14 +1,12 @@
# Common Tests - Test independent of all platforms
set(TEST_SRC
# AMD Tests
set(AMD_TEST_SRC
saxpy.cc
)
# Set source File properties
set_source_files_properties(saxpy.cc PROPERTIES COMPILE_FLAGS " -std=c++14 ")
set_source_files_properties(test.cc PROPERTIES COMPILE_FLAGS " -std=c++17 ")
if(HIP_PLATFORM MATCHES "amd")
# Create shared lib of all tests
add_library(RTC SHARED EXCLUDE_FROM_ALL ${AMD_TEST_SRC})
# Create shared lib of all tests
add_library(RTC SHARED EXCLUDE_FROM_ALL ${TEST_SRC})
# Add dependency on build_tests to build it on this custom target
add_dependencies(build_tests RTC)
# Add dependency on build_tests to build it on this custom target
add_dependencies(build_tests RTC)
endif()
+33 -34
View File
@@ -15,7 +15,7 @@ static constexpr auto NUM_THREADS{128};
static constexpr auto NUM_BLOCKS{32};
static constexpr auto saxpy{
R"(
R"(
#include <hip/hip_runtime.h>
extern "C"
__global__
@@ -23,8 +23,7 @@ void saxpy(float a, float* x, float* y, float* out, size_t n)
{
size_t tid = blockIdx.x * blockDim.x + threadIdx.x;
if (tid < n) {
out[tid] = a * x[tid] + y[tid] ;
out[tid] = a * x[tid] + y[tid];
}
}
@@ -72,42 +71,42 @@ TEST_CASE("saxpy", "[hiprtc][saxpy]") {
unique_ptr<float[]> hX{new float[n]};
unique_ptr<float[]> hY{new float[n]};
unique_ptr<float[]> hOut{new float[n]};
for (size_t i = 0; i < n; ++i) {
hX[i] = static_cast<float>(i);
hY[i] = static_cast<float>(i * 2);
}
for (size_t i = 0; i < n; ++i) {
hX[i] = static_cast<float>(i);
hY[i] = static_cast<float>(i * 2);
}
hipDeviceptr_t dX, dY, dOut;
hipMalloc(&dX, bufferSize);
hipMalloc(&dY, bufferSize);
hipMalloc(&dOut, bufferSize);
hipMemcpyHtoD(dX, hX.get(), bufferSize);
hipMemcpyHtoD(dY, hY.get(), bufferSize);
hipDeviceptr_t dX, dY, dOut;
hipMalloc(&dX, bufferSize);
hipMalloc(&dY, bufferSize);
hipMalloc(&dOut, bufferSize);
hipMemcpyHtoD(dX, hX.get(), bufferSize);
hipMemcpyHtoD(dY, hY.get(), bufferSize);
struct {
float a_;
hipDeviceptr_t b_;
hipDeviceptr_t c_;
hipDeviceptr_t d_;
size_t e_;
} args{a, dX, dY, dOut, n};
struct {
float a_;
hipDeviceptr_t b_;
hipDeviceptr_t c_;
hipDeviceptr_t d_;
size_t e_;
} args{a, dX, dY, dOut, n};
auto size = sizeof(args);
void* config[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args,
HIP_LAUNCH_PARAM_BUFFER_SIZE, &size,
HIP_LAUNCH_PARAM_END};
auto size = sizeof(args);
void* config[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args, HIP_LAUNCH_PARAM_BUFFER_SIZE, &size,
HIP_LAUNCH_PARAM_END};
hipModuleLaunchKernel(kernel, NUM_BLOCKS, 1, 1, NUM_THREADS, 1, 1,
0, nullptr, nullptr, config);
hipMemcpyDtoH(hOut.get(), dOut, bufferSize);
hipModuleLaunchKernel(kernel, NUM_BLOCKS, 1, 1, NUM_THREADS, 1, 1, 0, nullptr, nullptr, config);
hipMemcpyDtoH(hOut.get(), dOut, bufferSize);
for (size_t i = 0; i < n; ++i) {
REQUIRE(fabs(a * hX[i] + hY[i] - hOut[i]) > fabs(hOut[i]) * 1e-6);
}
for (size_t i = 0; i < n; ++i) {
INFO("For " << i << " Value: " << fabs(a * hX[i] + hY[i] - hOut[i])
<< " with: " << (fabs(hOut[i] * 1.0f) * 1e-6));
REQUIRE(fabs(a * hX[i] + hY[i] - hOut[i]) <= fabs(hOut[i]) * 1e-6);
}
hipFree(dX);
hipFree(dY);
hipFree(dOut);
hipFree(dX);
hipFree(dY);
hipFree(dOut);
hipModuleUnload(module);
hipModuleUnload(module);
}
-6
View File
@@ -1,6 +0,0 @@
#include <hip_test_common.hh>
TEST_CASE("cpp17 test") {
constexpr auto l = []() { return 2 * 10 * 30; };
REQUIRE(l() == 600);
}