Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 81 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Builds all available modules and examples

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

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

# Debug builds for all modules
debug: debug-module1 debug-module2 debug-module3 debug-module4 debug-module5 debug-module6 debug-module7 debug-module8 debug-module9

debug-module1:
@echo "Debug build Module 1..."
@$(MAKE) -C modules/module1/examples debug

debug-module2:
@echo "Debug build Module 2..."
@$(MAKE) -C modules/module2/examples debug

debug-module3:
@echo "Debug build Module 3..."
@$(MAKE) -C modules/module3/examples debug

debug-module4:
@echo "Debug build Module 4..."
@$(MAKE) -C modules/module4/examples debug

debug-module5:
@echo "Debug build Module 5..."
@$(MAKE) -C modules/module5/examples debug

debug-module6:
@echo "Debug build Module 6..."
@$(MAKE) -C modules/module6/examples debug

debug-module7:
@echo "Debug build Module 7..."
@$(MAKE) -C modules/module7/examples debug

debug-module8:
@echo "Debug build Module 8..."
@$(MAKE) -C modules/module8/examples debug

debug-module9:
@echo "Debug build Module 9..."
@$(MAKE) -C modules/module9/examples debug

# Profile builds for all modules
profile: profile-module1 profile-module2 profile-module3 profile-module4 profile-module5 profile-module6 profile-module7 profile-module8 profile-module9

profile-module1:
@echo "Profile build Module 1..."
@$(MAKE) -C modules/module1/examples profile

profile-module2:
@echo "Profile build Module 2..."
@$(MAKE) -C modules/module2/examples profile

profile-module3:
@echo "Profile build Module 3..."
@$(MAKE) -C modules/module3/examples profile

profile-module4:
@echo "Profile build Module 4..."
@$(MAKE) -C modules/module4/examples profile

profile-module5:
@echo "Profile build Module 5..."
@$(MAKE) -C modules/module5/examples profile

profile-module6:
@echo "Profile build Module 6..."
@$(MAKE) -C modules/module6/examples profile

profile-module7:
@echo "Profile build Module 7..."
@$(MAKE) -C modules/module7/examples profile

profile-module8:
@echo "Profile build Module 8..."
@$(MAKE) -C modules/module8/examples profile

profile-module9:
@echo "Profile build Module 9..."
@$(MAKE) -C modules/module9/examples profile

# Clean all builds
clean:
@echo "Cleaning all modules..."
Expand Down Expand Up @@ -193,6 +271,8 @@ help:
@echo " all - Build all available modules"
@echo " clean - Clean all build artifacts"
@echo " test - Run all available tests"
@echo " debug - Build all modules with debug flags"
@echo " profile - Build all modules with profiling flags"
@echo " help - Show this help message"
@echo ""
@echo "Module targets:"
Expand Down
42 changes: 42 additions & 0 deletions modules/module1/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,52 @@ debug: CUDA_FLAGS = $(CUDA_DEBUG_FLAGS)
debug: HIP_FLAGS = $(HIP_DEBUG_FLAGS)
debug: all

# Profile builds with actual profiling
.PHONY: profile
profile: CUDA_FLAGS += -lineinfo
profile: HIP_FLAGS += -g
profile: all
@echo "Generating profile data..."
@mkdir -p $(PROFILE_DIR)
ifeq ($(BUILD_HIP),1)
@echo "Running HIP profiling..."
@for target in $(HIP_TARGETS); do \
if [ -f $$target ]; then \
echo "Profiling $$target..."; \
rocprofv3 --runtime-trace --output-format csv -d $(PROFILE_DIR) -o $$(basename $$target).csv -- $$target 2>/dev/null || echo "rocprofv3 completed"; \
fi; \
done
endif
ifeq ($(BUILD_CUDA),1)
@echo "Running CUDA profiling..."
@for target in $(CUDA_TARGETS); do \
if [ -f $$target ]; then \
echo "Profiling $$target..."; \
nvprof --csv -o $(PROFILE_DIR)/$$(basename $$target).csv $$target 2>/dev/null || echo "nvprof completed"; \
fi; \
done
endif
@echo "Profile data saved to $(PROFILE_DIR)/"
@ls -la $(PROFILE_DIR)/

# Clean
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
rm -rf $(BUILD_DIR) $(PROFILE_DIR)

# Test target - run built examples
.PHONY: test
test: all
@echo "Running Module 1 Tests..."
@for target in $(ALL_TARGETS); do \
if [ -f $$target ]; then \
echo "Testing $$target..."; \
$$target || echo "Test completed with exit code $$?"; \
echo ""; \
fi; \
done

# Help
.PHONY: help
help:
Expand All @@ -200,5 +240,7 @@ help:
@echo " cuda - Build CUDA examples (requires NVIDIA GPU)"
@echo " hip - Build HIP examples (requires AMD GPU)"
@echo " debug - Build with debug flags"
@echo " profile - Build with profiling flags"
@echo " test - Run all built examples"
@echo " clean - Remove build artifacts"
@echo " help - Show this help message"
42 changes: 35 additions & 7 deletions modules/module2/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,34 @@ debug: CUDA_FLAGS = $(CUDA_DEBUG_FLAGS)
debug: HIP_FLAGS = $(HIP_DEBUG_FLAGS)
debug: all

# Profile builds
.PHONY: profile
profile: CUDA_FLAGS += -lineinfo
profile: HIP_FLAGS += -g
profile: all
@echo "Generating profile data..."
@mkdir -p $(PROFILE_DIR)
ifeq ($(BUILD_HIP),1)
@echo "Running HIP profiling..."
@for target in $(HIP_TARGETS); do \
if [ -f $$target ]; then \
echo "Profiling $$target..."; \
rocprofv3 --runtime-trace --output-format csv -d $(PROFILE_DIR) -o $$(basename $$target).csv -- $$target 2>/dev/null || echo "rocprofv3 completed"; \
fi; \
done
endif
ifeq ($(BUILD_CUDA),1)
@echo "Running CUDA profiling..."
@for target in $(CUDA_TARGETS); do \
if [ -f $$target ]; then \
echo "Profiling $$target..."; \
nvprof --csv -o $(PROFILE_DIR)/$$(basename $$target).csv $$target 2>/dev/null || echo "nvprof completed"; \
fi; \
done
endif
@echo "Profile data saved to $(PROFILE_DIR)/"
@ls -la $(PROFILE_DIR)/

# Clean
.PHONY: clean
clean:
Expand Down Expand Up @@ -174,15 +202,15 @@ test_cuda: cuda
@if command -v nvidia-smi > /dev/null; then \
echo "=== Testing Advanced Memory Management Examples ==="; \
echo "1. Shared Memory Transpose..."; \
./01_shared_memory_transpose_cuda || echo "βœ— Shared memory transpose failed"; \
$(BUILD_DIR)/01_shared_memory_transpose_cuda || echo "βœ— Shared memory transpose failed"; \
echo "2. Memory Coalescing Analysis..."; \
./02_memory_coalescing_cuda || echo "βœ— Memory coalescing failed"; \
$(BUILD_DIR)/02_memory_coalescing_cuda || echo "βœ— Memory coalescing failed"; \
echo "3. Texture Memory Examples..."; \
./03_texture_memory_cuda || echo "βœ— Texture memory failed"; \
$(BUILD_DIR)/03_texture_memory_cuda || echo "βœ— Texture memory failed"; \
echo "4. Unified Memory Examples..."; \
./04_unified_memory_cuda || echo "βœ— Unified memory failed"; \
$(BUILD_DIR)/04_unified_memory_cuda || echo "βœ— Unified memory failed"; \
echo "5. Bandwidth Optimization..."; \
./05_memory_bandwidth_optimization_cuda || echo "βœ— Bandwidth optimization failed"; \
$(BUILD_DIR)/05_memory_bandwidth_optimization_cuda || echo "βœ— Bandwidth optimization failed"; \
echo "βœ“ Module 2 CUDA tests completed"; \
else \
echo "No NVIDIA GPU detected, skipping CUDA tests"; \
Expand All @@ -193,9 +221,9 @@ test_hip: hip
@if command -v rocm-smi > /dev/null || command -v nvidia-smi > /dev/null; then \
echo "=== Testing HIP Memory Examples ==="; \
echo "1. Shared Memory Transpose..."; \
./01_shared_memory_transpose_hip || echo "βœ— HIP shared memory transpose failed"; \
$(BUILD_DIR)/01_shared_memory_transpose_hip || echo "βœ— HIP shared memory transpose failed"; \
echo "2. Memory Coalescing Analysis..."; \
./02_memory_coalescing_hip || echo "βœ— HIP memory coalescing failed"; \
$(BUILD_DIR)/02_memory_coalescing_hip || echo "βœ— HIP memory coalescing failed"; \
echo "βœ“ Module 2 HIP tests completed"; \
else \
echo "No compatible GPU detected, skipping HIP tests"; \
Expand Down
55 changes: 43 additions & 12 deletions modules/module3/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ endif
# Add detected GPU architecture to HIP flags
HIP_FLAGS += --offload-arch=$(GPU_ARCH)
HIP_DEBUG_FLAGS += --offload-arch=$(GPU_ARCH)

# ROCm library linking for advanced examples
HIP_LIB_DIR := $(ROCM_PATH)/lib
HIP_LDFLAGS := -L$(HIP_LIB_DIR) -lrocblas -Wl,-rpath,$(HIP_LIB_DIR)

CXX_FLAGS = -std=c++17 -O2

# Directories
Expand Down Expand Up @@ -129,7 +134,7 @@ endif
ifeq ($(BUILD_HIP),1)
$(BUILD_DIR)/%_hip: $(EXAMPLES_DIR)/%_hip.cpp
@echo "Building HIP example: $@"
$(HIPCC) $(HIP_FLAGS) $< -o $@
$(HIPCC) $(HIP_FLAGS) $< -o $@ $(HIP_LDFLAGS)
endif

# Debug builds
Expand All @@ -138,6 +143,32 @@ debug: CUDA_FLAGS = $(CUDA_DEBUG_FLAGS)
debug: HIP_FLAGS = $(HIP_DEBUG_FLAGS)
debug: all

# Profile builds
.PHONY: profile
profile: CUDA_FLAGS += -lineinfo
profile: HIP_FLAGS += -g
profile: all
@echo "Generating profile data..."
@mkdir -p $(PROFILE_DIR)
ifeq ($(BUILD_HIP),1)
@echo "Running HIP profiling..."
@for target in $(HIP_TARGETS); do \
if [ -f $$target ]; then \
echo "Profiling $$target..."; \
rocprofv3 --runtime-trace --output-format csv -d $(PROFILE_DIR) -o $$(basename $$target).csv -- $$target 2>/dev/null || echo "rocprofv3 completed"; \
fi; \
done
endif
ifeq ($(BUILD_CUDA),1)
@echo "Running CUDA profiling..."
@for target in $(CUDA_TARGETS); do \
if [ -f $$target ]; then \
echo "Profiling $$target..."; \
nvprof --csv -o $(PROFILE_DIR)/$$(basename $$target).csv $$target 2>/dev/null || echo "nvprof completed"; \
fi; \
done
endif

# Clean\n.PHONY: clean\nclean:\n\t@echo \"Cleaning build artifacts...\"\n\trm -rf $(BUILD_DIR) $(PROFILE_DIR)

# Help
Expand Down Expand Up @@ -172,19 +203,19 @@ test_cuda: cuda
@if command -v nvidia-smi > /dev/null; then \
echo "=== Testing Advanced Algorithm Examples ==="; \
echo "1. Reduction Algorithms..."; \
./01_reduction_algorithms_cuda || echo "βœ— Reduction algorithms failed"; \
$(BUILD_DIR)/01_reduction_algorithms_cuda || echo "βœ— Reduction algorithms failed"; \
echo "2. Scan (Prefix Sum)..."; \
./02_scan_prefix_sum_cuda || echo "βœ— Scan algorithms failed"; \
$(BUILD_DIR)/02_scan_prefix_sum_cuda || echo "βœ— Scan algorithms failed"; \
echo "3. Sorting Algorithms..."; \
./03_sorting_algorithms_cuda || echo "βœ— Sorting algorithms failed"; \
$(BUILD_DIR)/03_sorting_algorithms_cuda || echo "βœ— Sorting algorithms failed"; \
echo "4. Convolution/Stencil..."; \
./04_convolution_stencil_cuda || echo "βœ— Convolution failed"; \
$(BUILD_DIR)/04_convolution_stencil_cuda || echo "βœ— Convolution failed"; \
echo "5. Matrix Operations..."; \
./05_matrix_operations_cuda || echo "βœ— Matrix operations failed"; \
$(BUILD_DIR)/05_matrix_operations_cuda || echo "βœ— Matrix operations failed"; \
echo "6. Graph Algorithms..."; \
./06_graph_algorithms_cuda || echo "βœ— Graph algorithms failed"; \
$(BUILD_DIR)/06_graph_algorithms_cuda || echo "βœ— Graph algorithms failed"; \
echo "7. Cooperative Groups..."; \
./07_cooperative_groups_cuda || echo "βœ— Cooperative groups failed"; \
$(BUILD_DIR)/07_cooperative_groups_cuda || echo "βœ— Cooperative groups failed"; \
echo "βœ“ Module 3 CUDA tests completed"; \
else \
echo "No NVIDIA GPU detected, skipping CUDA tests"; \
Expand All @@ -195,13 +226,13 @@ test_hip: hip
@if command -v rocm-smi > /dev/null || command -v nvidia-smi > /dev/null; then \
echo "=== Testing HIP Algorithm Examples ==="; \
echo "1. Reduction Algorithms..."; \
./01_reduction_algorithms_hip || echo "βœ— HIP reduction algorithms failed"; \
$(BUILD_DIR)/01_reduction_algorithms_hip || echo "βœ— HIP reduction algorithms failed"; \
echo "2. Scan (Prefix Sum)..."; \
./02_scan_prefix_sum_hip || echo "βœ— HIP scan algorithms failed"; \
$(BUILD_DIR)/02_scan_prefix_sum_hip || echo "βœ— HIP scan algorithms failed"; \
echo "3. Sorting Algorithms..."; \
./03_sorting_algorithms_hip || echo "βœ— HIP sorting algorithms failed"; \
$(BUILD_DIR)/03_sorting_algorithms_hip || echo "βœ— HIP sorting algorithms failed"; \
echo "4. Convolution/Stencil..."; \
./04_convolution_stencil_hip || echo "βœ— HIP convolution failed"; \
$(BUILD_DIR)/04_convolution_stencil_hip || echo "βœ— HIP convolution failed"; \
echo "βœ“ Module 3 HIP tests completed"; \
else \
echo "No compatible GPU detected, skipping HIP tests"; \
Expand Down
Loading