aboutsummaryrefslogtreecommitdiffstats
path: root/libsmctrl.h
diff options
context:
space:
mode:
Diffstat (limited to 'libsmctrl.h')
-rw-r--r--libsmctrl.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/libsmctrl.h b/libsmctrl.h
new file mode 100644
index 0000000..7be425d
--- /dev/null
+++ b/libsmctrl.h
@@ -0,0 +1,62 @@
1/**
2 * Copyright 2022 Joshua Bakita
3 * Library to control TPC masks on CUDA launches. Co-opts preexisting debug
4 * logic in the CUDA driver library, and thus requires a build with -lcuda.
5 */
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11/* PARTITIONING FUNCTIONS */
12
13// Set global default TPC mask for all kernels, incl. CUDA-internal ones
14// @param mask A bitmask of enabled/disabled TPCs (see Notes on Bitmasks)
15// Supported: CUDA 10.2, and CUDA 11.0 - CUDA 11.8
16extern void libsmctrl_set_global_mask(uint64_t mask);
17// Set default TPC mask for all kernels launched via `stream`
18// (overrides global mask)
19// @param stream A cudaStream_t (aka CUstream_st*) to apply the mask on
20// @param mask A bitmask of enabled/disabled TPCs (see Notes on Bitmasks)
21// Supported: CUDA 8.0 - CUDA 11.8
22extern void libsmctrl_set_stream_mask(void* stream, uint64_t mask);
23// Set TPC mask for the next kernel launch from the caller's CPU thread
24// (overrides global and per-stream masks, applies only to next launch).
25// @param mask A bitmask of enabled/disabled TPCs (see Notes on Bitmasks)
26// Supported: CUDA 11.0 - CUDA 11.8
27extern void libsmctrl_set_next_mask(uint64_t mask);
28
29// **DEPRECATED**: Old name for libsmctrl_set_global_mask()
30extern void set_sm_mask(uint64_t mask) __attribute__((deprecated("Use libsmctrl_set_global_mask()")));
31
32/**
33 * Notes on Bitmasks
34 *
35 * All of the core partitioning functions take a `uint64_t mask` parameter. A
36 * set bit in the mask indicates that the respective Thread Processing Cluster
37 * (TPC) is to be __disabled__.
38 *
39 * Examples
40 * To prohibit the next kernel from using TPC 0:
41 * libsmctrl_set_next_mask(0x1);
42 * Allow kernels to only use TPC 0 by default:
43 * libsmctrl_set_global_mask(~0x1ull);
44 * Allow kernels in a stream to only use TPCs 2, 3, and 4:
45 * libsmctrl_set_stream_mask(stream, ~0b00111100ull);
46 *
47 * Note that the bitwise inversion operator (~, as used above) is very useful,
48 * just be sure to apply it to 64-bit integer literals only! (~0x1 != ~0x1ull)
49 */
50
51/* INFORMATIONAL FUNCTIONS */
52
53// Get total number of TPCs on device number `dev`.
54extern int libsmctrl_get_tpc_info(uint32_t* num_tpcs, int dev);
55// Get number of GPCs for devices number `dev`, and a GPC-indexed array
56// containing masks of which TPCs are associated with each GPC.
57// Note that the `nvdebug` module must be loaded to use this function.
58extern int libsmctrl_get_gpc_info(uint32_t* num_enabled_gpcs, uint64_t** tpcs_for_gpc, int dev);
59
60#ifdef __cplusplus
61}
62#endif