Skip to content

Commit 8681b3e

Browse files
Adapts some in-tree smoke tests to work on Windows. (#422)
* This has nothing to do with the full regression test harness: it just makes the default `ctest` unit tests work on Windows: * Fixes the example/cpp-sdk-user test so that it sets up the HIP compiler properly and sets the PATH when running tests so that in-tree DLLs can be found. * Extends the `hip-host-test` to also take an argument for the device ordinal to validate. This can be used for very basic sanity checking that the runtime works at all on a platform. * Conditions running extended device tests (vs just tests that will pass on a build machine without a GPU) by the `THEROCK_ENABLE_DEVICE_TEST=ON` env var. This lets us get some extended sanity checking in client builds by `$env:THEROCK_ENABLE_DEVICE_TEST=ON`. * Turns the kernel test into an executable and tests it as well if THEROCK_ENABLE_DEVICE_TEST. * Disables shared library tests on WIN32. * Fixes fileset_tool to not attempt to fchmod on Windows when decompressing. * Fixes fileset_tool to consider `*.lib` files part of dev components.
1 parent 7da18cd commit 8681b3e

File tree

7 files changed

+119
-16
lines changed

7 files changed

+119
-16
lines changed

build_tools/_therock_utils/artifacts.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,10 @@ def __call__(self, *artifact_paths: Sequence[Path]):
218218
) as out_file:
219219
out_file.write(member_file.read())
220220
st = os.fstat(out_file.fileno())
221-
new_mode = st.st_mode | exec_mask
222-
os.fchmod(out_file.fileno(), new_mode)
221+
if hasattr(os, "fchmod"):
222+
# Windows has no fchmod.
223+
new_mode = st.st_mode | exec_mask
224+
os.fchmod(out_file.fileno(), new_mode)
223225
elif member.isdir():
224226
dest_path.mkdir(parents=True, exist_ok=True)
225227
elif member.issym():

build_tools/fileset_tool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def get(name: str) -> "ComponentDefaults":
8282
"dev",
8383
includes=[
8484
"**/*.a",
85+
"**/*.lib",
8586
"**/cmake/**",
8687
"**/include/**",
8788
"**/share/modulefiles/**",

cmake/therock_testing.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ function(therock_test_validate_shared_lib)
88
"PATH"
99
"LIB_NAMES"
1010
)
11+
if(WIN32)
12+
# This helper is Linux only. In the future, we can have separate DLL_NAMES
13+
# and verify.
14+
return()
15+
endif()
16+
1117
if(NOT IS_ABSOLUTE ARG_PATH)
1218
cmake_path(ABSOLUTE_PATH ARG_PATH BASE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
1319
endif()

examples/CMakeLists.txt

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
# TODO: HIP language support not based on an /opt/rocm installed SDK
2+
# must have these three cache variables set to avoid language setup
3+
# error. https://github.com/ROCm/TheRock/issues/102
4+
set(HIP_CMAKE_ARGS
5+
-DCMAKE_HIP_PLATFORM=amd
6+
"-DCMAKE_HIP_COMPILER_ROCM_ROOT=${THEROCK_BINARY_DIR}/dist/rocm"
7+
)
8+
9+
if(WIN32)
10+
# On Windows, only a unified compiler is supported (i.e. use the HIP compiler
11+
# for everything).
12+
list(APPEND HIP_CMAKE_ARGS
13+
"-DCMAKE_CXX_COMPILER=${THEROCK_BINARY_DIR}/dist/rocm/lib/llvm/bin/clang++${CMAKE_EXECUTABLE_SUFFIX}"
14+
)
15+
else()
16+
# On everything else, the HIP language compiler can be independent from the
17+
# overall CXX compiler.
18+
list(APPEND HIP_CMAKE_ARGS
19+
"-DCMAKE_HIP_COMPILER=${THEROCK_BINARY_DIR}/dist/rocm/lib/llvm/bin/clang++${CMAKE_EXECUTABLE_SUFFIX}"
20+
)
21+
endif()
22+
123
add_test(
224
NAME therock-examples-cpp-sdk-user
325
COMMAND
@@ -15,13 +37,6 @@ add_test(
1537
"-DTHEROCK_ENABLE_RCCL=${THEROCK_ENABLE_RCCL}"
1638
"-DTHEROCK_ENABLE_SOLVER=${THEROCK_ENABLE_SOLVER}"
1739
"-DTHEROCK_ENABLE_SPARSE=${THEROCK_ENABLE_SPARSE}"
18-
19-
# TODO: HIP language support not based on an /opt/rocm installed SDK
20-
# must have these three cache variables set to avoid language setup
21-
# error. https://github.com/ROCm/TheRock/issues/102
22-
-DCMAKE_HIP_PLATFORM=amd
23-
"-DCMAKE_HIP_COMPILER=${THEROCK_BINARY_DIR}/dist/rocm/lib/llvm/bin/clang++"
24-
"-DCMAKE_HIP_COMPILER_ROCM_ROOT=${THEROCK_BINARY_DIR}/dist/rocm"
25-
40+
${HIP_CMAKE_ARGS}
2641
-P "${CMAKE_CURRENT_SOURCE_DIR}/clean_configure_test_project.cmake"
2742
)

examples/clean_configure_test_project.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ if(EXISTS "${BINARY_DIR}")
44
endif()
55

66
set(propagate_vars
7+
CMAKE_CXX_COMPILER
78
THEROCK_ENABLE_BLAS
89
THEROCK_ENABLE_FFT
910
THEROCK_ENABLE_HIP
@@ -31,7 +32,7 @@ execute_process(
3132
"${BINARY_DIR}"
3233
--build-generator "${GENERATOR}"
3334
--build-options ${build_options}
34-
--test-command "${CMAKE_CTEST_COMMAND}" --output-on-failure
35+
--test-command "${CMAKE_CTEST_COMMAND}" --output-on-failure --verbose
3536
RESULT_VARIABLE CMD_RESULT
3637
)
3738

examples/cpp-sdk-user/CMakeLists.txt

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ enable_testing()
1111

1212
set(CMAKE_CXX_STANDARD 17)
1313

14+
include(CMakeDependentOption)
15+
1416
# If defining a new option, ensure it is in the outer CMakeLists.txt and
1517
# the clean_configure_test_project.cmake to ensure it is passed from the
1618
# parent when testing.
@@ -23,6 +25,17 @@ option(THEROCK_ENABLE_RAND "Whether rocrand/hiprand are available" ON)
2325
option(THEROCK_ENABLE_RCCL "Whether rccl is available" ON)
2426
option(THEROCK_ENABLE_SOLVER "Whether rocsolver/hipsolver are available" ON)
2527
option(THEROCK_ENABLE_SPARSE "Whether rocsparse/hipsparse are available" ON)
28+
option(ENABLE_DEVICE_TEST "Whether to enable testing that requires a device" OFF)
29+
30+
set(TEST_PATH)
31+
if(WIN32)
32+
# On Windows, when not installed as a global assembly, the ROCM bin dir
33+
# must be on the PATH in order to find DLLs.
34+
set(TEST_PATH "${CMAKE_HIP_COMPILER_ROCM_ROOT}/bin")
35+
string(APPEND TEST_PATH ";")
36+
string(APPEND TEST_PATH "$ENV{PATH}")
37+
message(STATUS "Using test path: ${TEST_PATH}")
38+
endif()
2639

2740
if(THEROCK_ENABLE_HIP)
2841
# TODO: Don't require HIP_PLATFORM https://github.com/ROCm/TheRock/issues/68
@@ -97,8 +110,29 @@ if(THEROCK_ENABLE_HIP)
97110
hip-host-test.cpp
98111
)
99112
target_link_libraries(hip-host-test PRIVATE hip::host)
100-
add_test(NAME hip-host-test COMMAND hip-host-test)
113+
set(_DEVICE_ORDINAL)
114+
if(ENABLE_DEVICE_TEST)
115+
set(_DEVICE_ORDINAL 0)
116+
endif()
117+
add_test(NAME hip-host-test
118+
COMMAND hip-host-test ${_DEVICE_ORDINAL}
119+
)
120+
if(TEST_PATH)
121+
set_tests_properties(
122+
hip-host-test
123+
PROPERTIES ENVIRONMENT "PATH=${TEST_PATH}"
124+
)
125+
endif()
101126

102-
add_library(sample_kernel sample_kernel.hip)
127+
add_executable(sample_kernel sample_kernel.hip)
103128
set_source_files_properties(sample_kernel PROPERTIES LANGUAGE HIP)
129+
if(ENABLE_DEVICE_TEST)
130+
add_test(NAME sample-kernel-test COMMAND sample_kernel)
131+
if(TEST_PATH)
132+
set_tests_properties(
133+
sample-kernel-test
134+
PROPERTIES ENVIRONMENT "PATH=${TEST_PATH}"
135+
)
136+
endif()
137+
endif()
104138
endif()
Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1+
#include <cstdint>
2+
#include <string>
3+
14
#include <hip/hip_runtime_api.h>
25

36
#include <iostream>
47

58
int main(int argc, char **argv) {
9+
int device_ordinal = -1;
10+
if (argc > 1) {
11+
try {
12+
device_ordinal = std::stoi(argv[1]);
13+
} catch (std::exception &e) {
14+
std::cerr << "could not parse device ordinal from command line: "
15+
<< e.what() << "\n";
16+
return 1;
17+
}
18+
}
19+
620
int runtime_version;
721
auto err = hipRuntimeGetVersion(&runtime_version);
822
if (err != hipSuccess) {
@@ -11,11 +25,41 @@ int main(int argc, char **argv) {
1125
}
1226
std::cout << "HIP runtime version: " << runtime_version << "\n";
1327
err = hipInit(0);
28+
if (device_ordinal < 0) {
29+
// Not testing actual device - just linkage and ability to run at all.
30+
std::cout << "Not testing on GPU device (no device ordinal passed)\n";
31+
return 0;
32+
}
1433
if (err != hipSuccess) {
15-
// Since this is primarily run on CI to verify that linkage works, we
16-
// just ignore any error (this lets us run the test on machines that
17-
// lack a GPU).
1834
std::cerr << "Error initializing HIP: " << err << " (ignored)\n";
35+
return 3;
36+
}
37+
38+
// Get the device.
39+
hipDevice_t device;
40+
err = hipDeviceGet(&device, device_ordinal);
41+
if (err != hipSuccess) {
42+
std::cerr << "Error getting device ordinal " << device_ordinal << "\n";
43+
return 4;
1944
}
45+
46+
// Get device name.
47+
char device_name[80];
48+
err = hipDeviceGetName(device_name, sizeof(device_name) - 1, device);
49+
if (err != hipSuccess) {
50+
std::cerr << "Error getting device name \n";
51+
return 5;
52+
}
53+
std::cout << "Device name: " << device_name << "\n";
54+
55+
// Get device memory.
56+
size_t memory_size;
57+
err = hipDeviceTotalMem(&memory_size, device);
58+
if (err != hipSuccess) {
59+
std::cerr << "Error getting device memory\n";
60+
return 6;
61+
}
62+
std::cout << "Device memory: " << (memory_size / 1024 / 1024) << " MiB\n";
63+
2064
return 0;
2165
}

0 commit comments

Comments
 (0)