Skip to content

Commit

Permalink
rename qlat_GPU_ to qacc_
Browse files Browse the repository at this point in the history
  • Loading branch information
jinluchang committed Apr 15, 2024
1 parent c159735 commit 81824d6
Show file tree
Hide file tree
Showing 17 changed files with 255 additions and 255 deletions.
2 changes: 1 addition & 1 deletion qlat-utils/qlat_utils/include/qlat-utils/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ header_files = files(
'types.h',
'vector.h',
'version.h',
'qlat_GPU_translator.h',
'qacc-translator.h',
)
py3.install_sources(header_files, subdir: 'qlat_utils/include/qlat-utils')

Expand Down
14 changes: 7 additions & 7 deletions qlat-utils/qlat_utils/include/qlat-utils/qacc-func.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ API inline int& qacc_num_threads()
dim3 CUDA_THREADS_DIM3(QACC_NUM_THREADS, 1, 1); \
dim3 CUDA_BLOCKS_DIM3((num1 + QACC_NUM_THREADS - 1) / QACC_NUM_THREADS, \
num2, 1); \
qlat_GPU_Error CUDA_LAST_ERROR_OBJECT = qlat_GPU_GetLastError(); \
if (qlat_GPU_Success != CUDA_LAST_ERROR_OBJECT) { \
qacc_Error CUDA_LAST_ERROR_OBJECT = qacc_GetLastError(); \
if (qacc_Success != CUDA_LAST_ERROR_OBJECT) { \
qerr(qlat::ssprintf("qacc_for: Cuda error %s from '%s' Line %d.", \
qlat_GPU_GetErrorString(CUDA_LAST_ERROR_OBJECT), \
qacc_GetErrorString(CUDA_LAST_ERROR_OBJECT), \
__FILE__, __LINE__)); \
} \
qlambda_apply<<<CUDA_BLOCKS_DIM3, CUDA_THREADS_DIM3>>>( \
Expand All @@ -96,12 +96,12 @@ __global__ void qlambda_apply(Long num1, Long num2, Lambda lam)

#define qacc_barrier(dummy) \
{ \
qlat_GPU_DeviceSynchronize(); \
qlat_GPU_Error err = qlat_GPU_GetLastError(); \
if (qlat_GPU_Success != err) { \
qacc_DeviceSynchronize(); \
qacc_Error err = qacc_GetLastError(); \
if (qacc_Success != err) { \
qlat::displayln( \
qlat::ssprintf("qacc_barrier: Cuda error %s from '%s' Line %d.", \
qlat_GPU_GetErrorString(err), __FILE__, __LINE__)); \
qacc_GetErrorString(err), __FILE__, __LINE__)); \
qassert(false); \
} \
}
Expand Down
97 changes: 97 additions & 0 deletions qlat-utils/qlat_utils/include/qlat-utils/qacc-translator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
//// https://github.com/ROCm-Developer-Tools/HIPIFY/blob/amd-staging/docs/tables/CUDA_Runtime_API_functions_supported_by_HIP.md
//// https://github.com/ROCm-Developer-Tools/HIPIFY/blob/amd-staging/docs/tables/CUFFT_API_supported_by_HIP.md

#ifndef QLAT_GPU_TRANSLATOR_H
#define QLAT_GPU_TRANSLATOR_H
#pragma once

#ifdef QLAT_USE_ACC

#ifdef __NVCC__

#define qacc_DeviceProp cudaDeviceProp
#define qacc_DeviceReset cudaDeviceReset
#define qacc_DeviceSetCacheConfig cudaDeviceSetCacheConfig
#define qacc_DeviceSynchronize cudaDeviceSynchronize
#define qacc_ErrorCudartUnloading cudaErrorCudartUnloading
#define qacc_Error cudaError
#define qacc_Free cudaFree
#define qacc_FuncCachePreferL1 cudaFuncCachePreferL1
#define qacc_FuncCachePreferNone cudaFuncCachePreferNone
#define qacc_GetDevice cudaGetDevice
#define qacc_GetDeviceCount cudaGetDeviceCount
#define qacc_GetDeviceFlags cudaGetDeviceFlags
#define qacc_GetDeviceProperties cudaGetDeviceProperties
#define qacc_GetErrorString cudaGetErrorString
#define qacc_GetLastError cudaGetLastError
#define qacc_Malloc cudaMalloc
#define qacc_Malloc3D cudaMalloc3D
#define qacc_MallocManaged cudaMallocManaged
#define qacc_MemAdvise cudaMemAdvise
#define qacc_MemAdviseSetReadMostly cudaMemAdviseSetReadMostly
#define qacc_MemAdviseUnsetReadMostly cudaMemAdviseUnsetReadMostly
#define qacc_MemGetInfo cudaMemGetInfo
#define qacc_MemPrefetchAsync cudaMemPrefetchAsync
#define qacc_Memcpy2DAsync cudaMemcpy2DAsync
#define qacc_MemcpyAsync cudaMemcpyAsync
#define qacc_MemcpyDeviceToDevice cudaMemcpyDeviceToDevice
#define qacc_MemcpyDeviceToHost cudaMemcpyDeviceToHost
#define qacc_MemcpyHostToDevice cudaMemcpyHostToDevice
#define qacc_MemcpyHostToHost cudaMemcpyHostToHost
#define qacc_MemcpyKind cudaMemcpyKind
#define qacc_MemcpyToSymbol cudaMemcpyToSymbol
#define qacc_MemsetAsync cudaMemsetAsync
#define qacc_SetDevice cudaSetDevice
#define qacc_StreamCreate cudaStreamCreate
#define qacc_Stream_t cudaStream_t
#define qacc_Success cudaSuccess
#define qacc_StreamDestroy cudaStreamDestroy

#else

#include <hip/hip_runtime.h>
#include <hip/hip_runtime_api.h>

#define qacc_DeviceProp hipDeviceProp_t
#define qacc_DeviceReset hipDeviceReset
#define qacc_DeviceSetCacheConfig hipDeviceSetCacheConfig
#define qacc_DeviceSynchronize hipDeviceSynchronize
#define qacc_ErrorCudartUnloading hipErrorDeinitialized
#define qacc_Error hipError_t
#define qacc_Free hipFree
#define qacc_FuncCachePreferL1 hipFuncCachePreferL1
#define qacc_FuncCachePreferNone hipFuncCachePreferNone
#define qacc_GetDevice hipGetDevice
#define qacc_GetDeviceCount hipGetDeviceCount
#define qacc_GetDeviceFlags hipGetDeviceFlags
#define qacc_GetDeviceProperties hipGetDeviceProperties
#define qacc_GetErrorString hipGetErrorString
#define qacc_GetLastError hipGetLastError
#define qacc_Malloc hipMalloc
#define qacc_Malloc3D hipMalloc3D
#define qacc_MallocManaged hipMallocManaged
#define qacc_MemAdvise hipMemAdvise
#define qacc_MemAdviseSetReadMostly hipMemAdviseSetReadMostly
#define qacc_MemAdviseUnsetReadMostly hipMemAdviseUnsetReadMostly
#define qacc_MemGetInfo hipMemGetInfo
#define qacc_MemPrefetchAsync hipMemPrefetchAsync
#define qacc_Memcpy2DAsync hipMemcpy2DAsync
#define qacc_MemcpyAsync hipMemcpyAsync
#define qacc_MemcpyDeviceToDevice hipMemcpyDeviceToDevice
#define qacc_MemcpyDeviceToHost hipMemcpyDeviceToHost
#define qacc_MemcpyHostToDevice hipMemcpyHostToDevice
#define qacc_MemcpyHostToHost hipMemcpyHostToHost
#define qacc_MemcpyKind hipMemcpyKind
#define qacc_MemcpyToSymbol hipMemcpyToSymbol
#define qacc_MemsetAsync hipMemsetAsync
#define qacc_SetDevice hipSetDevice
#define qacc_StreamCreate hipStreamCreate
#define qacc_Stream_t hipStream_t
#define qacc_Success hipSuccess
#define qacc_StreamDestroy hipStreamDestroy

#endif

#endif

#endif
2 changes: 1 addition & 1 deletion qlat-utils/qlat_utils/include/qlat-utils/qacc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#endif

#include <qlat-utils/qlat_GPU_translator.h>
#include <qlat-utils/qacc-translator.h>

namespace qlat
{ //
Expand Down
97 changes: 0 additions & 97 deletions qlat-utils/qlat_utils/include/qlat-utils/qlat_GPU_translator.h

This file was deleted.

28 changes: 14 additions & 14 deletions qlat-utils/qlat_utils/include/qlat-utils/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ struct API MemCache {
qassert(ptr != NULL);
#ifdef QLAT_USE_ACC
if (is_acc) {
qlat_GPU_Error err = qlat_GPU_Free(ptr);
if (qlat_GPU_Success != err) {
if (qlat_GPU_ErrorCudartUnloading != err) {
qerr(fname + ssprintf(": Cuda error '%s' (%d) after qlat_GPU_Free.",
qlat_GPU_GetErrorString(err), err));
qacc_Error err = qacc_Free(ptr);
if (qacc_Success != err) {
if (qacc_ErrorCudartUnloading != err) {
qerr(fname + ssprintf(": Cuda error '%s' (%d) after qacc_Free.",
qacc_GetErrorString(err), err));
}
}
} else {
Expand Down Expand Up @@ -170,16 +170,16 @@ inline void* alloc_mem(const Long min_size, const bool is_acc = false)
void* ptr = NULL;
#ifdef QLAT_USE_ACC
if (is_acc) {
qlat_GPU_Error err = qlat_GPU_GetLastError();
if (qlat_GPU_Success != err) {
qerr(fname + ssprintf(": Cuda error '%s' before qlat_GPU_MallocManaged.",
qlat_GPU_GetErrorString(err)));
qacc_Error err = qacc_GetLastError();
if (qacc_Success != err) {
qerr(fname + ssprintf(": Cuda error '%s' before qacc_MallocManaged.",
qacc_GetErrorString(err)));
}
err = qlat_GPU_MallocManaged(&ptr, size);
if (qlat_GPU_Success != err) {
err = qacc_MallocManaged(&ptr, size);
if (qacc_Success != err) {
qerr(fname +
ssprintf(": Cuda error '%s', min_size=%ld, size=%ld, ptr=%lX.",
qlat_GPU_GetErrorString(err), min_size, size, ptr));
qacc_GetErrorString(err), min_size, size, ptr));
}
} else {
ptr = alloc_mem_alloc_no_acc(size);
Expand Down Expand Up @@ -218,7 +218,7 @@ struct API vector {
// Only used in qacc macros, or if it is already a copy.
//
bool is_copy; // do not free memory if is_copy=true
bool is_acc; // if place data on qlat_GPU_MallocManaged memory (default false)
bool is_acc; // if place data on qacc_MallocManaged memory (default false)
Vector<M> v;
//
vector()
Expand Down Expand Up @@ -639,7 +639,7 @@ struct API box {
// Only used in qacc macros, or if it is already a copy.
//
bool is_copy; // do not free memory if is_copy=true
bool is_acc; // if place data on qlat_GPU_MallocManaged memory (default false)
bool is_acc; // if place data on qacc_MallocManaged memory (default false)
Handle<M> v;
//
box()
Expand Down
Loading

0 comments on commit 81824d6

Please sign in to comment.