12#include <kernel/util/string.hpp>
16#include <cusparse_v2.h>
29 extern cusparseHandle_t cusparse_handle;
30 extern cublasHandle_t cublas_handle;
31 extern cublasLtMatmulAlgo_t * cublas_lt_algo_matmat;
32 extern bool * cublas_lt_algo_matmat_initialized;
33 extern size_t cuda_workspace_size;
34 extern void * cuda_workspace;
37 extern bool stream_ordered_supported;
43 extern int cuda_device_number;
46 extern Index cuda_blocksize_misc;
49 extern Index cuda_blocksize_reduction;
52 extern Index cuda_blocksize_spmv;
55 extern Index cuda_blocksize_axpy;
58 extern Index cuda_blocksize_scalar_assembly;
61 extern Index cuda_blocksize_blocked_assembly;
64 extern Index cuda_blocksize_vanka_assembly;
67 struct RuntimeParameter
85 void* stream =
nullptr;
87 std::uint32_t stream_idx = 0;
91 void cuda_set_device(
const int device);
92 void cuda_check_last_error();
97 void * cuda_get_static_memory(
const Index bytes);
100 void cuda_free_static_memory();
101 void cuda_initialize(
int rank,
int ranks_per_node,
int ranks_per_uma,
int gpus_per_node);
102 void cuda_finalize();
111 void cuda_register_finalize_callback(
void (*callback)());
112 NOINLINE
void cuda_synchronize();
113 NOINLINE
void cuda_force_synchronize();
114 void cuda_reset_device();
119 void cuda_reset_algos();
124 int cuda_get_device_count();
125 int cuda_get_device_id();
126 String cuda_get_visible_devices();
127 std::size_t cuda_get_max_cache_thread();
128 void cuda_set_max_cache_thread(
const std::size_t bytes);
129 void cuda_start_profiling();
130 void cuda_stop_profiling();
131 std::size_t cuda_get_shared_mem_per_sm();
132 std::size_t cuda_get_max_blocks_per_sm();
133 std::size_t cuda_get_sm_count();
137 bool cuda_get_stream_ordered_alloc_supported();
144 inline int cuda_get_occupancy(T kernel_func,
int blocksize,
int shared_memory = 0)
147 if(cudaOccupancyMaxActiveBlocksPerMultiprocessor(&num_blocks, kernel_func, blocksize, shared_memory) != cudaSuccess)
149 throw InternalError(__func__, __FILE__, __LINE__,
"cudaOccupancyMaxActiveBlockPerMultiprocessor failed!");
155 std::uint64_t cuda_start_range(
const char* name);
157 void cuda_stop_range(std::uint64_t
id);
159 void cuda_mark_event(
const char* name);
190 std::vector<std::uint64_t>
_ids;
207 void push([[maybe_unused]]
const char* name)
210 _ids.push_back(cuda_start_range(name));
220 cuda_stop_range(
_ids.back());
234 inline NvtxRangeStack& nvtx_thread_stack()
236 thread_local NvtxRangeStack stack;
260 _stack(nvtx_thread_stack())
284 inline void nvtx_mark([[maybe_unused]]
const char* name)
287 cuda_mark_event(name);
Stack manager for nested NVTX profiling ranges.
void push(const char *name)
opens a new named range and pushes it onto the stack
std::vector< std::uint64_t > _ids
the ids of the currently open ranges (LIFO order)
~NvtxRangeStack()
closes all ranges that are still open
NvtxRangeStack(const NvtxRangeStack &)=delete
stacks must not be copied (ownership of open range ids is unique)
std::size_t size() const
returns the number of currently open ranges
void pop()
closes the most recently opened range (no-op if the stack is empty)
RAII scope guard for an NVTX profiling range.
NvtxRangeStack & _stack
the stack this range was pushed onto
ScopedNvtxRange(NvtxRangeStack &stack, const char *name)
opens a range name on the given stack
ScopedNvtxRange(const ScopedNvtxRange &)=delete
scope guards must not be copied or moved
ScopedNvtxRange(const char *name)
opens a range name on the calling thread's default stack
~ScopedNvtxRange()
closes the range
std::uint64_t Index
Index data type.