Adding optional hip test (#34907)
* Adding optional hip test * Modifications to run every samples test * Skipping test directories without a Makefile * fix styling and cleaning code * fix styling and changed method of itterating through sample folders * changed to new syntax for standalone tests * Updates for changes in syntax
This commit is contained in:
parent
a8301709a8
commit
c1b084d754
@ -0,0 +1,55 @@
|
|||||||
|
diff --git a/samples/2_Cookbook/15_static_library/device_functions/hipMain2.cpp b/samples/2_Cookbook/15_static_library/device_functions/hipMain2.cpp
|
||||||
|
index a3c3f8f..fafbf5a 100644
|
||||||
|
--- a/samples/2_Cookbook/15_static_library/device_functions/hipMain2.cpp
|
||||||
|
+++ b/samples/2_Cookbook/15_static_library/device_functions/hipMain2.cpp
|
||||||
|
@@ -23,8 +23,15 @@
|
||||||
|
#include <hip/hip_runtime.h>
|
||||||
|
#include <hip/hip_runtime_api.h>
|
||||||
|
#include <iostream>
|
||||||
|
+#include <stdexcept>
|
||||||
|
|
||||||
|
-#define HIP_ASSERT(status) assert(status == hipSuccess)
|
||||||
|
+#define HIP_ASSERT(status) \
|
||||||
|
+ { \
|
||||||
|
+ if ((status != hipSuccess)) { \
|
||||||
|
+ std::cerr << "Failed in: " << __LINE__ << " on hip call: " #status << std::endl; \
|
||||||
|
+ throw std::runtime_error("generic failure"); \
|
||||||
|
+ } \
|
||||||
|
+ }
|
||||||
|
#define LEN 512
|
||||||
|
|
||||||
|
extern __device__ int square_me(int);
|
||||||
|
diff --git a/samples/2_Cookbook/15_static_library/host_functions/CMakeLists.txt b/samples/2_Cookbook/15_static_library/host_functions/CMakeLists.txt
|
||||||
|
index 3c7c306..8404ac5 100644
|
||||||
|
--- a/samples/2_Cookbook/15_static_library/host_functions/CMakeLists.txt
|
||||||
|
+++ b/samples/2_Cookbook/15_static_library/host_functions/CMakeLists.txt
|
||||||
|
@@ -37,7 +37,7 @@ endif()
|
||||||
|
add_library(HipOptLibrary STATIC ${CPP_SOURCES})
|
||||||
|
|
||||||
|
# Set-up the correct flags to generate the static library.
|
||||||
|
-target_link_libraries(HipOptLibrary PRIVATE --emit-static-lib)
|
||||||
|
+target_link_options(HipOptLibrary PRIVATE --emit-static-lib)
|
||||||
|
target_include_directories(HipOptLibrary PRIVATE /opt/rocm/hsa/include)
|
||||||
|
|
||||||
|
# Create test executable that uses libHipOptLibrary.a
|
||||||
|
diff --git a/samples/2_Cookbook/15_static_library/host_functions/hipOptLibrary.cpp b/samples/2_Cookbook/15_static_library/host_functions/hipOptLibrary.cpp
|
||||||
|
index 68f5418..7e52ce3 100644
|
||||||
|
--- a/samples/2_Cookbook/15_static_library/host_functions/hipOptLibrary.cpp
|
||||||
|
+++ b/samples/2_Cookbook/15_static_library/host_functions/hipOptLibrary.cpp
|
||||||
|
@@ -23,8 +23,15 @@
|
||||||
|
#include <hip/hip_runtime.h>
|
||||||
|
#include <hip/hip_runtime_api.h>
|
||||||
|
#include <iostream>
|
||||||
|
+#include <stdexcept>
|
||||||
|
|
||||||
|
-#define HIP_ASSERT(status) assert(status == hipSuccess)
|
||||||
|
+#define HIP_ASSERT(status) \
|
||||||
|
+ { \
|
||||||
|
+ if ((status != hipSuccess)) { \
|
||||||
|
+ std::cerr << "Failed in: " << __LINE__ << " on hip call: " #status << std::endl; \
|
||||||
|
+ throw std::runtime_error("generic failure"); \
|
||||||
|
+ } \
|
||||||
|
+ }
|
||||||
|
#define LEN 512
|
||||||
|
|
||||||
|
__global__ void copy(uint32_t* A, uint32_t* B) {
|
@ -114,10 +114,12 @@ class Hip(CMakePackage):
|
|||||||
|
|
||||||
depends_on("cuda", when="+cuda")
|
depends_on("cuda", when="+cuda")
|
||||||
|
|
||||||
depends_on("cmake@3.16.8:", type="build", when="@4.5.0:")
|
depends_on("cmake@3.16.8:", type=("build"), when="@4.5.0:")
|
||||||
depends_on("cmake@3.4.3:", type="build")
|
depends_on("cmake@3.4.3:", type="build")
|
||||||
depends_on("perl@5.10:", type=("build", "run"))
|
depends_on("perl@5.10:", type=("build", "run"))
|
||||||
|
|
||||||
|
test_requires_compiler = True
|
||||||
|
|
||||||
with when("+rocm"):
|
with when("+rocm"):
|
||||||
depends_on("gl@4.5:")
|
depends_on("gl@4.5:")
|
||||||
depends_on("py-cppheaderparser", type="build", when="@5.3.3:")
|
depends_on("py-cppheaderparser", type="build", when="@5.3.3:")
|
||||||
@ -330,6 +332,7 @@ class Hip(CMakePackage):
|
|||||||
|
|
||||||
patch("Add_missing_open_cl_header_file_for_4.3.0.patch", when="@4.3.0:4.3.2")
|
patch("Add_missing_open_cl_header_file_for_4.3.0.patch", when="@4.3.0:4.3.2")
|
||||||
patch("0014-hip-test-file-reorg-5.4.0.patch", when="@5.4.0:")
|
patch("0014-hip-test-file-reorg-5.4.0.patch", when="@5.4.0:")
|
||||||
|
patch("0016-hip-sample-fix-hipMalloc-call.patch", when="@5.4.3:")
|
||||||
patch("0014-remove-compiler-rt-linkage-for-host.5.5.0.patch", when="@5.5")
|
patch("0014-remove-compiler-rt-linkage-for-host.5.5.0.patch", when="@5.5")
|
||||||
|
|
||||||
# See https://github.com/ROCm-Developer-Tools/HIP/pull/3206
|
# See https://github.com/ROCm-Developer-Tools/HIP/pull/3206
|
||||||
@ -612,3 +615,68 @@ def cmake_args(self):
|
|||||||
args.append("-DCMAKE_INSTALL_LIBDIR=lib")
|
args.append("-DCMAKE_INSTALL_LIBDIR=lib")
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
test_src_dir = "samples"
|
||||||
|
|
||||||
|
@run_after("install")
|
||||||
|
def cache_test_sources(self):
|
||||||
|
"""Copy the tests source files after the package is installed to an
|
||||||
|
install test subdirectory for use during `spack test run`."""
|
||||||
|
if self.spec.satisfies("@:5.1.0"):
|
||||||
|
return
|
||||||
|
self.cache_extra_test_sources([self.test_src_dir])
|
||||||
|
|
||||||
|
def test_samples(self):
|
||||||
|
# configure, build and run all hip samples
|
||||||
|
if self.spec.satisfies("@:5.1.0"):
|
||||||
|
raise SkipTest("Test is only available for specs after version 5.1.0")
|
||||||
|
test_dir = join_path(self.test_suite.current_test_cache_dir, self.test_src_dir)
|
||||||
|
prefixes = ";".join(
|
||||||
|
[
|
||||||
|
self.spec["hip"].prefix,
|
||||||
|
self.spec["llvm-amdgpu"].prefix,
|
||||||
|
self.spec["comgr"].prefix,
|
||||||
|
self.spec["hsa-rocr-dev"].prefix,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
cc_options = ["-DCMAKE_PREFIX_PATH=" + prefixes, ".."]
|
||||||
|
|
||||||
|
amdclang_path = join_path(self.spec["llvm-amdgpu"].prefix, "bin", "amdclang++")
|
||||||
|
os.environ["CXX"] = amdclang_path
|
||||||
|
os.environ["FC"] = "/usr/bin/gfortran"
|
||||||
|
|
||||||
|
cmake = which(self.spec["cmake"].prefix.bin.cmake)
|
||||||
|
|
||||||
|
for root, dirs, files in os.walk(test_dir):
|
||||||
|
dirs.sort()
|
||||||
|
if "CMakeLists.txt" in files or "Makefile" in files:
|
||||||
|
with working_dir(root, create=True):
|
||||||
|
head, test_name = os.path.split(root)
|
||||||
|
with test_part(
|
||||||
|
self,
|
||||||
|
"test_sample_{0}".format(test_name),
|
||||||
|
purpose="configure, build and run test: {0}".format(test_name),
|
||||||
|
):
|
||||||
|
if "CMakeLists.txt" in files:
|
||||||
|
print("Configuring test " + test_name)
|
||||||
|
os.mkdir("build")
|
||||||
|
os.chdir("build")
|
||||||
|
cmake(*cc_options)
|
||||||
|
|
||||||
|
print("Building test " + test_name)
|
||||||
|
make(parallel=False)
|
||||||
|
# iterate through the files in dir to find the newly built binary
|
||||||
|
for file in os.listdir("."):
|
||||||
|
if (
|
||||||
|
file not in files
|
||||||
|
and os.path.isfile(file)
|
||||||
|
and os.access(file, os.X_OK)
|
||||||
|
and not file.endswith(".o")
|
||||||
|
):
|
||||||
|
print("Executing test binary: " + file)
|
||||||
|
exe = which(file)
|
||||||
|
if file == "hipDispatchEnqueueRateMT":
|
||||||
|
options = ["16", "0"]
|
||||||
|
else:
|
||||||
|
options = []
|
||||||
|
exe(*options)
|
||||||
|
Loading…
Reference in New Issue
Block a user