Skip to content

Commit

Permalink
Merge pull request #22 from ntrost57/develop
Browse files Browse the repository at this point in the history
more debug output on tests; including git revision and rocsparse version
  • Loading branch information
ntrost57 authored Nov 12, 2018
2 parents 0c3638e + 454d36b commit 9f22f5c
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions clients/common/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions clients/include/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 17 additions & 1 deletion clients/tests/hipsparse_gtest_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 10 additions & 2 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")

Expand Down
1 change: 1 addition & 0 deletions library/include/hipsparse-version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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_
2 changes: 2 additions & 0 deletions library/include/hipsparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
41 changes: 40 additions & 1 deletion library/src/hcc_detail/hipsparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "hipsparse.h"

#include <rocsparse.h>
#include <stdio.h>
#include <hip/hip_runtime_api.h>

#ifdef __cplusplus
Expand Down Expand Up @@ -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)
Expand Down
45 changes: 44 additions & 1 deletion library/src/nvcc_detail/hipsparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "hipsparse.h"

#include <stdio.h>
#include <hip/hip_runtime_api.h>
#include <cuda_runtime_api.h>
#include <cusparse_v2.h>
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9f22f5c

Please sign in to comment.