diff options
| author | Joshua Bakita <jbakita@cs.unc.edu> | 2025-06-16 19:29:07 -0400 |
|---|---|---|
| committer | Joshua Bakita <jbakita@cs.unc.edu> | 2025-06-17 14:01:49 -0400 |
| commit | 89177fce34edb5ad0059a41548888d05588cc1c5 (patch) | |
| tree | 096dc302bb5e17e3987c45a59ef02c69ec73e9ed /Makefile | |
| parent | 03ae77e35d35b2a82f5387d1903cfa954b696edd (diff) | |
Rewrite nvtaskset and implementation of partitioning for unmodified tasks
Rather than requiring libsmctrl.so to be preloaded, we now wrap
libcuda.so.1. All CUDA-using applications will load libcuda.so.1,
ensuring that our wrapper will always be dynamically loaded, no
matter if LD_PRELOAD is enabled, or if a program has been staticly
linked. All that needs to be done is that the location of our
"fake" libcuda.so.1 need to be put within the loader search path.
This can be done by setting LD_LIBRARY_PATH, or by installing
our wrapper into /lib/x86_64-linux-gnu.
The mask can still be set via the LIBSMCTRL_MASK environment
variable, but the easier-to-use nvtaskset tool is now the
recommended way to view or change the supreme TPC mask for any
CUDA-using application. This allows launching a program on the
first two GPCs via a command as simple as:
./nvtaskset -g 0-1 ./a_program a_program_args
(Note that use of the -g option requires the nvdebug kernel module
to first be loaded.)
These changes support the final version of the ECRTS'25 paper.
Note that nvtaskset does not yet fully support multi-GPU systems.
Bugfixes:
- Fix crash that would occur if both libsmctrl.so and libsmctrl.a
were built into an application.
- Correctly use GPU ID when initializing a context in
`libsmctrl_test_gpc_info`.
- Include `nvtaskset` as a prerequisite for
`libsmctrl_test_supreme_mask`.
- Fix malfunction of `libsmctrl_test_gpc_info` if
CUDA_VISIBLE_DEVICES is set.
Other minor changes:
- Adds make target to run all the tests.
- Fixes typos in comments.
- Enables -Wall build option.
- Upgrades supreme mask from 64 to 128 bits.
- Removes `detect_parker_soc()` from the global namespace.
- Adjusts test messages to be more succinct.
- Updates README with overview of how to partition unmodified
applications, more details on the tests, and information on the
new ECRTS'25 paper.
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 47 |
1 files changed, 41 insertions, 6 deletions
| @@ -3,9 +3,11 @@ CUDA ?= /usr/local/cuda | |||
| 3 | # Note that CXX and CC are predefined as g++ and cc (respectively) by Make | 3 | # Note that CXX and CC are predefined as g++ and cc (respectively) by Make |
| 4 | NVCC ?= $(CUDA)/bin/nvcc | 4 | NVCC ?= $(CUDA)/bin/nvcc |
| 5 | # Everything has to have -lcuda, as it's needed for libsmctrl | 5 | # Everything has to have -lcuda, as it's needed for libsmctrl |
| 6 | LDFLAGS := -lcuda -I$(CUDA)/include -L$(CUDA)/lib64 | 6 | LDFLAGS := -ldl -lcuda -I$(CUDA)/include -L$(CUDA)/lib64 |
| 7 | ARCH = $(shell $(CC) -dumpmachine) | ||
| 8 | CFLAGS := -Wall -Wno-parentheses | ||
| 7 | 9 | ||
| 8 | .PHONY: clean tests all | 10 | .PHONY: clean tests all install remove run_tests |
| 9 | 11 | ||
| 10 | # ----- Main Library ----- | 12 | # ----- Main Library ----- |
| 11 | libsmctrl.so: libsmctrl.c libsmctrl.h | 13 | libsmctrl.so: libsmctrl.c libsmctrl.h |
| @@ -14,9 +16,14 @@ libsmctrl.so: libsmctrl.c libsmctrl.h | |||
| 14 | # -fPIC is needed even if built as a static library, in case we are linked into | 16 | # -fPIC is needed even if built as a static library, in case we are linked into |
| 15 | # another shared library | 17 | # another shared library |
| 16 | libsmctrl.a: libsmctrl.c libsmctrl.h | 18 | libsmctrl.a: libsmctrl.c libsmctrl.h |
| 17 | $(CC) $< -c -o libsmctrl.o -fPIC $(CFLAGS) $(LDFLAGS) | 19 | $(CC) $< -c -o libsmctrl.o -fPIC -DLIBSMCTRL_STATIC $(CFLAGS) $(LDFLAGS) |
| 18 | ar rcs $@ libsmctrl.o | 20 | ar rcs $@ libsmctrl.o |
| 19 | 21 | ||
| 22 | # ----- CUDA Wrapper ----- | ||
| 23 | libcuda.so.1: libsmctrl.c libsmctrl.h | ||
| 24 | $(CC) $< -shared -o $@ -fPIC -DLIBSMCTRL_WRAPPER $(CFLAGS) $(LDFLAGS) | ||
| 25 | patchelf libcuda.so.1 --add-needed libcuda.so | ||
| 26 | |||
| 20 | # ----- Utilities ----- | 27 | # ----- Utilities ----- |
| 21 | # Use static linking with tests to avoid LD_LIBRARY_PATH issues | 28 | # Use static linking with tests to avoid LD_LIBRARY_PATH issues |
| 22 | nvtaskset: nvtaskset.c libsmctrl.so libsmctrl.a | 29 | nvtaskset: nvtaskset.c libsmctrl.so libsmctrl.a |
| @@ -29,7 +36,7 @@ libsmctrl_test_gpc_info: libsmctrl_test_gpc_info.c libsmctrl.a testbench.h | |||
| 29 | libsmctrl_test_mask_shared.o: libsmctrl_test_mask_shared.cu testbench.h | 36 | libsmctrl_test_mask_shared.o: libsmctrl_test_mask_shared.cu testbench.h |
| 30 | $(NVCC) -ccbin $(CXX) $< -c -g | 37 | $(NVCC) -ccbin $(CXX) $< -c -g |
| 31 | 38 | ||
| 32 | libsmctrl_test_supreme_mask: libsmctrl_test_supreme_mask.c libsmctrl.a libsmctrl_test_mask_shared.o | 39 | libsmctrl_test_supreme_mask: libsmctrl_test_supreme_mask.c libsmctrl.a libsmctrl_test_mask_shared.o libcuda.so.1 nvtaskset |
| 33 | $(NVCC) -ccbin $(CXX) $@.c -o $@ libsmctrl_test_mask_shared.o -g -L. -l:libsmctrl.a $(LDFLAGS) | 40 | $(NVCC) -ccbin $(CXX) $@.c -o $@ libsmctrl_test_mask_shared.o -g -L. -l:libsmctrl.a $(LDFLAGS) |
| 34 | 41 | ||
| 35 | libsmctrl_test_global_mask: libsmctrl_test_global_mask.c libsmctrl.a libsmctrl_test_mask_shared.o | 42 | libsmctrl_test_global_mask: libsmctrl_test_global_mask.c libsmctrl.a libsmctrl_test_mask_shared.o |
| @@ -52,7 +59,7 @@ tests: libsmctrl_test_gpc_info libsmctrl_test_supreme_mask \ | |||
| 52 | libsmctrl_test_stream_mask_override libsmctrl_test_next_mask \ | 59 | libsmctrl_test_stream_mask_override libsmctrl_test_next_mask \ |
| 53 | libsmctrl_test_next_mask_override | 60 | libsmctrl_test_next_mask_override |
| 54 | 61 | ||
| 55 | all: libsmctrl.so nvtaskset tests | 62 | all: libsmctrl.so libcuda.so.1 nvtaskset tests |
| 56 | 63 | ||
| 57 | clean: | 64 | clean: |
| 58 | rm -f libsmctrl.so libsmctrl.o libsmctrl.a libsmctrl_test_gpc_info \ | 65 | rm -f libsmctrl.so libsmctrl.o libsmctrl.a libsmctrl_test_gpc_info \ |
| @@ -60,4 +67,32 @@ clean: | |||
| 60 | libsmctrl_test_global_mask \ | 67 | libsmctrl_test_global_mask \ |
| 61 | libsmctrl_test_stream_mask libsmctrl_test_stream_mask_override \ | 68 | libsmctrl_test_stream_mask libsmctrl_test_stream_mask_override \ |
| 62 | libsmctrl_test_next_mask libsmctrl_test_next_mask_override \ | 69 | libsmctrl_test_next_mask libsmctrl_test_next_mask_override \ |
| 63 | nvtaskset | 70 | nvtaskset libcuda.so.1 |
| 71 | |||
| 72 | install: libcuda.so.1 | ||
| 73 | @# Check that CUDA is installed first | ||
| 74 | test -f /lib/$(ARCH)/libcuda.so.*.* | ||
| 75 | @# Change libcuda.so link to bypass libcuda.so.1 | ||
| 76 | sudo ln -sf /lib/$(ARCH)/libcuda.so.*.* /lib/$(ARCH)/libcuda.so | ||
| 77 | @# Remove libcuda.so.1 symlink | ||
| 78 | sudo rm /lib/$(ARCH)/libcuda.so.1 | ||
| 79 | @# Install wrapper as libcuda.so.1 | ||
| 80 | sudo cp libcuda.so.1 /lib/$(ARCH)/libcuda.so.1 | ||
| 81 | |||
| 82 | remove: | ||
| 83 | @# Test that our library in installed first | ||
| 84 | test ! -L /lib/$(ARCH)/libcuda.so.1 | ||
| 85 | @# Overwrite install with original symlinks | ||
| 86 | sudo ln -sf libcuda.so.1 /lib/$(ARCH)/libcuda.so | ||
| 87 | sudo ln -sf /lib/$(ARCH)/libcuda.so.*.* /lib/$(ARCH)/libcuda.so.1 | ||
| 88 | |||
| 89 | run_tests: tests | ||
| 90 | ./libsmctrl_test_global_mask | ||
| 91 | ./libsmctrl_test_next_mask | ||
| 92 | ./libsmctrl_test_stream_mask | ||
| 93 | ./libsmctrl_test_next_mask_override | ||
| 94 | ./libsmctrl_test_stream_mask_override | ||
| 95 | @# Must set LD_LIBRARY_PATH in case make install has not been run | ||
| 96 | LD_LIBRARY_PATH=. ./libsmctrl_test_supreme_mask | ||
| 97 | ./libsmctrl_test_gpc_info | ||
| 98 | @ echo "All tests passed!" | ||
