|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2017 NVIDIA CORPORATION & AFFILIATES. |
| 2 | +# All rights reserved. |
| 3 | +# SPDX-License-Identifier: BSD-3-Clause |
| 4 | +# |
| 5 | +# Redistribution and use in source and binary forms, with or without |
| 6 | +# modification, are permitted provided that the following conditions are met: |
| 7 | +# |
| 8 | +# 1. Redistributions of source code must retain the above copyright notice, this |
| 9 | +# list of conditions and the following disclaimer. |
| 10 | +# |
| 11 | +# 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | +# this list of conditions and the following disclaimer in the documentation |
| 13 | +# and/or other materials provided with the distribution. |
| 14 | +# |
| 15 | +# 3. Neither the name of the copyright holder nor the names of its |
| 16 | +# contributors may be used to endorse or promote products derived from |
| 17 | +# this software without specific prior written permission. |
| 18 | +# |
| 19 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 22 | +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 23 | +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 24 | +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 25 | +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 26 | +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 27 | +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | + |
| 30 | +NVCC=nvcc -ccbin=$(CXX) -D_FORCE_INLINES |
| 31 | +PTXAS=ptxas |
| 32 | + |
| 33 | +NVCC_VER_REQ=10.1 |
| 34 | +NVCC_VER=$(shell $(NVCC) --version | grep release | cut -f2 -d, | cut -f3 -d' ') |
| 35 | +NVCC_VER_CHECK=$(shell echo "${NVCC_VER} >= $(NVCC_VER_REQ)" | bc) |
| 36 | + |
| 37 | +ifeq ($(NVCC_VER_CHECK),0) |
| 38 | +$(error ERROR: nvcc version >= $(NVCC_VER_REQ) required to compile an nvbit tool! Instrumented applications can still use lower versions of nvcc.) |
| 39 | +endif |
| 40 | + |
| 41 | +PTXAS_VER_ADD_FLAG=12.3 |
| 42 | +PTXAS_VER=$(shell $(PTXAS) --version | grep release | cut -f2 -d, | cut -f3 -d' ') |
| 43 | +PTXAS_VER_CHECK=$(shell echo "${PTXAS_VER} >= $(PTXAS_VER_ADD_FLAG)" | bc) |
| 44 | + |
| 45 | +ifeq ($(PTXAS_VER_CHECK), 0) |
| 46 | +MAXRREGCOUNT_FLAG=-maxrregcount=24 |
| 47 | +else |
| 48 | +MAXRREGCOUNT_FLAG= |
| 49 | +endif |
| 50 | + |
| 51 | +NVBIT_PATH=../../nvbit_release/core |
| 52 | +INCLUDES=-I$(NVBIT_PATH) |
| 53 | + |
| 54 | +LIBS=-L$(NVBIT_PATH) -lnvbit |
| 55 | +NVCC_PATH=-L $(subst bin/nvcc,lib64,$(shell which nvcc | tr -s /)) |
| 56 | + |
| 57 | +SOURCES=$(wildcard *.cu) |
| 58 | + |
| 59 | +OBJECTS=$(SOURCES:.cu=.o) |
| 60 | +ARCH?=all |
| 61 | + |
| 62 | +mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) |
| 63 | +current_dir := $(notdir $(patsubst %/,%,$(dir $(mkfile_path)))) |
| 64 | + |
| 65 | +NVBIT_TOOL=$(current_dir).so |
| 66 | + |
| 67 | +all: $(NVBIT_TOOL) |
| 68 | + |
| 69 | +$(NVBIT_TOOL): $(OBJECTS) $(NVBIT_PATH)/libnvbit.a |
| 70 | + $(NVCC) -arch=$(ARCH) -O3 $(OBJECTS) $(LIBS) $(NVCC_PATH) -lcuda -lcudart_static -shared -o $@ |
| 71 | + |
| 72 | +%.o: %.cu |
| 73 | + $(NVCC) -dc -c -std=c++17 $(INCLUDES) -Xptxas -cloning=no -Xcompiler -Wall -arch=$(ARCH) -O3 -Xcompiler -fPIC $< -o $@ |
| 74 | + |
| 75 | +inject_funcs.o: inject_funcs.cu |
| 76 | + $(NVCC) $(INCLUDES) $(MAXRREGCOUNT_FLAG) -Xptxas -astoolspatch --keep-device-functions -arch=$(ARCH) -Xcompiler -Wall -Xcompiler -fPIC -c $< -o $@ |
| 77 | + |
| 78 | +clean: |
| 79 | + rm -f *.so *.o |
0 commit comments