Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate chipstar #459

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions catch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ option(ENABLE_ADDRESS_SANITIZER "Option to enable ASAN build" OFF)
message(STATUS "STANDALONE_TESTS : ${STANDALONE_TESTS}")

# Check if platform is set
if(NOT HIP_PLATFORM STREQUAL "amd" AND NOT HIP_PLATFORM STREQUAL "nvidia")
if(NOT HIP_PLATFORM STREQUAL "amd" AND NOT HIP_PLATFORM STREQUAL "nvidia" AND NOT HIP_PLATFORM STREQUAL "spirv")
message(FATAL_ERROR "Unexpected HIP_PLATFORM: " ${HIP_PLATFORM})
endif()

Expand Down Expand Up @@ -132,7 +132,21 @@ option(RTC_TESTING "Run tests using HIP RTC to compile the kernels" OFF)
if (RTC_TESTING)
add_definitions(-DRTC_TESTING=ON)
endif()
add_definitions(-DKERNELS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/kernels/")

# The following does not work
# add_definitions(-DKERNELS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/kernels/")
# In file included from /space/pvelesko/chipStar/hip-tests-update/hip-tests/catch/hipTestMain/main.cc:3:
# In file included from /space/pvelesko/chipStar/hip-tests-update/hip-tests/catch/./include/hip_test_common.hh:37:
# /space/pvelesko/chipStar/hip-tests-update/hip-tests/catch/./include/hip_test_rtc.hh:110:36: error: use of undeclared identifier 'tests'
# <command line>:1:68: note: expanded from macro 'KERNELS_PATH'
# 1 | #define KERNELS_PATH /space/pvelesko/chipStar/hip-tests-update/hip-tests/catch/kernels/
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/kernels_path.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/kernels_path.h"
)

# Include the generated header file directory
include_directories("${CMAKE_CURRENT_BINARY_DIR}")

set(CATCH_BUILD_DIR catch_tests)
execute_process(COMMAND ${CMAKE_COMMAND} -E
Expand Down
8 changes: 6 additions & 2 deletions catch/external/Catch2/cmake/Catch2/Catch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ function(hip_add_exe_to_target_compile_time_detection)
add_executable(${_EXE_NAME} EXCLUDE_FROM_ALL ${SRC_NAME} ${COMMON_SHARED_SRC} $<TARGET_OBJECTS:Main_Object>)
if(HIP_PLATFORM STREQUAL "amd")
target_link_libraries(${_EXE_NAME} hiprtc)
else()
elseif(HIP_PLATFORM STREQUAL "nvidia")
target_link_libraries(${_EXE_NAME} nvrtc)
endif()
endif()
Expand Down Expand Up @@ -365,8 +365,12 @@ function(hip_add_exe_to_target)
add_executable(${_EXE_NAME} EXCLUDE_FROM_ALL ${SRC_NAME} ${COMMON_SHARED_SRC} $<TARGET_OBJECTS:Main_Object>)
if(HIP_PLATFORM STREQUAL "amd")
target_link_libraries(${_EXE_NAME} hiprtc)
else()
elseif(HIP_PLATFORM STREQUAL "nvidia")
target_link_libraries(${_EXE_NAME} nvrtc)
elseif(HIP_PLATFORM STREQUAL "spirv")
# nothing extra needed for chipStar
else()
message(FATAL_ERROR "Unsupported HIP_PLATFORM: ${HIP_PLATFORM}")
endif()
endif()
if (DEFINED _PROPERTY)
Expand Down
5 changes: 4 additions & 1 deletion catch/hipTestMain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ endif()
add_library(Main_Object EXCLUDE_FROM_ALL OBJECT main.cc hip_test_context.cc hip_test_features.cc)
if(HIP_PLATFORM MATCHES "amd")
set_property(TARGET Main_Object PROPERTY CXX_STANDARD 17)
else()
elseif(HIP_PLATFORM MATCHES "nvidia")
target_compile_options(Main_Object PUBLIC -std=c++17)
elseif(HIP_PLATFORM MATCHES "spirv")
target_compile_options(Main_Object PUBLIC ${HIP_OFFLOAD_COMPILE_OPTIONS_BUILD_})
set_property(TARGET Main_Object PROPERTY CXX_STANDARD 17)
endif()
11 changes: 10 additions & 1 deletion catch/hipTestMain/hip_test_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ void TestContext::detectOS() {
void TestContext::detectPlatform() {
#if (HT_AMD == 1)
amd = true;
#elif (HT_SPIRV == 1)
spirv = true;
#elif (HT_NVIDIA == 1)
nvidia = true;
#endif
Expand Down Expand Up @@ -160,7 +162,13 @@ std::string& TestContext::getCommonJsonFile() {


void TestContext::getConfigFiles() {
config_.platform = (amd ? "amd" : (nvidia ? "nvidia" : "unknown"));
if(config_.platform == "amd") {
amd = true;
} else if(config_.platform == "nvidia") {
nvidia = true;
} else if(config_.platform == "spirv") {
spirv = true;
}
config_.os = (p_windows ? "windows" : (p_linux ? "linux" : "unknown"));

if (config_.os == "unknown" || config_.platform == "unknown") {
Expand Down Expand Up @@ -210,6 +218,7 @@ bool TestContext::isLinux() const { return p_linux; }

bool TestContext::isNvidia() const { return nvidia; }
bool TestContext::isAmd() const { return amd; }
bool TestContext::isSpirv() const { return spirv; }

void TestContext::parseOptions(int argc, char** argv) {
// Test name is at [1] position
Expand Down
60 changes: 48 additions & 12 deletions catch/include/hip_test_common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ THE SOFTWARE.
#include <mutex>
#include <cstdlib>
#include <thread>
// Had to add this include to make the code compile
// error: use of undeclared identifier 'launchRTCKernel'
#include "hip_test_rtc.hh"

#define HIP_PRINT_STATUS(status) INFO(hipGetErrorName(status) << " at line: " << __LINE__);

Expand Down Expand Up @@ -254,7 +257,7 @@ static inline int RAND_R(unsigned* rand_seed) {

inline bool isImageSupported() {
int imageSupport = 1;
#if HT_AMD
#if HT_AMD || HT_SPIRV
int device;
HIP_CHECK(hipGetDevice(&device));
HIPCHECK(hipDeviceGetAttribute(&imageSupport, hipDeviceAttributeImageSupport, device));
Expand All @@ -276,7 +279,9 @@ static inline void HIP_SKIP_TEST(char const* const reason) noexcept {
*
* @return constexpr std::tuple<FArgs...> the expected arguments of the kernel.
*/
template <typename... FArgs> std::tuple<FArgs...> getExpectedArgs(void(FArgs...)){};
// template <typename... FArgs> std::tuple<FArgs...> getExpectedArgs(void(FArgs...)){};
template <typename... FArgs>
std::tuple<FArgs...> getExpectedArgs(void(*)(FArgs...)) {};

/**
* @brief Asserts that the types of the arguments of a function match exactly with the types in the
Expand All @@ -289,10 +294,18 @@ template <typename... FArgs> std::tuple<FArgs...> getExpectedArgs(void(FArgs...)
* @tparam F the kernel function
* @tparam Args the parameters that will be passed to the kernel.
*/
template <typename F, typename... Args> void validateArguments(F f, Args...) {
using expectedArgsTuple = decltype(getExpectedArgs(f));
static_assert(std::is_same<expectedArgsTuple, std::tuple<Args...>>::value,
"Kernel arguments types must match exactly!");
// template <typename F, typename... Args> void validateArguments(F f, Args...) {
// using expectedArgsTuple = decltype(getExpectedArgs(f));
// static_assert(std::is_same<expectedArgsTuple, std::tuple<Args...>>::value,
// "Kernel arguments types must match exactly!");
// }
template <typename F, typename... Args>
void validateArguments(F f, Args&&... args) {
using expectedArgsTuple = decltype(getExpectedArgs(f));
using providedArgsTuple = std::tuple<Args...>;

static_assert(std::is_same<expectedArgsTuple, providedArgsTuple>::value,
"Kernel arguments types must match exactly!");
}

/**
Expand All @@ -311,15 +324,38 @@ template <typename F, typename... Args> void validateArguments(F f, Args...) {
* @param stream
* @param packedArgs A list of kernel arguments to be forwarded.
*/
template <typename... Typenames, typename K, typename Dim, typename... Args>
void launchKernel(K kernel, Dim numBlocks, Dim numThreads, std::uint32_t memPerBlock,
hipStream_t stream, Args&&... packedArgs) {
// template <typename... Typenames, typename K, typename Dim, typename... Args>
// void launchKernel(K kernel, Dim numBlocks, Dim numThreads, std::uint32_t memPerBlock,
// hipStream_t stream, Args&&... packedArgs) {
// #ifndef RTC_TESTING
// validateArguments(kernel, packedArgs...);
// kernel<<<numBlocks, numThreads, memPerBlock, stream>>>(std::forward<Args>(packedArgs)...);
// #else
// launchRTCKernel<Typenames...>(kernel, numBlocks, numThreads, memPerBlock, stream,
// std::forward<Args>(packedArgs)...);
// #endif
// HIP_CHECK(hipGetLastError());
// }
Comment on lines +328 to +339
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't working - fix implemented below. With the following changes I was able to compile using LLVM17.

This solution seems not to respect const. Does the original implementation (can't test since it doesn't compile) ?


template <typename... Typenames, typename Kernel, typename Dim, typename... Args>
void launchKernel(Kernel kernel, Dim numBlocks, Dim numThreads, std::uint32_t memPerBlock, hipStream_t stream, Args&&... args) {
#ifndef RTC_TESTING
validateArguments(kernel, packedArgs...);
kernel<<<numBlocks, numThreads, memPerBlock, stream>>>(std::forward<Args>(packedArgs)...);
// Define a stateless, capture-free lambda that matches the kernel's signature.
auto kernelWrapperLambda = [] (Args... args) {
// This lambda is intentionally left empty as it's used solely for type validation.
};

// Convert the lambda to a function pointer.
void (*kernelWrapper)(Args...) = kernelWrapperLambda;

// Use the wrapper function pointer to validate arguments.
validateArguments(kernelWrapper, std::forward<Args>(args)...);

// Launch the kernel directly with the provided arguments.
kernel<<<numBlocks, numThreads, memPerBlock, stream>>>(std::forward<Args>(args)...);
#else
launchRTCKernel<Typenames...>(kernel, numBlocks, numThreads, memPerBlock, stream,
std::forward<Args>(packedArgs)...);
std::forward<Args>(args)...);
#endif
HIP_CHECK(hipGetLastError());
}
Expand Down
11 changes: 9 additions & 2 deletions catch/include/hip_test_context.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ THE SOFTWARE.
#if defined(__HIP_PLATFORM_AMD__)
#define HT_AMD 1
#define HT_NVIDIA 0
#define HT_SPIRV 0
#elif defined(__HIP_PLATFORM_NVIDIA__)
#define HT_AMD 0
#define HT_NVIDIA 1
#define HT_SPIRV 0
#elif defined(__HIP_PLATFORM_CLANG__) || defined(__HIP_PLATFORM_SPIRV__)
#define HT_AMD 0
#define HT_NVIDIA 0
#define HT_SPIRV 1
#else
#error "Platform not recognized"
#endif
Expand All @@ -74,12 +80,12 @@ struct HCResult {

class TestContext {
bool p_windows = false, p_linux = false; // OS
bool amd = false, nvidia = false; // HIP Platform
bool amd = false, nvidia = false, spirv = false; // HIP Platform
std::string exe_path;
std::string current_test;
std::set<std::string> skip_test;
std::string json_file_;
std::vector<std::string> platform_list_ = {"amd", "nvidia"};
std::vector<std::string> platform_list_ = {"amd", "nvidia", "spirv"};
std::vector<std::string> os_list_ = {"windows", "linux", "all"};
std::vector<std::string> amd_arch_list_ = {};

Expand Down Expand Up @@ -141,6 +147,7 @@ class TestContext {
bool isLinux() const;
bool isNvidia() const;
bool isAmd() const;
bool isSpirv() const;
bool skipTest() const;

const std::string& getCurrentTest() const { return current_test; }
Expand Down
1 change: 1 addition & 0 deletions catch/include/hip_test_rtc.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ THE SOFTWARE.
#include <mutex>
#include "hip/hip_runtime_api.h"
#include "hip_test_context.hh"
#include "kernels_path.h"

namespace HipTest {

Expand Down
8 changes: 4 additions & 4 deletions catch/include/memcpy3d_tests_common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -595,31 +595,31 @@ void Memcpy3DZeroWidthHeightDepth(F memcpy_func, const hipStream_t stream = null
}

constexpr auto MemTypeHost() {
#if HT_AMD
#if HT_AMD || HT_SPIRV
return hipMemoryTypeHost;
#else
return CU_MEMORYTYPE_HOST;
#endif
}

constexpr auto MemTypeDevice() {
#if HT_AMD
#if HT_AMD || HT_SPIRV
return hipMemoryTypeDevice;
#else
return CU_MEMORYTYPE_DEVICE;
#endif
}

constexpr auto MemTypeArray() {
#if HT_AMD
#if HT_AMD || HT_SPIRV
return hipMemoryTypeArray;
#else
return CU_MEMORYTYPE_ARRAY;
#endif
}

constexpr auto MemTypeUnified() {
#if HT_AMD
#if HT_AMD || HT_SPIRV
return hipMemoryTypeUnified;
#else
return CU_MEMORYTYPE_UNIFIED;
Expand Down
4 changes: 2 additions & 2 deletions catch/include/utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static __global__ void Delay(uint32_t interval, const uint32_t ticks_per_ms) {
__builtin_amdgcn_s_sleep(10);
}
#endif
#if HT_NVIDIA
#if HT_NVIDIA || HT_SPIRV
uint64_t start = clock64();
while (clock64() - start < ticks_per_ms) {
}
Expand All @@ -150,7 +150,7 @@ __global__ void Iota(T* const out, size_t pitch, size_t w, size_t h, size_t d) {

inline void LaunchDelayKernel(const std::chrono::milliseconds interval, const hipStream_t stream = nullptr) {
int ticks_per_ms = 0;
#if HT_AMD
#if HT_AMD || HT_SPIRV
HIPCHECK(hipDeviceGetAttribute(&ticks_per_ms, hipDeviceAttributeWallClockRate, 0));
#endif
#if HT_NVIDIA
Expand Down
6 changes: 6 additions & 0 deletions catch/kernels_path.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef KERNELS_PATH_H
#define KERNELS_PATH_H

#define KERNELS_PATH "@CMAKE_CURRENT_SOURCE_DIR@/kernels/"

#endif
Comment on lines +1 to +6
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part also didn't compile. Tried escaping in the CMakeLists.txt but didn't work.

1 change: 1 addition & 0 deletions catch/packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,5 @@ set(CPACK_TEST_ZIP "ON")
set(CPACK_ZIP_TEST_PACKAGE_NAME "catch")
endif()

set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/../../LICENSE.txt")
include(CPack)
2 changes: 1 addition & 1 deletion catch/performance/stream/hipStreamWaitValue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ THE SOFTWARE.

static int IsStreamWaitValueSupported(int device_id) {
int wait_value_supported = 0;
#if HT_AMD
#if HT_AMD || HT_SPIRV
HIP_CHECK(hipDeviceGetAttribute(&wait_value_supported, hipDeviceAttributeCanUseStreamWaitValue,
device_id));
#else
Expand Down
3 changes: 3 additions & 0 deletions catch/stress/memory/hipHmmOvrSubscriptionTst.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ __global__ void floatx2(float* ptr, size_t size) {
}

TEST_CASE("Stress_HMM_OverSubscriptionTst") {
#if HT_SPIRV
HipTest::HIP_SKIP_TEST("Stress_HMM_OverSubscriptionTst Unsupported on SPIRV");
#endif
int hmm = 0;
HIP_CHECK(hipDeviceGetAttribute(&hmm, hipDeviceAttributeManagedMemory, 0));

Expand Down
3 changes: 3 additions & 0 deletions catch/stress/memory/hipHostRegisterStress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ static __global__ void Inc(uint8_t* Ad) {
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Stress_hipHostRegister_Oversubscription") {
#if HT_SPIRV
HipTest::HIP_SKIP_TEST("Stress_hipHostRegister_Oversubscription Unsupported on SPIRV");
#endif
hipDeviceProp_t prop;
HIP_CHECK(hipGetDeviceProperties(&prop, 0));
std::string arch = prop.gcnArchName;
Expand Down
10 changes: 7 additions & 3 deletions catch/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ add_subdirectory(memory)
add_subdirectory(stream_ordered)
add_subdirectory(stream)
add_subdirectory(event)
add_subdirectory(occupancy)
add_subdirectory(device)
add_subdirectory(printf)
add_subdirectory(texture)
add_subdirectory(surface)
add_subdirectory(streamperthread)
add_subdirectory(kernel)
add_subdirectory(multiThread)
Expand All @@ -54,6 +51,13 @@ add_subdirectory(syncthreads)
add_subdirectory(threadfence)
add_subdirectory(virtualMemoryManagement)


if(NOT HIP_PLATFORM STREQUAL "spirv")
add_subdirectory(occupancy)
add_subdirectory(surface)
add_subdirectory(texture)
endif()

if(HIP_PLATFORM STREQUAL "amd")
add_subdirectory(callback)
#add_subdirectory(clock)
Expand Down
4 changes: 2 additions & 2 deletions catch/unit/assertion/assert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ template <bool should_abort> void LaunchAssertKernel() {

if constexpr (should_abort) {
AssertFailKernel<<<num_blocks, num_threads, 0, 0>>>(d_a);
#if HT_AMD
#if HT_AMD || HT_SPIRV
HIP_CHECK(hipDeviceSynchronize());
#else
HIP_CHECK_ERROR(hipDeviceSynchronize(), hipErrorAssert);
Expand Down Expand Up @@ -116,7 +116,7 @@ TEST_CASE("Unit_Assert_Positive_Basic_KernelPass") {
*/
TEST_CASE("Unit_Assert_Positive_Basic_KernelFail") {
try_and_catch_abort(&LaunchAssertKernel<true>);
#if HT_AMD
#if HT_AMD || HT_SPIRV
REQUIRE(abort_raised_flag == 1);
#else
REQUIRE(abort_raised_flag == 0);
Expand Down
Loading