@@ -185,11 +185,47 @@ debug: CUDA_FLAGS = $(CUDA_DEBUG_FLAGS)
185185debug : HIP_FLAGS = $(HIP_DEBUG_FLAGS )
186186debug : all
187187
188- # Profile builds
188+ # Profile builds - build with profiling flags and generate profile data
189189.PHONY : profile
190190profile : CUDA_FLAGS = $(CUDA_FLAGS ) -lineinfo
191191profile : HIP_FLAGS = $(HIP_FLAGS ) -g
192192profile : all
193+ @echo " Generating profile data..."
194+ @mkdir -p $(PROFILE_DIR )
195+ ifeq ($(BUILD_CUDA ) ,1)
196+ @echo "Running CUDA profiling..."
197+ @for target in $(CUDA_TARGETS); do \
198+ if [ -f $$target ]; then \
199+ echo "Profiling $$target..."; \
200+ basename_target=$$(basename $$target); \
201+ if command -v nsys >/dev/null 2>&1; then \
202+ nsys profile --output=$(PROFILE_DIR)/$$basename_target.nsys-rep $$target 2>/dev/null || echo "nsys profiling completed"; \
203+ elif command -v nvprof >/dev/null 2>&1; then \
204+ nvprof --log-file $(PROFILE_DIR)/$$basename_target.nvprof $$target 2>/dev/null || echo "nvprof profiling completed"; \
205+ else \
206+ echo "No CUDA profiler available (nsys/nvprof)"; \
207+ fi; \
208+ fi; \
209+ done
210+ endif
211+ ifeq ($(BUILD_HIP ) ,1)
212+ @echo "Running HIP profiling..."
213+ @for target in $(HIP_TARGETS) $(CPP_TARGETS); do \
214+ if [ -f $$target ]; then \
215+ echo "Profiling $$target..."; \
216+ basename_target=$$(basename $$target); \
217+ if command -v rocprof >/dev/null 2>&1; then \
218+ rocprof --output-file $(PROFILE_DIR)/$$basename_target.csv $$target 2>/dev/null || echo "rocprof profiling completed"; \
219+ else \
220+ echo "rocprof not available - saving timing data instead"; \
221+ echo "Profiling $$target at $$(date)" > $(PROFILE_DIR)/$$basename_target.profile; \
222+ time $$target >> $(PROFILE_DIR)/$$basename_target.profile 2>&1 || echo "Timing completed"; \
223+ fi; \
224+ fi; \
225+ done
226+ endif
227+ @echo "Profile data saved to $(PROFILE_DIR)/"
228+ @ls -la $(PROFILE_DIR)/ 2>/dev/null || echo "Profile directory created but no files generated"
193229
194230# Clean
195231.PHONY : clean
0 commit comments