35#include "hip/hip_runtime.h"
57#define CS_HIP_CHECK(a) { \
58 hipError_t _l_ret_code = a; \
59 if (hipSuccess != _l_ret_code) { \
60 bft_error(__FILE__, __LINE__, 0, "[HIP error] %d: %s\n running: %s", \
61 _l_ret_code, ::hipGetErrorString(_l_ret_code), #a); \
65#define CS_HIP_CHECK_CALL(a, file_name, line_num) { \
66 hipError_t _l_ret_code = a; \
67 if (hipSuccess != _l_ret_code) { \
68 bft_error(file_name, line_num, 0, "[HIP error] %d: %s\n running: %s", \
69 _l_ret_code, ::hipGetErrorString(_l_ret_code), #a); \
76#if defined(__GFX8__) || defined(__GFX9__)
77 #define CS_HIP_WARP_SIZE 64
78using cs_hip_mask_t = uint64_t;
80 #define CS_HIP_WARP_SIZE 32
81using cs_hip_mask_t = uint32_t;
92extern int cs_glob_hip_device_id;
96extern int cs_glob_hip_shared_mem_per_block;
97extern int cs_glob_hip_max_threads_per_block;
98extern int cs_glob_hip_max_block_size;
99extern int cs_glob_hip_max_blocks;
100extern int cs_glob_hip_n_mp;
102#if defined(HAVE_NCCL)
104extern ncclComm_t cs_glob_nccl_comm;
107extern ncclDataType_t cs_datatype_to_nccl[];
114extern bool cs_glob_hip_allow_graph;
139cs_hip_copy_h2d(
void *dst,
161cs_hip_copy_h2d_async(
void *dst,
182cs_hip_copy_d2h(
void *dst,
203cs_hip_copy_d2h_async(
void *dst,
222cs_hip_copy_d2d(
void *dst,
245cs_hip_get_host_ptr(
const void *ptr);
268 unsigned int block_size)
270 return (n % block_size) ? n/block_size + 1 : n/block_size;
273#if defined(__HIPCC__)
290cs_sync_or_copy_h2d(
const T *val_h,
297 const T *_val_d = NULL;
303 size_t size = n_vals *
sizeof(T);
306 CS_HIP_CHECK(hipMalloc(&_buf_d, size));
307 cs_hip_copy_h2d(_buf_d, val_h, size);
308 _val_d = (
const T *)_buf_d;
350cs_hip_get_stream(
int stream_id);
363cs_hip_get_stream_prefetch(
void);
378cs_hip_get_stream_id(hipStream_t stream);
398cs_hip_get_2_stage_reduce_buffers(
int stream_id,
401 unsigned int grid_size,
void cs_base_hip_nccl_info(cs_log_t log_id)
Log information on NCCL.
Definition: cs_base_hip.cpp:698
void cs_base_hip_device_info(cs_log_t log_id)
Log information on available HIP devices.
Definition: cs_base_hip.cpp:604
int cs_base_hip_get_device(void)
Return currently selected HIP devices.
Definition: cs_base_hip.cpp:816
void cs_base_hip_compiler_info(cs_log_t log_id)
Log information on HIP compiler.
Definition: cs_base_hip.cpp:683
int cs_base_hip_select_default_device(void)
Set HIP device based on MPI rank and number of devices.
Definition: cs_base_hip.cpp:727
void cs_base_hip_version_info(cs_log_t log_id)
Log information on available HIP version.
Definition: cs_base_hip.cpp:662
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
cs_log_t
Definition: cs_log.h:44
void cs_sync_h2d(const void *ptr)
Synchronize data from host to device.
Definition: cs_mem.h:935
cs_alloc_mode_t cs_check_device_ptr(const void *ptr)
Check if a pointer is associated with a device.
Definition: cs_mem.h:727
const void * cs_get_device_ptr_const(const void *ptr)
Return matching device pointer for a given constant pointer.
Definition: cs_mem.h:687
cs_alloc_mode_t
Definition: cs_mem.h:46
@ CS_ALLOC_HOST
Definition: cs_mem.h:48
@ CS_ALLOC_HOST_DEVICE_SHARED
Definition: cs_mem.h:53