-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMakefile
More file actions
183 lines (166 loc) · 7.68 KB
/
Makefile
File metadata and controls
183 lines (166 loc) · 7.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2024 Red Hat Inc
SHELL := /bin/bash
##@ Help
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
AMD_IMAGE_NAME ?=amd
CPU_IMAGE_NAME ?=cpu
CTR_CMD := $(or $(shell command -v podman), $(shell command -v docker))
DEMO_TOOLS ?= false
NOTEBOOK_PORT ?= 8888
HIP_DEVICES := $(or $(HIP_VISIBLE_DEVICES), 0)
IMAGE_REPO ?=quay.io/triton-dev-containers
mkfile_path :=$(abspath $(lastword $(MAKEFILE_LIST)))
NVIDIA_IMAGE_NAME ?=nvidia
OS := $(shell uname -s)
SELINUXFLAG := $(shell if [ "$(shell getenforce 2> /dev/null)" == "Enforcing" ]; then echo ":z"; fi)
source_dir :=$(shell dirname "$(mkfile_path)")
STRIPPED_CMD := $(shell basename $(CTR_CMD))
torch_version ?=$(shell curl -s https://api.github.com/repos/pytorch/pytorch/releases/latest | grep '"tag_name":' | sed -E 's/.*"tag_name": "v?([^\"]+)".*/\1/')
TRITON_CPU_BACKEND ?=0
TRITON_TAG ?= latest
triton_path ?=$(source_dir)
llvm_path ?=
torch_path ?=
helion_path ?=
user_path ?=
gitconfig_path ?="$(HOME)/.gitconfig"
USERNAME ?=triton
# NOTE: Requires host build system to have a valid Red Hat Subscription if true
INSTALL_NSIGHT ?=false
INSTALL_LLVM ?= skip # Options: source, skip
INSTALL_TORCH ?= skip # Options: nightly, release, source, skip, test
INSTALL_TRITON ?= source # Options: release, source, skip
INSTALL_HELION ?= skip # Options: release, source, skip
INSTALL_JUPYTER ?= true
USE_CCACHE ?= 0
CUDA_VERSION ?= 12-8
ROCM_VERSION ?= 6.2
MAX_JOBS ?= $(shell nproc --all)
##@ Container Build
.PHONY: image-builder-check
image-builder-check: ## Verify if container runtime is available
@if [ -z "$(CTR_CMD)" ]; then \
echo '!! ERROR: containerized builds require podman or docker CLI, none found in $$PATH' >&2; \
exit 1; \
fi
.PHONY: all
all: triton-image triton-cpu-image triton-amd-image
.PHONY: gosu-image
gosu-image: image-builder-check ## Build the Triton gosu image
$(CTR_CMD) build -t $(IMAGE_REPO)/gosu:latest -f dockerfiles/Dockerfile.gosu .
.PHONY: triton-image
triton-image: image-builder-check gosu-image ## Build the Triton devcontainer image
$(CTR_CMD) build -t $(IMAGE_REPO)/$(NVIDIA_IMAGE_NAME):$(TRITON_TAG) \
--build-arg BUILD_CUDA_VERSION=$(CUDA_VERSION) \
-f dockerfiles/Dockerfile.triton .
.PHONY: triton-cpu-image
triton-cpu-image: image-builder-check gosu-image ## Build the Triton CPU image
$(CTR_CMD) build -t $(IMAGE_REPO)/$(CPU_IMAGE_NAME):$(TRITON_TAG) \
-f dockerfiles/Dockerfile.triton-cpu .
.PHONY: triton-amd-image
triton-amd-image: image-builder-check gosu-image ## Build the Triton AMD devcontainer image
$(CTR_CMD) build -t $(IMAGE_REPO)/$(AMD_IMAGE_NAME):$(TRITON_TAG) \
--build-arg BUILD_ROCM_VERSION=$(ROCM_VERSION) \
-f dockerfiles/Dockerfile.triton-amd .
##@ Container Run
# If you are on an OS that has the user in /etc/passwd then we can pass
# the user from the host to the pod. Otherwise we default to create the
# user inside the container.
# With podman if you aren't creating the user you need to explicitly pass
# the user as --user $(USER) to start the container as that user.
define run_container
echo "Running container image: $(IMAGE_REPO)/$(strip $(1)):$(TRITON_TAG) with $(CTR_CMD)"
@if [ "$(triton_path)" != "$(source_dir)" ]; then \
volume_arg="-v $(triton_path):/workspace/$(strip $(2))$(SELINUXFLAG)"; \
else \
volume_arg=""; \
fi; \
if [ -n "$(llvm_path)" ]; then \
volume_arg+=" -v $(llvm_path):/workspace/llvm-project$(SELINUXFLAG)"; \
fi; \
if [ -n "$(torch_path)" ]; then \
volume_arg+=" -v $(torch_path):/workspace/torch$(SELINUXFLAG)"; \
fi; \
if [ -n "$(helion_path)" ]; then \
volume_arg+=" -v $(helion_path):/workspace/helion$(SELINUXFLAG)"; \
fi; \
if [ -n "$(user_path)" ]; then \
volume_arg+=" -v $(user_path):/workspace/user$(SELINUXFLAG)"; \
fi; \
if [ "$(OS)" != "Darwin" ] && ! getent passwd $(USER) > /dev/null; then \
volume_arg+=" -v /etc/passwd:/etc/passwd:ro -v /etc/group:/etc/group:ro"; \
fi; \
if [ -f "$(gitconfig_path)" ]; then \
gitconfig_arg="-v $(gitconfig_path):/etc/gitconfig$(SELINUXFLAG)"; \
else \
gitconfig_arg=""; \
fi; \
if [ "$(strip $(1))" = "$(AMD_IMAGE_NAME)" ]; then \
gpu_args="--device=/dev/kfd --device=/dev/dri --security-opt seccomp=unconfined --group-add=video --cap-add=SYS_PTRACE --ipc=host --env HIP_VISIBLE_DEVICES=$(HIP_DEVICES)"; \
elif [ "$(strip $(1))" = "$(NVIDIA_IMAGE_NAME)" ]; then \
if command -v nvidia-ctk >/dev/null 2>&1 && nvidia-ctk cdi list | grep -q "nvidia.com/gpu=all"; then \
gpu_args="--device nvidia.com/gpu=all"; \
else \
gpu_args="--runtime=nvidia --gpus=all"; \
fi; \
gpu_args+=" --security-opt label=disable"; \
if [ "$(INSTALL_NSIGHT)" = "true" ]; then \
profiling_args="--privileged --cap-add=SYS_ADMIN -e INSTALL_NSIGHT=${INSTALL_NSIGHT} -e DISPLAY=${DISPLAY} -e WAYLAND_DISPLAY=${WAYLAND_DISPLAY} -e XDG_RUNTIME_DIR=/tmp -v ${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}:/tmp/${WAYLAND_DISPLAY}:ro"; \
else \
profiling_args=""; \
fi; \
else \
profiling_args=""; \
fi; \
if [ "$(STRIPPED_CMD)" = "podman" ]; then \
keep_ns_arg="--userns=keep-id"; \
else \
keep_ns_arg=""; \
fi; \
if [ "$(DEMO_TOOLS)" = "true" ]; then \
port_arg="-p ${NOTEBOOK_PORT}:${NOTEBOOK_PORT}"; \
else \
port_arg=""; \
fi; \
env_vars="-e USERNAME=$(USER) -e USER_UID=`id -u $(USER)` -e USER_GID=`id -g $(USER)` -e TORCH_VERSION=$(torch_version) -e INSTALL_LLVM=$(INSTALL_LLVM) -e INSTALL_TOOLS=$(DEMO_TOOLS) -e INSTALL_JUPYTER=$(INSTALL_JUPYTER) -e NOTEBOOK_PORT=$(NOTEBOOK_PORT) -e INSTALL_HELION=$(INSTALL_HELION) -e INSTALL_TORCH=$(INSTALL_TORCH) -e INSTALL_TRITON=$(INSTALL_TRITON) -e USE_CCACHE=$(USE_CCACHE) -e MAX_JOBS=$(MAX_JOBS)"; \
if [ "$(STRIPPED_CMD)" = "docker" ]; then \
$(CTR_CMD) run $$env_vars $$gpu_args $$profiling_args $$port_arg \
-ti $$volume_arg $$gitconfig_arg $(IMAGE_REPO)/$(strip $(1)):$(TRITON_TAG) bash; \
elif [ "$(STRIPPED_CMD)" = "podman" ]; then \
$(CTR_CMD) run $$env_vars $$keep_ns_arg $$gpu_args $$profiling_args $$port_arg \
-ti $$volume_arg $$gitconfig_arg $(IMAGE_REPO)/$(strip $(1)):$(TRITON_TAG) bash; \
fi
endef
.PHONY: triton-run
triton-run: image-builder-check ## Run the Triton devcontainer image
$(call run_container, $(NVIDIA_IMAGE_NAME), "triton")
.PHONY: triton-cpu-run
triton-cpu-run: image-builder-check ## Run the Triton CPU devcontainer image
$(call run_container, $(CPU_IMAGE_NAME), "triton-cpu")
.PHONY: triton-amd-run
triton-amd-run: image-builder-check ## Run the Triton AMD devcontainer image
$(call run_container, $(AMD_IMAGE_NAME), "triton")
##@ Devcontainer
.PHONY: devcontainers
devcontainers: ## Generate all devcontainer.json files
@echo "Running devcontainer generation..."
$(MAKE) -C .devcontainer generate
.PHONY: clean-devcontainers
clean-devcontainers: ## Remove generated devcontainer.json files
$(MAKE) -C .devcontainer clean
.PHONY: devcontainers-help
devcontainers-help: ## Show devcontainer help
$(MAKE) -C .devcontainer help