Skip to content

Commit a3c4572

Browse files
authored
Merge pull request #6 from AIComputing101/coketaste/make
Update the Makefile of project
2 parents 42326bc + b9e8520 commit a3c4572

File tree

11 files changed

+380
-89
lines changed

11 files changed

+380
-89
lines changed

Makefile

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Builds all available modules and examples
33

44
# Default target
5-
.PHONY: all clean test help module1 module2 module3 module4 module5 module6 module7 module8 module9
5+
.PHONY: all clean test debug profile help module1 module2 module3 module4 module5 module6 module7 module8 module9
66

77
# Build all available modules
88
all: module1 module2 module3 module4 module5 module6 module7 module8 module9
@@ -83,6 +83,84 @@ test-module9:
8383
@echo "Testing Module 9..."
8484
@$(MAKE) -C modules/module9/examples test
8585

86+
# Debug builds for all modules
87+
debug: debug-module1 debug-module2 debug-module3 debug-module4 debug-module5 debug-module6 debug-module7 debug-module8 debug-module9
88+
89+
debug-module1:
90+
@echo "Debug build Module 1..."
91+
@$(MAKE) -C modules/module1/examples debug
92+
93+
debug-module2:
94+
@echo "Debug build Module 2..."
95+
@$(MAKE) -C modules/module2/examples debug
96+
97+
debug-module3:
98+
@echo "Debug build Module 3..."
99+
@$(MAKE) -C modules/module3/examples debug
100+
101+
debug-module4:
102+
@echo "Debug build Module 4..."
103+
@$(MAKE) -C modules/module4/examples debug
104+
105+
debug-module5:
106+
@echo "Debug build Module 5..."
107+
@$(MAKE) -C modules/module5/examples debug
108+
109+
debug-module6:
110+
@echo "Debug build Module 6..."
111+
@$(MAKE) -C modules/module6/examples debug
112+
113+
debug-module7:
114+
@echo "Debug build Module 7..."
115+
@$(MAKE) -C modules/module7/examples debug
116+
117+
debug-module8:
118+
@echo "Debug build Module 8..."
119+
@$(MAKE) -C modules/module8/examples debug
120+
121+
debug-module9:
122+
@echo "Debug build Module 9..."
123+
@$(MAKE) -C modules/module9/examples debug
124+
125+
# Profile builds for all modules
126+
profile: profile-module1 profile-module2 profile-module3 profile-module4 profile-module5 profile-module6 profile-module7 profile-module8 profile-module9
127+
128+
profile-module1:
129+
@echo "Profile build Module 1..."
130+
@$(MAKE) -C modules/module1/examples profile
131+
132+
profile-module2:
133+
@echo "Profile build Module 2..."
134+
@$(MAKE) -C modules/module2/examples profile
135+
136+
profile-module3:
137+
@echo "Profile build Module 3..."
138+
@$(MAKE) -C modules/module3/examples profile
139+
140+
profile-module4:
141+
@echo "Profile build Module 4..."
142+
@$(MAKE) -C modules/module4/examples profile
143+
144+
profile-module5:
145+
@echo "Profile build Module 5..."
146+
@$(MAKE) -C modules/module5/examples profile
147+
148+
profile-module6:
149+
@echo "Profile build Module 6..."
150+
@$(MAKE) -C modules/module6/examples profile
151+
152+
profile-module7:
153+
@echo "Profile build Module 7..."
154+
@$(MAKE) -C modules/module7/examples profile
155+
156+
profile-module8:
157+
@echo "Profile build Module 8..."
158+
@$(MAKE) -C modules/module8/examples profile
159+
160+
profile-module9:
161+
@echo "Profile build Module 9..."
162+
@$(MAKE) -C modules/module9/examples profile
163+
86164
# Clean all builds
87165
clean:
88166
@echo "Cleaning all modules..."
@@ -193,6 +271,8 @@ help:
193271
@echo " all - Build all available modules"
194272
@echo " clean - Clean all build artifacts"
195273
@echo " test - Run all available tests"
274+
@echo " debug - Build all modules with debug flags"
275+
@echo " profile - Build all modules with profiling flags"
196276
@echo " help - Show this help message"
197277
@echo ""
198278
@echo "Module targets:"

modules/module1/examples/Makefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,52 @@ debug: CUDA_FLAGS = $(CUDA_DEBUG_FLAGS)
185185
debug: HIP_FLAGS = $(HIP_DEBUG_FLAGS)
186186
debug: all
187187

188+
# Profile builds with actual profiling
189+
.PHONY: profile
190+
profile: CUDA_FLAGS += -lineinfo
191+
profile: HIP_FLAGS += -g
192+
profile: all
193+
@echo "Generating profile data..."
194+
@mkdir -p $(PROFILE_DIR)
195+
ifeq ($(BUILD_HIP),1)
196+
@echo "Running HIP profiling..."
197+
@for target in $(HIP_TARGETS); do \
198+
if [ -f $$target ]; then \
199+
echo "Profiling $$target..."; \
200+
rocprofv3 --runtime-trace --output-format csv -d $(PROFILE_DIR) -o $$(basename $$target).csv -- $$target 2>/dev/null || echo "rocprofv3 completed"; \
201+
fi; \
202+
done
203+
endif
204+
ifeq ($(BUILD_CUDA),1)
205+
@echo "Running CUDA profiling..."
206+
@for target in $(CUDA_TARGETS); do \
207+
if [ -f $$target ]; then \
208+
echo "Profiling $$target..."; \
209+
nvprof --csv -o $(PROFILE_DIR)/$$(basename $$target).csv $$target 2>/dev/null || echo "nvprof completed"; \
210+
fi; \
211+
done
212+
endif
213+
@echo "Profile data saved to $(PROFILE_DIR)/"
214+
@ls -la $(PROFILE_DIR)/
215+
188216
# Clean
189217
.PHONY: clean
190218
clean:
191219
@echo "Cleaning build artifacts..."
192220
rm -rf $(BUILD_DIR) $(PROFILE_DIR)
193221

222+
# Test target - run built examples
223+
.PHONY: test
224+
test: all
225+
@echo "Running Module 1 Tests..."
226+
@for target in $(ALL_TARGETS); do \
227+
if [ -f $$target ]; then \
228+
echo "Testing $$target..."; \
229+
$$target || echo "Test completed with exit code $$?"; \
230+
echo ""; \
231+
fi; \
232+
done
233+
194234
# Help
195235
.PHONY: help
196236
help:
@@ -200,5 +240,7 @@ help:
200240
@echo " cuda - Build CUDA examples (requires NVIDIA GPU)"
201241
@echo " hip - Build HIP examples (requires AMD GPU)"
202242
@echo " debug - Build with debug flags"
243+
@echo " profile - Build with profiling flags"
244+
@echo " test - Run all built examples"
203245
@echo " clean - Remove build artifacts"
204246
@echo " help - Show this help message"

modules/module2/examples/Makefile

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,34 @@ debug: CUDA_FLAGS = $(CUDA_DEBUG_FLAGS)
138138
debug: HIP_FLAGS = $(HIP_DEBUG_FLAGS)
139139
debug: all
140140

141+
# Profile builds
142+
.PHONY: profile
143+
profile: CUDA_FLAGS += -lineinfo
144+
profile: HIP_FLAGS += -g
145+
profile: all
146+
@echo "Generating profile data..."
147+
@mkdir -p $(PROFILE_DIR)
148+
ifeq ($(BUILD_HIP),1)
149+
@echo "Running HIP profiling..."
150+
@for target in $(HIP_TARGETS); do \
151+
if [ -f $$target ]; then \
152+
echo "Profiling $$target..."; \
153+
rocprofv3 --runtime-trace --output-format csv -d $(PROFILE_DIR) -o $$(basename $$target).csv -- $$target 2>/dev/null || echo "rocprofv3 completed"; \
154+
fi; \
155+
done
156+
endif
157+
ifeq ($(BUILD_CUDA),1)
158+
@echo "Running CUDA profiling..."
159+
@for target in $(CUDA_TARGETS); do \
160+
if [ -f $$target ]; then \
161+
echo "Profiling $$target..."; \
162+
nvprof --csv -o $(PROFILE_DIR)/$$(basename $$target).csv $$target 2>/dev/null || echo "nvprof completed"; \
163+
fi; \
164+
done
165+
endif
166+
@echo "Profile data saved to $(PROFILE_DIR)/"
167+
@ls -la $(PROFILE_DIR)/
168+
141169
# Clean
142170
.PHONY: clean
143171
clean:
@@ -174,15 +202,15 @@ test_cuda: cuda
174202
@if command -v nvidia-smi > /dev/null; then \
175203
echo "=== Testing Advanced Memory Management Examples ==="; \
176204
echo "1. Shared Memory Transpose..."; \
177-
./01_shared_memory_transpose_cuda || echo "✗ Shared memory transpose failed"; \
205+
$(BUILD_DIR)/01_shared_memory_transpose_cuda || echo "✗ Shared memory transpose failed"; \
178206
echo "2. Memory Coalescing Analysis..."; \
179-
./02_memory_coalescing_cuda || echo "✗ Memory coalescing failed"; \
207+
$(BUILD_DIR)/02_memory_coalescing_cuda || echo "✗ Memory coalescing failed"; \
180208
echo "3. Texture Memory Examples..."; \
181-
./03_texture_memory_cuda || echo "✗ Texture memory failed"; \
209+
$(BUILD_DIR)/03_texture_memory_cuda || echo "✗ Texture memory failed"; \
182210
echo "4. Unified Memory Examples..."; \
183-
./04_unified_memory_cuda || echo "✗ Unified memory failed"; \
211+
$(BUILD_DIR)/04_unified_memory_cuda || echo "✗ Unified memory failed"; \
184212
echo "5. Bandwidth Optimization..."; \
185-
./05_memory_bandwidth_optimization_cuda || echo "✗ Bandwidth optimization failed"; \
213+
$(BUILD_DIR)/05_memory_bandwidth_optimization_cuda || echo "✗ Bandwidth optimization failed"; \
186214
echo "✓ Module 2 CUDA tests completed"; \
187215
else \
188216
echo "No NVIDIA GPU detected, skipping CUDA tests"; \
@@ -193,9 +221,9 @@ test_hip: hip
193221
@if command -v rocm-smi > /dev/null || command -v nvidia-smi > /dev/null; then \
194222
echo "=== Testing HIP Memory Examples ==="; \
195223
echo "1. Shared Memory Transpose..."; \
196-
./01_shared_memory_transpose_hip || echo "✗ HIP shared memory transpose failed"; \
224+
$(BUILD_DIR)/01_shared_memory_transpose_hip || echo "✗ HIP shared memory transpose failed"; \
197225
echo "2. Memory Coalescing Analysis..."; \
198-
./02_memory_coalescing_hip || echo "✗ HIP memory coalescing failed"; \
226+
$(BUILD_DIR)/02_memory_coalescing_hip || echo "✗ HIP memory coalescing failed"; \
199227
echo "✓ Module 2 HIP tests completed"; \
200228
else \
201229
echo "No compatible GPU detected, skipping HIP tests"; \

modules/module3/examples/Makefile

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ endif
5454
# Add detected GPU architecture to HIP flags
5555
HIP_FLAGS += --offload-arch=$(GPU_ARCH)
5656
HIP_DEBUG_FLAGS += --offload-arch=$(GPU_ARCH)
57+
58+
# ROCm library linking for advanced examples
59+
HIP_LIB_DIR := $(ROCM_PATH)/lib
60+
HIP_LDFLAGS := -L$(HIP_LIB_DIR) -lrocblas -Wl,-rpath,$(HIP_LIB_DIR)
61+
5762
CXX_FLAGS = -std=c++17 -O2
5863

5964
# Directories
@@ -129,7 +134,7 @@ endif
129134
ifeq ($(BUILD_HIP),1)
130135
$(BUILD_DIR)/%_hip: $(EXAMPLES_DIR)/%_hip.cpp
131136
@echo "Building HIP example: $@"
132-
$(HIPCC) $(HIP_FLAGS) $< -o $@
137+
$(HIPCC) $(HIP_FLAGS) $< -o $@ $(HIP_LDFLAGS)
133138
endif
134139

135140
# Debug builds
@@ -138,6 +143,32 @@ debug: CUDA_FLAGS = $(CUDA_DEBUG_FLAGS)
138143
debug: HIP_FLAGS = $(HIP_DEBUG_FLAGS)
139144
debug: all
140145

146+
# Profile builds
147+
.PHONY: profile
148+
profile: CUDA_FLAGS += -lineinfo
149+
profile: HIP_FLAGS += -g
150+
profile: all
151+
@echo "Generating profile data..."
152+
@mkdir -p $(PROFILE_DIR)
153+
ifeq ($(BUILD_HIP),1)
154+
@echo "Running HIP profiling..."
155+
@for target in $(HIP_TARGETS); do \
156+
if [ -f $$target ]; then \
157+
echo "Profiling $$target..."; \
158+
rocprofv3 --runtime-trace --output-format csv -d $(PROFILE_DIR) -o $$(basename $$target).csv -- $$target 2>/dev/null || echo "rocprofv3 completed"; \
159+
fi; \
160+
done
161+
endif
162+
ifeq ($(BUILD_CUDA),1)
163+
@echo "Running CUDA profiling..."
164+
@for target in $(CUDA_TARGETS); do \
165+
if [ -f $$target ]; then \
166+
echo "Profiling $$target..."; \
167+
nvprof --csv -o $(PROFILE_DIR)/$$(basename $$target).csv $$target 2>/dev/null || echo "nvprof completed"; \
168+
fi; \
169+
done
170+
endif
171+
141172
# Clean\n.PHONY: clean\nclean:\n\t@echo \"Cleaning build artifacts...\"\n\trm -rf $(BUILD_DIR) $(PROFILE_DIR)
142173

143174
# Help
@@ -172,19 +203,19 @@ test_cuda: cuda
172203
@if command -v nvidia-smi > /dev/null; then \
173204
echo "=== Testing Advanced Algorithm Examples ==="; \
174205
echo "1. Reduction Algorithms..."; \
175-
./01_reduction_algorithms_cuda || echo "✗ Reduction algorithms failed"; \
206+
$(BUILD_DIR)/01_reduction_algorithms_cuda || echo "✗ Reduction algorithms failed"; \
176207
echo "2. Scan (Prefix Sum)..."; \
177-
./02_scan_prefix_sum_cuda || echo "✗ Scan algorithms failed"; \
208+
$(BUILD_DIR)/02_scan_prefix_sum_cuda || echo "✗ Scan algorithms failed"; \
178209
echo "3. Sorting Algorithms..."; \
179-
./03_sorting_algorithms_cuda || echo "✗ Sorting algorithms failed"; \
210+
$(BUILD_DIR)/03_sorting_algorithms_cuda || echo "✗ Sorting algorithms failed"; \
180211
echo "4. Convolution/Stencil..."; \
181-
./04_convolution_stencil_cuda || echo "✗ Convolution failed"; \
212+
$(BUILD_DIR)/04_convolution_stencil_cuda || echo "✗ Convolution failed"; \
182213
echo "5. Matrix Operations..."; \
183-
./05_matrix_operations_cuda || echo "✗ Matrix operations failed"; \
214+
$(BUILD_DIR)/05_matrix_operations_cuda || echo "✗ Matrix operations failed"; \
184215
echo "6. Graph Algorithms..."; \
185-
./06_graph_algorithms_cuda || echo "✗ Graph algorithms failed"; \
216+
$(BUILD_DIR)/06_graph_algorithms_cuda || echo "✗ Graph algorithms failed"; \
186217
echo "7. Cooperative Groups..."; \
187-
./07_cooperative_groups_cuda || echo "✗ Cooperative groups failed"; \
218+
$(BUILD_DIR)/07_cooperative_groups_cuda || echo "✗ Cooperative groups failed"; \
188219
echo "✓ Module 3 CUDA tests completed"; \
189220
else \
190221
echo "No NVIDIA GPU detected, skipping CUDA tests"; \
@@ -195,13 +226,13 @@ test_hip: hip
195226
@if command -v rocm-smi > /dev/null || command -v nvidia-smi > /dev/null; then \
196227
echo "=== Testing HIP Algorithm Examples ==="; \
197228
echo "1. Reduction Algorithms..."; \
198-
./01_reduction_algorithms_hip || echo "✗ HIP reduction algorithms failed"; \
229+
$(BUILD_DIR)/01_reduction_algorithms_hip || echo "✗ HIP reduction algorithms failed"; \
199230
echo "2. Scan (Prefix Sum)..."; \
200-
./02_scan_prefix_sum_hip || echo "✗ HIP scan algorithms failed"; \
231+
$(BUILD_DIR)/02_scan_prefix_sum_hip || echo "✗ HIP scan algorithms failed"; \
201232
echo "3. Sorting Algorithms..."; \
202-
./03_sorting_algorithms_hip || echo "✗ HIP sorting algorithms failed"; \
233+
$(BUILD_DIR)/03_sorting_algorithms_hip || echo "✗ HIP sorting algorithms failed"; \
203234
echo "4. Convolution/Stencil..."; \
204-
./04_convolution_stencil_hip || echo "✗ HIP convolution failed"; \
235+
$(BUILD_DIR)/04_convolution_stencil_hip || echo "✗ HIP convolution failed"; \
205236
echo "✓ Module 3 HIP tests completed"; \
206237
else \
207238
echo "No compatible GPU detected, skipping HIP tests"; \

0 commit comments

Comments
 (0)