-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
209 additions
and
89 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// Created by sachetto on 28/11/24. | ||
// | ||
|
||
#include "accel_utils.h" | ||
#include "gpu_utils.h" | ||
|
||
#ifdef COMPILE_CUDA | ||
#include <cublas_v2.h> | ||
#include <cusparse_v2.h> | ||
#endif | ||
|
||
extern "C" void malloc_device(void **ptr, size_t n) { | ||
|
||
#ifdef COMPILE_CUDA | ||
check_cuda_error(cudaMalloc(ptr, n)); | ||
#elif defined(COMPILE_SYCL) | ||
DPCT_CHECK_ERROR(ptr = sycl::malloc_device(n, dpct::get_in_order_queue())); | ||
#endif | ||
|
||
} | ||
|
||
extern "C" void free_device(void *ptr) { | ||
#ifdef COMPILE_CUDA | ||
check_cuda_error(cudaFree(ptr)); | ||
#elif defined(COMPILE_SYCL) | ||
DPCT_CHECK_ERROR(dpct::dpct_free(persistent_data->d_col, dpct::get_in_order_queue())); | ||
#endif | ||
} | ||
|
||
extern "C" void memcpy_device(void *dest, const void *src, size_t n, copy_direction kind) { | ||
|
||
if(kind == HOST_TO_DEVICE) { | ||
#ifdef COMPILE_CUDA | ||
check_cuda_error(cudaMemcpy(dest, src, n, cudaMemcpyHostToDevice)); | ||
#elif defined(COMPILE_SYCL) | ||
sycl::device dev_ct1; | ||
sycl::queue q_ct1(dev_ct1, sycl::property_list{sycl::property::queue::in_order()}); | ||
q_ct1.memcpy(dest, src, n).wait(); | ||
#endif | ||
} else if(kind == DEVICE_TO_HOST) { | ||
#ifdef COMPILE_CUDA | ||
check_cuda_error(cudaMemcpy(dest, src, n, cudaMemcpyDeviceToHost)); | ||
#elif defined(COMPILE_SYCL) | ||
dpct::device_ext &dev_ct1 = dpct::get_current_device(); | ||
sycl::queue &q_ct1 = dev_ct1.default_queue(); | ||
q_ct1.memcpy(dest, src, n).wait(); | ||
#endif | ||
} | ||
} | ||
|
||
extern "C" void create_sparse_handle(void *handle) { | ||
#ifdef COMPILE_CUDA | ||
check_cublas_error(cusparseCreate((cusparseHandle_t *)handle)); | ||
#elif defined(COMPILE_SYCL) | ||
DPCT_CHECK_ERROR(handle = new dpct::sparse::descriptor(); | ||
#endif | ||
} | ||
|
||
extern "C" void create_blas_handle(void *handle) { | ||
#ifdef COMPILE_CUDA | ||
check_cublas_error(cublasCreate((cublasHandle_t *)handle)); | ||
#elif defined(COMPILE_SYCL) | ||
DPCT_CHECK_ERROR(handle = new dpct::blas::descriptor(); | ||
#endif | ||
} | ||
|
||
extern "C" void sparse_create_scr(void *mat, int64_t rows, int64_t cols, int64_t nnz, | ||
void* csrRowOffsets, | ||
void* csrColInd, | ||
void* csrValues, | ||
cusparseIndexType_t csrRowOffsetsType, | ||
cusparseIndexType_t csrColIndType, | ||
cusparseIndexBase_t idxBase, | ||
cudaDataType valueType) { | ||
#ifdef COMPILE_CUDA | ||
check_cuda_error(cusparseCreateCsr(&(PSEUDO_BIDOMAIN_DATA->matA), N, N, nz, PSEUDO_BIDOMAIN_DATA->d_row, PSEUDO_BIDOMAIN_DATA->d_col, | ||
PSEUDO_BIDOMAIN_DATA->d_val, CUSPARSE_INDEX_32I, CUSPARSE_INDEX_32I, CUSPARSE_INDEX_BASE_ZERO, CUBLAS_SIZE)); | ||
#elif defined(COMPILE_SYCL) | ||
DPCT_CHECK_ERROR(mat = new dpct::sparse::sparse_matrix_desc( | ||
rows, cols, nnz, csrRowOffsets,csrColInd, csrValues, dpct::library_data_t::real_int32, | ||
dpct::library_data_t::real_int32, oneapi::mkl::index_base::zero, CUBLAS_SIZE, dpct::sparse::matrix_format::csr)); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// Created by sachetto on 28/11/24. | ||
// | ||
|
||
#ifndef ACCEL_UTILS_H | ||
#define ACCEL_UTILS_H | ||
|
||
#include <stddef.h> | ||
|
||
typedef enum { | ||
HOST_TO_DEVICE, | ||
DEVICE_TO_HOST, | ||
} copy_direction; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
void malloc_device(void **ptr, size_t n); | ||
void free_device(void *ptr); | ||
void memcpy_device(void *dest, const void *src, size_t n, copy_direction kind); | ||
void create_sparse_handle(void *handle); | ||
void create_blas_handle(void *handle); | ||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif //ACCEL_UTILS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
GPU_UTILS_SOURCE_FILES="gpu_utils.c" | ||
GPU_UTILS_HEADER_FILES="gpu_utils.h" | ||
GPU_UTILS_SOURCE_FILES="gpu_utils.c accel_utils.cpp" | ||
GPU_UTILS_HEADER_FILES="gpu_utils.h accel_utils.h" | ||
|
||
if [ -n "$CUDA_FOUND" ]; then | ||
GPU_UTILS_EXTRA_LIB_PATH=$CUDA_LIBRARY_PATH | ||
GPU_UTILS_DYNAMIC_LIBS="c cudart" | ||
GPU_UTILS_DYNAMIC_LIBS="c cudart cublas cusparse" | ||
GPU_UTILS_SOURCE_FILES="$GPU_UTILS_SOURCE_FILES gpu_utils.cu" | ||
fi | ||
|
||
|
||
COMPILE_SHARED_LIB "gpu_utils" "$GPU_UTILS_SOURCE_FILES" "$GPU_UTILS_HEADER_FILES" "" "$GPU_UTILS_DYNAMIC_LIBS" "$GPU_UTILS_EXTRA_LIB_PATH" "" "$CUDA_FOUND" | ||
#COMPILE_STATIC_LIB "gpu_utils" "$GPU_UTILS_SOURCE_FILES" "$GPU_UTILS_HEADER_FILES" | ||
COMPILE_SHARED_LIB "gpu_utils" "$GPU_UTILS_SOURCE_FILES" "$GPU_UTILS_HEADER_FILES" "" "$GPU_UTILS_DYNAMIC_LIBS" "$GPU_UTILS_EXTRA_LIB_PATH" "" "$CUDA_FOUND" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters