Skip to content

Commit

Permalink
Merge branch 'master' into feature/hip
Browse files Browse the repository at this point in the history
Signed-off-by: Aurelien Bouteiller <bouteill@icl.utk.edu>
  • Loading branch information
abouteiller committed Oct 19, 2023
2 parents f89a541 + 749c912 commit 9558c09
Show file tree
Hide file tree
Showing 27 changed files with 1,434 additions and 706 deletions.
2 changes: 1 addition & 1 deletion parsec
6 changes: 5 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ set(EXTRA_SOURCES
utils/dplasma_arena_datatype.c
utils/dplasma_lapack_adtt.c
utils/dplasma_info.c
cuda/lapack_cuda_stage_in.c
)
if( NOT DPLASMA_HAVE_COMPLEX_H )
list(APPEND EXTRA_SOURCES complex.c)
endif()
if( DPLASMA_HAVE_CUDA )
list(APPEND EXTRA_SOURCES dplasmaaux_cuda.c cuda/lapack_cuda_stage_in.c)
endif()
if( DPLASMA_HAVE_HIP )
list(APPEND EXTRA_SOURCES dplasmaaux_hip.c)
FILE(GLOB cuda_sources cuda/[^\\.]*.[ch])
find_package(Perl REQUIRED)
find_program(HIPIFY_PERL_COMMAND NAMES hipify-perl HINTS ${HIP_BIN_INSTALL_DIR} REQUIRED)
Expand Down Expand Up @@ -232,6 +235,7 @@ target_ptg_sources(dplasma PRIVATE
${generated_jdf})

Add_Subdirectory(cores)
Add_Subdirectory(dtd_wrappers)

target_include_directories(dplasma
INTERFACE
Expand Down
135 changes: 1 addition & 134 deletions src/dplasmaaux.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2021 The University of Tennessee and The University
* Copyright (c) 2011-2023 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2013 Inria. All rights reserved.
Expand Down Expand Up @@ -110,136 +110,3 @@ dplasma_aux_getGEMMLookahead( parsec_tiled_matrix_t *A )
}
}

#if defined(DPLASMA_HAVE_CUDA)
#include <cublas_v2.h>
#include <cusolverDn.h>

/* Unfortunately, CUBLAS does not provide a error to string function */
static char *dplasma_cublas_error_to_string(cublasStatus_t cublas_status)
{
switch(cublas_status)
{
case CUBLAS_STATUS_SUCCESS: return "CUBLAS_STATUS_SUCCESS";
case CUBLAS_STATUS_NOT_INITIALIZED: return "CUBLAS_STATUS_NOT_INITIALIZED";
case CUBLAS_STATUS_ALLOC_FAILED: return "CUBLAS_STATUS_ALLOC_FAILED";
case CUBLAS_STATUS_INVALID_VALUE: return "CUBLAS_STATUS_INVALID_VALUE";
case CUBLAS_STATUS_ARCH_MISMATCH: return "CUBLAS_STATUS_ARCH_MISMATCH";
case CUBLAS_STATUS_MAPPING_ERROR: return "CUBLAS_STATUS_MAPPING_ERROR";
case CUBLAS_STATUS_EXECUTION_FAILED: return "CUBLAS_STATUS_EXECUTION_FAILED";
case CUBLAS_STATUS_INTERNAL_ERROR: return "CUBLAS_STATUS_INTERNAL_ERROR";
default: return "unknown CUBLAS error";
}
}

/* Unfortunately, cuSolver does not provide a error to string function */
static char *dplasma_cusolver_error_to_string(cusolverStatus_t cusolver_status)
{
switch(cusolver_status) {
case CUSOLVER_STATUS_SUCCESS: return "CUSOLVER_STATUS_SUCCESS";
case CUSOLVER_STATUS_NOT_INITIALIZED: return "CUSOLVER_STATUS_NOT_INITIALIZED";
case CUSOLVER_STATUS_ALLOC_FAILED: return "CUSOLVER_STATUS_ALLOC_FAILED";
case CUSOLVER_STATUS_INVALID_VALUE: return "CUSOLVER_STATUS_INVALID_VALUE";
case CUSOLVER_STATUS_ARCH_MISMATCH: return "CUSOLVER_STATUS_ARCH_MISMATCH";
case CUSOLVER_STATUS_EXECUTION_FAILED: return "CUSOLVER_STATUS_EXECUTION_FAILED";
case CUSOLVER_STATUS_INTERNAL_ERROR: return "CUSOLVER_STATUS_INTERNAL_ERROR";
case CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED: return "CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED";
default: return "unknown cusolver error";
}
}

void *dplasma_create_cuda_handles(void *obj, void *_n)
{
parsec_cuda_exec_stream_t *cuda_stream = (parsec_cuda_exec_stream_t *)obj;
dplasma_cuda_handles_t *new;
cublasHandle_t cublas_handle;
cublasStatus_t cublas_status;

(void)_n;

/* No need to call cudaSetDevice, as this has been done by PaRSEC before calling the task body */
cublas_status = cublasCreate(&cublas_handle);
if(CUBLAS_STATUS_SUCCESS != cublas_status) {
if( CUBLAS_STATUS_ALLOC_FAILED == cublas_status ) {
parsec_show_help("help-dplasma.txt", "gpu_alloc_failed", 1, "CUBLAS");
}
parsec_fatal("Unable to create CUBLAS Handle: %s",
dplasma_cublas_error_to_string(cublas_status));
return NULL;
}
cublas_status = cublasSetStream(cublas_handle, cuda_stream->cuda_stream);
assert(CUBLAS_STATUS_SUCCESS == cublas_status);

cusolverDnHandle_t cusolver_handle;
cusolverStatus_t cusolver_status;
cusolver_status = cusolverDnCreate(&cusolver_handle);
if(CUSOLVER_STATUS_SUCCESS != cusolver_status) {
cublasDestroy(cublas_handle);
if( CUSOLVER_STATUS_ALLOC_FAILED == cusolver_status ) {
parsec_show_help("help-dplasma.txt", "gpu_alloc_failed", 1, "cusolver");
}
parsec_fatal("Unable to create a cuSolver handle: %s",
dplasma_cusolver_error_to_string(cusolver_status));
return NULL;
}
cusolver_status = cusolverDnSetStream(cusolver_handle, cuda_stream->cuda_stream);
assert(CUSOLVER_STATUS_SUCCESS == cusolver_status);

new = malloc(sizeof(dplasma_cuda_handles_t));
new->cublas_handle = cublas_handle;
new->cusolverDn_handle = cusolver_handle;

return new;
}

#endif

#if defined(DPLASMA_HAVE_HIP)
#include <hipblas.h>

/* Unfortunately, HIPBLAS does not provide a error to string function */
static char *dplasma_hipblas_error_to_string(hipblasStatus_t hipblas_status)
{
switch(hipblas_status)
{
case HIPBLAS_STATUS_SUCCESS: return "HIPBLAS_STATUS_SUCCESS";
case HIPBLAS_STATUS_NOT_INITIALIZED: return "HIPBLAS_STATUS_NOT_INITIALIZED";
case HIPBLAS_STATUS_ALLOC_FAILED: return "HIPBLAS_STATUS_ALLOC_FAILED";
case HIPBLAS_STATUS_INVALID_VALUE: return "HIPBLAS_STATUS_INVALID_VALUE";
case HIPBLAS_STATUS_ARCH_MISMATCH: return "HIPBLAS_STATUS_ARCH_MISMATCH";
case HIPBLAS_STATUS_MAPPING_ERROR: return "HIPBLAS_STATUS_MAPPING_ERROR";
case HIPBLAS_STATUS_EXECUTION_FAILED: return "HIPBLAS_STATUS_EXECUTION_FAILED";
case HIPBLAS_STATUS_INTERNAL_ERROR: return "HIPBLAS_STATUS_INTERNAL_ERROR";
default: return "unknown HIPBLAS error";
}
}


void *dplasma_create_hip_handles(void *obj, void *_n)
{
parsec_hip_exec_stream_t *stream = (parsec_hip_exec_stream_t *)obj;
dplasma_hip_handles_t *new;
hipblasHandle_t hipblas_handle;
hipblasStatus_t hipblas_status;

(void)_n;


/* No need to call hipSetDevice, as this has been done by PaRSEC before calling the task body */
hipblas_status = hipblasCreate(&hipblas_handle);
if(HIPBLAS_STATUS_SUCCESS != hipblas_status) {
if( HIPBLAS_STATUS_ALLOC_FAILED == hipblas_status) {
parsec_show_help("help-dplasma.txt", "gpu_alloc_failed", 1, "HIPBLAS");
}
parsec_fatal("Unable to create HIPBLAS Handle: %s", dplasma_hipblas_error_to_string(hipblas_status));
return NULL;
}
hipblas_status = hipblasSetStream(hipblas_handle, stream->hip_stream);
assert(HIPBLAS_STATUS_SUCCESS == hipblas_status);

new = malloc(sizeof(dplasma_hip_handles_t));
new->hipblas_handle = hipblas_handle;

return new;
}
#endif

42 changes: 2 additions & 40 deletions src/dplasmaaux.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,45 +109,7 @@ extern void *dplasma_pcomm;
#define dplasma_error(__func, __msg) do { fprintf(stderr, "%s: %s\n", (__func), (__msg)); } while(0)
#endif /* defined(DPLASMA_DEBUG) */

#if defined(DPLASMA_HAVE_CUDA)
#include <cublas.h>
#include "parsec/mca/device/cuda/device_cuda.h"
typedef struct {
cublasHandle_t cublas_handle;
void * cusolverDn_handle;
} dplasma_cuda_handles_t;
void *dplasma_create_cuda_handles(void *obj, void *user);
#endif

#if defined(DPLASMA_HAVE_HIP)
#include <hipblas.h>
#include "parsec/mca/device/hip/device_hip.h"

#define DPLASMA_ROCBLAS_CHECK_ERROR(STR, ERROR, CODE) \
do { \
rocblas_status __error = (rocblas_status) (ERROR); \
if(rocblas_status_success != __error) { \
parsec_warning( "%s:%d %s%s", __FILE__, __LINE__, \
(STR), rocblas_status_to_string(__error)); \
CODE; \
} \
} while(0)

/* For some reason the error values are not the same... */
#define DPLASMA_HIPBLAS_CHECK_ERROR(STR, ERROR, CODE) \
do { \
hipblasStatus_t __error = (hipblasStatus_t) (ERROR); \
if(HIPBLAS_STATUS_SUCCESS != __error) { \
parsec_warning( "%s:%d %s%s", __FILE__, __LINE__, \
(STR), hipblasStatusToString(__error)); \
CODE; \
} \
} while(0)

typedef struct {
hipblasHandle_t hipblas_handle;
} dplasma_hip_handles_t;
void *dplasma_create_hip_handles(void *obj, void *user);
#endif /* defined(DPLASMA_HAVE_HIP) */
#include "dplasmaaux_cuda.h"
#include "dplasmaaux_hip.h"

#endif /* _DPLASMAAUX_H_INCLUDED */
99 changes: 99 additions & 0 deletions src/dplasmaaux_cuda.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2023- The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* $COPYRIGHT
*
*/
#include "dplasma/config.h"
#include "parsec/utils/zone_malloc.h"
#include "parsec/utils/show_help.h"
#include <cublas_v2.h>
#include "dplasmaaux_cuda.h"
#include "potrf_gpu_workspaces.h"

/*
* Global info ID's for cublas handles and workspaces
* Should be initialized in the tests
* with the return of parsec_info_register
* or parsec_info_lookup
*/
parsec_info_id_t CuHI = -1;
parsec_info_id_t WoSI = -1;

/* Unfortunately, CUBLAS does not provide a error to string function */
char *dplasma_cublas_error_to_string(cublasStatus_t cublas_status)
{
switch(cublas_status)
{
case CUBLAS_STATUS_SUCCESS: return "CUBLAS_STATUS_SUCCESS";
case CUBLAS_STATUS_NOT_INITIALIZED: return "CUBLAS_STATUS_NOT_INITIALIZED";
case CUBLAS_STATUS_ALLOC_FAILED: return "CUBLAS_STATUS_ALLOC_FAILED";
case CUBLAS_STATUS_INVALID_VALUE: return "CUBLAS_STATUS_INVALID_VALUE";
case CUBLAS_STATUS_ARCH_MISMATCH: return "CUBLAS_STATUS_ARCH_MISMATCH";
case CUBLAS_STATUS_MAPPING_ERROR: return "CUBLAS_STATUS_MAPPING_ERROR";
case CUBLAS_STATUS_EXECUTION_FAILED: return "CUBLAS_STATUS_EXECUTION_FAILED";
case CUBLAS_STATUS_INTERNAL_ERROR: return "CUBLAS_STATUS_INTERNAL_ERROR";
default: return "unknown CUBLAS error";
}
}

/* Unfortunately, cuSolver does not provide a error to string function */
char *dplasma_cusolver_error_to_string(cusolverStatus_t cusolver_status)
{
switch(cusolver_status) {
case CUSOLVER_STATUS_SUCCESS: return "CUSOLVER_STATUS_SUCCESS";
case CUSOLVER_STATUS_NOT_INITIALIZED: return "CUSOLVER_STATUS_NOT_INITIALIZED";
case CUSOLVER_STATUS_ALLOC_FAILED: return "CUSOLVER_STATUS_ALLOC_FAILED";
case CUSOLVER_STATUS_INVALID_VALUE: return "CUSOLVER_STATUS_INVALID_VALUE";
case CUSOLVER_STATUS_ARCH_MISMATCH: return "CUSOLVER_STATUS_ARCH_MISMATCH";
case CUSOLVER_STATUS_EXECUTION_FAILED: return "CUSOLVER_STATUS_EXECUTION_FAILED";
case CUSOLVER_STATUS_INTERNAL_ERROR: return "CUSOLVER_STATUS_INTERNAL_ERROR";
case CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED: return "CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED";
default: return "unknown cusolver error";
}
}

void *dplasma_create_cuda_handles(void *obj, void *_n)
{
parsec_cuda_exec_stream_t *cuda_stream = (parsec_cuda_exec_stream_t *)obj;
dplasma_cuda_handles_t *new;
cublasHandle_t cublas_handle;
cublasStatus_t cublas_status;

(void)_n;

/* No need to call cudaSetDevice, as this has been done by PaRSEC before calling the task body */
cublas_status = cublasCreate(&cublas_handle);
if(CUBLAS_STATUS_SUCCESS != cublas_status) {
if( CUBLAS_STATUS_ALLOC_FAILED == cublas_status ) {
parsec_show_help("help-dplasma.txt", "cu*_alloc_failed", 1, "CUBLAS");
}
parsec_fatal("Unable to create CUBLAS Handle: %s",
dplasma_cublas_error_to_string(cublas_status));
return NULL;
}
cublas_status = cublasSetStream(cublas_handle, cuda_stream->cuda_stream);
assert(CUBLAS_STATUS_SUCCESS == cublas_status);

cusolverDnHandle_t cusolver_handle;
cusolverStatus_t cusolver_status;
cusolver_status = cusolverDnCreate(&cusolver_handle);
if(CUSOLVER_STATUS_SUCCESS != cusolver_status) {
cublasDestroy(cublas_handle);
if( CUSOLVER_STATUS_ALLOC_FAILED == cusolver_status ) {
parsec_show_help("help-dplasma.txt", "cu*_alloc_failed", 1, "cusolver");
}
parsec_fatal("Unable to create a cuSolver handle: %s",
dplasma_cusolver_error_to_string(cusolver_status));
return NULL;
}
cusolver_status = cusolverDnSetStream(cusolver_handle, cuda_stream->cuda_stream);
assert(CUSOLVER_STATUS_SUCCESS == cusolver_status);

new = malloc(sizeof(dplasma_cuda_handles_t));
new->cublas_handle = cublas_handle;
new->cusolverDn_handle = cusolver_handle;

return new;
}
Loading

0 comments on commit 9558c09

Please sign in to comment.