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

Change-Id: I3783caf85c694b724ed55b778220b8ef9a39f84b
Αυτή η υποβολή περιλαμβάνεται σε:
Jatin Chaudhary authored and Jatin Chaudhary committed 2021-05-25 07:12:54 -04:00
1 γονέας f088812b6f
υποβολή da360c2aab
17 files changed
+603 -130

No files matched your search

@@ -1,9 +1,18 @@
# Common Tests - Test independent of all platforms
set(TEST_SRC
floatMath.cc
)
# AMD only tests
set(AMD_TEST_SRC
vectorTypesDevice.cc
)
if(HIP_PLATFORM MATCHES "amd")
set(TEST_SRC ${TEST_SRC} ${AMD_TEST_SRC})
endif()
# Create shared lib of all tests
add_library(DeviceLibs SHARED EXCLUDE_FROM_ALL ${TEST_SRC})
@@ -2,12 +2,11 @@
#include <iostream>
template <typename T> __global__ void add(T* a, T* b, T* c, size_t size) {
int i = threadIdx.x;
c[i] = a[i] + b[i];
size_t i = threadIdx.x;
if (i < size) c[i] = a[i] + b[i];
}
TEMPLATE_TEST_CASE("Add Kernel", "[kernel][add]", int, long, float, long long, double) {
auto addKernel = add<TestType>;
auto size = GENERATE(as<size_t>{}, 100, 500, 1000);
TestType *d_a, *d_b, *d_c;
auto res = hipMalloc(&d_a, sizeof(TestType) * size);
@@ -18,7 +17,7 @@ TEMPLATE_TEST_CASE("Add Kernel", "[kernel][add]", int, long, float, long long, d
REQUIRE(res == hipSuccess);
std::vector<TestType> a, b, c;
for (int i = 0; i < size; i++) {
for (size_t i = 0; i < size; i++) {
a.push_back(i + 1);
b.push_back(i + 1);
c.push_back(2 * (i + 1));
@@ -29,7 +28,7 @@ TEMPLATE_TEST_CASE("Add Kernel", "[kernel][add]", int, long, float, long long, d
res = hipMemcpy(d_b, b.data(), sizeof(TestType) * size, hipMemcpyHostToDevice);
REQUIRE(res == hipSuccess);
hipLaunchKernelGGL(addKernel, 1, size, 0, 0, d_a, d_b, d_c, size);
hipLaunchKernelGGL(add<TestType>, 1, size, 0, 0, d_a, d_b, d_c, size);
res = hipMemcpy(a.data(), d_c, sizeof(TestType) * size, hipMemcpyDeviceToHost);
REQUIRE(res == hipSuccess);
@@ -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
Προβολή Αρχείου
@@ -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);
}
@@ -1,6 +0,0 @@
#include <hip_test_common.hh>
TEST_CASE("cpp17 test") {
constexpr auto l = []() { return 2 * 10 * 30; };
REQUIRE(l() == 600);
}