From 454d36bf42b309cb2f739ce0c8fc7589b7a92919 Mon Sep 17 00:00:00 2001 From: Nico Trost Date: Mon, 12 Nov 2018 12:12:23 +0100 Subject: [PATCH] more debug output on tests; including git revision and rocsparse version --- CMakeLists.txt | 2 +- clients/common/utility.cpp | 22 +++++++++++++ clients/include/utility.hpp | 4 +++ clients/tests/hipsparse_gtest_main.cpp | 18 ++++++++++- cmake/Dependencies.cmake | 2 +- library/CMakeLists.txt | 12 +++++-- library/include/hipsparse-version.h.in | 1 + library/include/hipsparse.h | 2 ++ library/src/hcc_detail/hipsparse.cpp | 41 ++++++++++++++++++++++- library/src/nvcc_detail/hipsparse.cpp | 45 +++++++++++++++++++++++++- 10 files changed, 142 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64c34acd..745b1f6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,7 @@ option(BUILD_VERBOSE "Output additional build information" OFF) include(cmake/Dependencies.cmake) # Setup version -rocm_setup_version(VERSION 0.1.3.2 NO_GIT_TAG_VERSION) +rocm_setup_version(VERSION 0.1.4.0 NO_GIT_TAG_VERSION) set(hipsparse_SOVERSION 0) # hipSPARSE library diff --git a/clients/common/utility.cpp b/clients/common/utility.cpp index 0ead1716..c3a5aaa5 100644 --- a/clients/common/utility.cpp +++ b/clients/common/utility.cpp @@ -32,6 +32,28 @@ extern "C" { #endif +/* ============================================================================================ */ +/* query for hipsparse version and git commit SHA-1. */ +void query_version(char* version) +{ + hipsparseHandle_t handle; + hipsparseCreate(&handle); + + int ver; + hipsparseGetVersion(handle, &ver); + + char rev[128]; + hipsparseGetGitRevision(handle, rev); + + sprintf(version, "v%d.%d.%d-%s", + ver / 100000, + ver / 100 % 1000, + ver % 100, + rev); + + hipsparseDestroy(handle); +} + /* ============================================================================================ */ /* device query and print out their ID and name; return number of compute-capable devices. */ int query_device_property() diff --git a/clients/include/utility.hpp b/clients/include/utility.hpp index cee3b39c..ff9cbb5c 100644 --- a/clients/include/utility.hpp +++ b/clients/include/utility.hpp @@ -889,6 +889,10 @@ int usolve(int m, extern "C" { #endif +/* ============================================================================================ */ +/* query for hipsparse version and git commit SHA-1. */ +void query_version(char* version); + /* ============================================================================================ */ /* device query and print out their ID and name */ int query_device_property(); diff --git a/clients/tests/hipsparse_gtest_main.cpp b/clients/tests/hipsparse_gtest_main.cpp index 43d5ff0a..e05ecb55 100644 --- a/clients/tests/hipsparse_gtest_main.cpp +++ b/clients/tests/hipsparse_gtest_main.cpp @@ -32,8 +32,24 @@ int main(int argc, char** argv) { + // Print version + char version[256]; + query_version(version); + + printf("hipSPARSE version: %s\n", version); + + // Get device id from command line + int device_id = 0; + + for(int i = 1; i < argc; ++i) + { + if(strcmp(argv[i], "--device") == 0 && argc > i + 1) + { + device_id = atoi(argv[i + 1]); + } + } + // Device Query - int device_id = 0; int device_count = query_device_property(); if(device_count <= device_id) diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 3e617432..1a8cf4da 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -34,7 +34,7 @@ find_package(HIP 1.5.18353 REQUIRED CONFIG PATHS /opt/rocm) # ROCm 1.9 # Either rocSPARSE or cuSPARSE is required if(NOT BUILD_CUDA) - find_package(rocsparse 0.1.3 REQUIRED) # ROCm 1.9 + find_package(rocsparse 0.1.4 REQUIRED) # ROCm 1.9 else() find_package(CUDA REQUIRED) endif() diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 2a92ef43..3da43205 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -26,6 +26,14 @@ if(BUILD_VERBOSE) include(../cmake/Verbose.cmake) endif() +# Get full git commit SHA-1 +set(GIT_COMMAND ${GIT_EXECUTABLE} rev-parse -q HEAD) +execute_process(COMMAND ${GIT_COMMAND} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE hipsparse_GIT_REVISION + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET) + # Configure a header file to pass the hipSPARSE version configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/hipsparse-version.h.in" "${PROJECT_BINARY_DIR}/include/hipsparse-version.h" @@ -110,8 +118,8 @@ rocm_install_symlink_subdir(hipsparse) # Package specific CPACK vars if(NOT BUILD_CUDA) - set(CPACK_DEBIAN_PACKAGE_DEPENDS "hip_hcc (>= 1.5.18353), rocsparse (>= 0.1.3)") - set(CPACK_RPM_PACKAGE_REQUIRES "hip_hcc >= 1.5.18353, rocsparse >= 0.1.3") + set(CPACK_DEBIAN_PACKAGE_DEPENDS "hip_hcc (>= 1.5.18353), rocsparse (>= 0.1.4)") + set(CPACK_RPM_PACKAGE_REQUIRES "hip_hcc >= 1.5.18353, rocsparse >= 0.1.4") endif() set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE.md") diff --git a/library/include/hipsparse-version.h.in b/library/include/hipsparse-version.h.in index 94c55a00..179ec898 100644 --- a/library/include/hipsparse-version.h.in +++ b/library/include/hipsparse-version.h.in @@ -34,6 +34,7 @@ #define hipsparseVersionMinor @hipsparse_VERSION_MINOR@ #define hipsparseVersionPatch @hipsparse_VERSION_PATCH@ #define hipsparseVersionTweak @hipsparse_VERSION_TWEAK@ +#define hipsparseGitRevision "@hipsparse_GIT_REVISION@" // clang-format on #endif // _HIPSPARSE_VERSION_H_ diff --git a/library/include/hipsparse.h b/library/include/hipsparse.h index 6daa5397..15a8c092 100644 --- a/library/include/hipsparse.h +++ b/library/include/hipsparse.h @@ -138,6 +138,8 @@ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroy(hipsparseHandle_t handle); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseGetVersion(hipsparseHandle_t handle, int* version); +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseGetGitRevision(hipsparseHandle_t handle, char* rev); // HIPSPARSE_EXPORT // hipsparseStatus_t hipsparseGetProperty(libraryPropertyType type, // int *value); diff --git a/library/src/hcc_detail/hipsparse.cpp b/library/src/hcc_detail/hipsparse.cpp index dae340c9..db40a907 100644 --- a/library/src/hcc_detail/hipsparse.cpp +++ b/library/src/hcc_detail/hipsparse.cpp @@ -24,6 +24,7 @@ #include "hipsparse.h" #include +#include #include #ifdef __cplusplus @@ -279,7 +280,45 @@ hipsparseStatus_t hipsparseDestroy(hipsparseHandle_t handle) hipsparseStatus_t hipsparseGetVersion(hipsparseHandle_t handle, int* version) { - return rocSPARSEStatusToHIPStatus(rocsparse_get_version((rocsparse_handle)handle, version)); + if(handle == nullptr) + { + return HIPSPARSE_STATUS_NOT_INITIALIZED; + } + + *version = hipsparseVersionMajor * 100000 + hipsparseVersionMinor * 100 + hipsparseVersionPatch; + + return HIPSPARSE_STATUS_SUCCESS; +} + +hipsparseStatus_t hipsparseGetGitRevision(hipsparseHandle_t handle, char* rev) +{ + // Get hipSPARSE revision + if(handle == nullptr) + { + return HIPSPARSE_STATUS_NOT_INITIALIZED; + } + + char hipsparse_rev[64]; + strcpy(hipsparse_rev, hipsparseGitRevision); + + // Get rocSPARSE revision + char rocsparse_rev[64]; + RETURN_IF_ROCSPARSE_ERROR(rocsparse_get_git_rev((rocsparse_handle)handle, rocsparse_rev)); + + // Get rocSPARSE version + int rocsparse_ver; + RETURN_IF_ROCSPARSE_ERROR(rocsparse_get_version((rocsparse_handle)handle, &rocsparse_ver)); + + // Combine + sprintf(rev, + "%s (rocSPARSE %d.%d.%d-%s)", + hipsparse_rev, + rocsparse_ver / 100000, + rocsparse_ver / 100 % 1000, + rocsparse_ver % 100, + rocsparse_rev); + + return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSetStream(hipsparseHandle_t handle, hipStream_t streamId) diff --git a/library/src/nvcc_detail/hipsparse.cpp b/library/src/nvcc_detail/hipsparse.cpp index 9e112f3c..de025a7d 100644 --- a/library/src/nvcc_detail/hipsparse.cpp +++ b/library/src/nvcc_detail/hipsparse.cpp @@ -23,6 +23,7 @@ #include "hipsparse.h" +#include #include #include #include @@ -31,6 +32,15 @@ extern "C" { #endif +#define RETURN_IF_CUSPARSE_ERROR(INPUT_STATUS_FOR_CHECK) \ + { \ + cusparseStatus_t TMP_STATUS_FOR_CHECK = INPUT_STATUS_FOR_CHECK; \ + if(TMP_STATUS_FOR_CHECK != CUSPARSE_STATUS_SUCCESS) \ + { \ + return hipCUSPARSEStatusToHIPStatus(TMP_STATUS_FOR_CHECK); \ + } \ + } + hipsparseStatus_t hipCUSPARSEStatusToHIPStatus(cusparseStatus_t cuStatus) { switch(cuStatus) @@ -249,7 +259,40 @@ hipsparseStatus_t hipsparseDestroy(hipsparseHandle_t handle) hipsparseStatus_t hipsparseGetVersion(hipsparseHandle_t handle, int* version) { - return hipCUSPARSEStatusToHIPStatus(cusparseGetVersion((cusparseHandle_t)handle, version)); + if(handle == nullptr) + { + return HIPSPARSE_STATUS_NOT_INITIALIZED; + } + + *version = hipsparseVersionMajor * 100000 + hipsparseVersionMinor * 100 + hipsparseVersionPatch; + + return HIPSPARSE_STATUS_SUCCESS; +} + +hipsparseStatus_t hipsparseGetGitRevision(hipsparseHandle_t handle, char* rev) +{ + // Get hipSPARSE revision + if(handle == nullptr) + { + return HIPSPARSE_STATUS_NOT_INITIALIZED; + } + + char hipsparse_rev[64]; + strcpy(hipsparse_rev, hipsparseGitRevision); + + // Get cuSPARSE version + int cusparse_ver; + RETURN_IF_CUSPARSE_ERROR(cusparseGetVersion((cusparseHandle_t)handle, &cusparse_ver)); + + // Combine + sprintf(rev, + "%s (cuSPARSE %d.%d.%d)", + hipsparse_rev, + cusparse_ver / 100000, + cusparse_ver / 100 % 1000, + cusparse_ver % 100); + + return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSetStream(hipsparseHandle_t handle, hipStream_t streamId)