-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
654 lines (594 loc) · 24.6 KB
/
Copy pathMakefile
File metadata and controls
654 lines (594 loc) · 24.6 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
# Module 8: Domain-Specific Applications
# Makefile for real-world GPU application examples
# Compiler settings
NVCC = nvcc
HIPCC = hipcc
# GPU vendor detection
NVIDIA_GPU := $(shell nvidia-smi > /dev/null 2>&1 && echo 1 || echo 0)
AMD_GPU := $(shell rocm-smi > /dev/null 2>&1 && echo 1 || echo 0)
# Determine build target based on GPU vendor
ifeq ($(NVIDIA_GPU),1)
BUILD_CUDA = 1
BUILD_HIP = 0
GPU_VENDOR = NVIDIA
else ifeq ($(AMD_GPU),1)
BUILD_CUDA = 0
BUILD_HIP = 1
GPU_VENDOR = AMD
else
BUILD_CUDA = 0
BUILD_HIP = 0
GPU_VENDOR = NONE
endif
# Compiler flags for professional-quality applications
CUDA_FLAGS = -std=c++17 -O3 -arch=sm_70 -lineinfo --use_fast_math
CUDA_DEBUG_FLAGS = -std=c++17 -g -G -arch=sm_70
HIP_FLAGS = -std=c++17 -O3 -ffast-math
HIP_DEBUG_FLAGS = -std=c++17 -g
# Library flags for domain-specific libraries
CUDA_LIBS = -lcublas -lcurand -lcufft
# Check for optional ROC libraries and set flags accordingly
# Only check for libraries if not cleaning and pkg-config is available
ifneq ($(MAKECMDGOALS),clean)
PKG_CONFIG_AVAILABLE := $(shell command -v pkg-config >/dev/null 2>&1 && echo 1 || echo 0)
ifeq ($(PKG_CONFIG_AVAILABLE),1)
HAS_ROCBLAS := $(shell pkg-config --exists rocblas && echo 1 || echo 0)
HAS_ROCRAND := $(shell pkg-config --exists rocrand && echo 1 || echo 0)
HAS_ROCFFT := $(shell pkg-config --exists rocfft && echo 1 || echo 0)
HAS_MIOPEN := $(shell pkg-config --exists MIOpen && echo 1 || echo 0)
else
HAS_ROCBLAS := 0
HAS_ROCRAND := 0
HAS_ROCFFT := 0
HAS_MIOPEN := 0
endif
else
HAS_ROCBLAS := 0
HAS_ROCRAND := 0
HAS_ROCFFT := 0
HAS_MIOPEN := 0
endif
# Build HIP_LIBS conditionally
HIP_LIBS =
# ROCm path detection for ROCm 7 compatibility
ROCM_PATH ?= $(shell ls -d /opt/rocm-7.0.0 2>/dev/null || ls -d /opt/rocm* 2>/dev/null | head -1)
# Add ROCm include path and rocThrust if available
ifneq ($(ROCM_PATH),)
HIP_FLAGS += -I$(ROCM_PATH)/include
# Check if rocThrust is available
HAS_ROCTHRUST := $(shell test -d $(ROCM_PATH)/include/thrust && echo 1 || echo 0)
ifeq ($(HAS_ROCTHRUST),1)
HIP_FLAGS += -DHAS_ROCTHRUST
endif
endif
ifeq ($(HAS_ROCBLAS),1)
HIP_LIBS += -lrocblas
HIP_FLAGS += -DHAS_ROCBLAS
endif
ifeq ($(HAS_ROCRAND),1)
HIP_LIBS += -lrocrand
HIP_FLAGS += -DHAS_ROCRAND
endif
ifeq ($(HAS_ROCFFT),1)
HIP_LIBS += -lrocfft
HIP_FLAGS += -DHAS_ROCFFT
endif
ifeq ($(HAS_MIOPEN),1)
HIP_LIBS += -lMIOpen
HIP_FLAGS += -DHAS_MIOPEN
endif
# Set compilation flag if any ROC libraries are available
ifneq ($(HIP_LIBS),)
HIP_FLAGS += -DHAS_ROC_LIBRARIES
endif
# Directories
BUILD_DIR = build
PROFILE_DIR = profiles
DATA_DIR = data
# Source files
CUDA_SOURCES = $(wildcard *_cuda.cu)
HIP_SOURCES = $(wildcard *_hip.cpp)
# Target executables based on GPU vendor
ifeq ($(BUILD_CUDA),1)
ACTIVE_TARGETS = $(CUDA_SOURCES:%.cu=$(BUILD_DIR)/%)
ACTIVE_SOURCES = $(CUDA_SOURCES)
COMPILER = $(NVCC)
COMPILE_FLAGS = $(CUDA_FLAGS)
else ifeq ($(BUILD_HIP),1)
ACTIVE_TARGETS = $(HIP_SOURCES:%.cpp=$(BUILD_DIR)/%)
ACTIVE_SOURCES = $(HIP_SOURCES)
COMPILER = $(HIPCC)
COMPILE_FLAGS = $(HIP_FLAGS)
else
ACTIVE_TARGETS =
ACTIVE_SOURCES =
endif
# Legacy target definitions (for compatibility)
CUDA_TARGETS = $(CUDA_SOURCES:%.cu=$(BUILD_DIR)/%)
HIP_TARGETS = $(HIP_SOURCES:%.cpp=$(BUILD_DIR)/%)
# Default target
.PHONY: all
all: setup $(ACTIVE_TARGETS)
# Setup directories
.PHONY: setup
setup:
@mkdir -p $(BUILD_DIR)
@mkdir -p $(PROFILE_DIR)
@mkdir -p $(DATA_DIR)
ifeq ($(GPU_VENDOR),NVIDIA)
@echo "✓ NVIDIA GPU detected - building CUDA examples"
else ifeq ($(GPU_VENDOR),AMD)
@echo "✓ AMD GPU detected - building HIP examples"
else
@echo "⚠ No compatible GPU detected - no examples will be built"
endif
# Build CUDA examples (if NVIDIA GPU detected)
.PHONY: cuda
ifeq ($(BUILD_CUDA),1)
cuda: setup $(CUDA_TARGETS)
else
cuda: setup
@echo "⚠ CUDA build requested but no NVIDIA GPU detected"
endif
# Build HIP examples (if AMD GPU detected)
.PHONY: hip
ifeq ($(BUILD_HIP),1)
hip: setup $(HIP_TARGETS)
else
hip: setup
@echo "⚠ HIP build requested but no AMD GPU detected"
endif
# Vendor-specific compilation rules
ifeq ($(BUILD_CUDA),1)
$(BUILD_DIR)/%_cuda: %_cuda.cu
@echo "Building CUDA domain application: $@"
$(NVCC) $(CUDA_FLAGS) $< -o $@ $(CUDA_LIBS)
endif
ifeq ($(BUILD_HIP),1)
$(BUILD_DIR)/%_hip: %_hip.cpp
@echo "Building HIP domain application: $@"
$(HIPCC) $(HIP_FLAGS) $< -o $@ $(HIP_LIBS)
endif
# Legacy compilation rules (for compatibility with explicit targets)
$(BUILD_DIR)/%_cuda: %_cuda.cu
@echo "Building CUDA domain application: $@"
$(NVCC) $(CUDA_FLAGS) $< -o $@ $(CUDA_LIBS)
$(BUILD_DIR)/%_hip: %_hip.cpp
@echo "Building HIP domain application: $@"
$(HIPCC) $(HIP_FLAGS) $< -o $@ $(HIP_LIBS)
# Debug builds
.PHONY: debug
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..."; \
nsys profile --cuda-event-trace=false -o $(PROFILE_DIR)/$$(basename $$target).nsys-rep $$target 2>/dev/null || echo "nsys completed"; \
fi; \
done
endif
# Professional builds with maximum optimization
.PHONY: production
production: CUDA_FLAGS += -DNDEBUG -Xptxas -O3
production: HIP_FLAGS += -DNDEBUG
production: all
# Domain-specific application targets
.PHONY: deep_learning
deep_learning: setup
ifeq ($(BUILD_CUDA),1)
@if [ -f 01_deep_learning_cuda.cu ]; then $(NVCC) $(CUDA_FLAGS) 01_deep_learning_cuda.cu -o $(BUILD_DIR)/01_deep_learning_cuda $(CUDA_LIBS); fi
endif
ifeq ($(BUILD_HIP),1)
@if [ -f 01_deep_learning_hip.cpp ]; then $(HIPCC) $(HIP_FLAGS) 01_deep_learning_hip.cpp -o $(BUILD_DIR)/01_deep_learning_hip $(HIP_LIBS); fi
endif
.PHONY: scientific
scientific: setup
ifeq ($(BUILD_CUDA),1)
@if [ -f 02_scientific_computing_cuda.cu ]; then $(NVCC) $(CUDA_FLAGS) 02_scientific_computing_cuda.cu -o $(BUILD_DIR)/02_scientific_computing_cuda $(CUDA_LIBS); fi
endif
ifeq ($(BUILD_HIP),1)
@if [ -f 02_scientific_computing_hip.cpp ]; then $(HIPCC) $(HIP_FLAGS) 02_scientific_computing_hip.cpp -o $(BUILD_DIR)/02_scientific_computing_hip $(HIP_LIBS); fi
endif
.PHONY: image_processing
image_processing: setup
ifeq ($(BUILD_CUDA),1)
@if [ -f 03_image_signal_processing_cuda.cu ]; then $(NVCC) $(CUDA_FLAGS) 03_image_signal_processing_cuda.cu -o $(BUILD_DIR)/03_image_signal_processing_cuda $(CUDA_LIBS); fi
endif
ifeq ($(BUILD_HIP),1)
@if [ -f 03_image_signal_processing_hip.cpp ]; then $(HIPCC) $(HIP_FLAGS) 03_image_signal_processing_hip.cpp -o $(BUILD_DIR)/03_image_signal_processing_hip $(HIP_LIBS); fi
endif
.PHONY: monte_carlo
monte_carlo: setup
ifeq ($(BUILD_CUDA),1)
@if [ -f 04_monte_carlo_cuda.cu ]; then $(NVCC) $(CUDA_FLAGS) 04_monte_carlo_cuda.cu -o $(BUILD_DIR)/04_monte_carlo_cuda $(CUDA_LIBS); fi
endif
ifeq ($(BUILD_HIP),1)
@if [ -f 04_monte_carlo_hip.cpp ]; then $(HIPCC) $(HIP_FLAGS) 04_monte_carlo_hip.cpp -o $(BUILD_DIR)/04_monte_carlo_hip $(HIP_LIBS); fi
endif
.PHONY: finance
finance: setup
ifeq ($(BUILD_CUDA),1)
@if [ -f 05_computational_finance_cuda.cu ]; then $(NVCC) $(CUDA_FLAGS) 05_computational_finance_cuda.cu -o $(BUILD_DIR)/05_computational_finance_cuda $(CUDA_LIBS); fi
endif
ifeq ($(BUILD_HIP),1)
@if [ -f 05_computational_finance_hip.cpp ]; then $(HIPCC) $(HIP_FLAGS) 05_computational_finance_hip.cpp -o $(BUILD_DIR)/05_computational_finance_hip $(HIP_LIBS); fi
endif
.PHONY: library_integration
library_integration: setup
ifeq ($(BUILD_CUDA),1)
@if [ -f 06_library_integration_cuda.cu ]; then $(NVCC) $(CUDA_FLAGS) 06_library_integration_cuda.cu -o $(BUILD_DIR)/06_library_integration_cuda $(CUDA_LIBS); fi
endif
ifeq ($(BUILD_HIP),1)
@if [ -f 06_library_integration_hip.cpp ]; then $(HIPCC) $(HIP_FLAGS) 06_library_integration_hip.cpp -o $(BUILD_DIR)/06_library_integration_hip $(HIP_LIBS); fi
endif
@if [ -f 06_library_integration_hip.cpp ]; then $(HIPCC) $(HIP_FLAGS) 06_library_integration_hip.cpp -o $(BUILD_DIR)/06_library_integration_hip $(HIP_LIBS); fi
# Testing targets with domain-specific validation
.PHONY: test
test: all
@echo "Running Module 8 Domain-Specific Application Tests..."
@for target in $(CUDA_TARGETS) $(HIP_TARGETS); do \
if [ -f $$target ]; then \
echo "Testing $$target..."; \
$$target --test-mode; \
echo ""; \
fi; \
done
.PHONY: test_cuda
test_cuda: cuda
@echo "Running CUDA Domain Application Tests..."
@for target in $(CUDA_TARGETS); do \
if [ -f $$target ]; then \
echo "Testing $$target..."; \
$$target --test-mode; \
echo ""; \
fi; \
done
.PHONY: test_hip
test_hip: hip
@echo "Running HIP Domain Application Tests..."
@for target in $(HIP_TARGETS); do \
if [ -f $$target ]; then \
echo "Testing $$target..."; \
$$target --test-mode; \
echo ""; \
fi; \
done
# Domain-specific application tests
.PHONY: test_deep_learning
test_deep_learning: deep_learning
@if [ -f $(BUILD_DIR)/01_deep_learning_cuda ]; then echo "CUDA Deep Learning:"; $(BUILD_DIR)/01_deep_learning_cuda --validation; fi
@if [ -f $(BUILD_DIR)/01_deep_learning_hip ]; then echo "HIP Deep Learning:"; $(BUILD_DIR)/01_deep_learning_hip --validation; fi
.PHONY: test_scientific
test_scientific: scientific
@if [ -f $(BUILD_DIR)/02_scientific_computing_cuda ]; then echo "CUDA Scientific Computing:"; $(BUILD_DIR)/02_scientific_computing_cuda --accuracy-test; fi
@if [ -f $(BUILD_DIR)/02_scientific_computing_hip ]; then echo "HIP Scientific Computing:"; $(BUILD_DIR)/02_scientific_computing_hip --accuracy-test; fi
.PHONY: test_image_processing
test_image_processing: image_processing
@if [ -f $(BUILD_DIR)/03_image_signal_processing_cuda ]; then echo "CUDA Image Processing:"; $(BUILD_DIR)/03_image_signal_processing_cuda --benchmark; fi
@if [ -f $(BUILD_DIR)/03_image_signal_processing_hip ]; then echo "HIP Image Processing:"; $(BUILD_DIR)/03_image_signal_processing_hip --benchmark; fi
.PHONY: test_monte_carlo
test_monte_carlo: monte_carlo
@if [ -f $(BUILD_DIR)/04_monte_carlo_cuda ]; then echo "CUDA Monte Carlo:"; $(BUILD_DIR)/04_monte_carlo_cuda --convergence-test; fi
@if [ -f $(BUILD_DIR)/04_monte_carlo_hip ]; then echo "HIP Monte Carlo:"; $(BUILD_DIR)/04_monte_carlo_hip --convergence-test; fi
.PHONY: test_finance
test_finance: finance
@if [ -f $(BUILD_DIR)/05_computational_finance_cuda ]; then echo "CUDA Computational Finance:"; $(BUILD_DIR)/05_computational_finance_cuda --market-simulation; fi
@if [ -f $(BUILD_DIR)/05_computational_finance_hip ]; then echo "HIP Computational Finance:"; $(BUILD_DIR)/05_computational_finance_hip --market-simulation; fi
# Production validation tests
.PHONY: validate_performance
validate_performance: production
@echo "Validating production performance targets..."
@for target in $(CUDA_TARGETS) $(HIP_TARGETS); do \
if [ -f $$target ]; then \
echo "Performance validation for $$target..."; \
$$target --performance-validation 2>&1 | tee $(PROFILE_DIR)/$$(basename $$target)_performance.txt; \
fi; \
done
.PHONY: validate_accuracy
validate_accuracy: all
@echo "Validating numerical accuracy for domain applications..."
@for target in $(CUDA_TARGETS) $(HIP_TARGETS); do \
if [ -f $$target ]; then \
echo "Accuracy validation for $$target..."; \
$$target --accuracy-validation 2>&1 | tee $(PROFILE_DIR)/$$(basename $$target)_accuracy.txt; \
fi; \
done
# Profiling with domain-specific metrics
.PHONY: profile_cuda
profile_cuda: cuda
@echo "Profiling CUDA domain applications with Nsight Compute..."
@for target in $(CUDA_TARGETS); do \
if [ -f $$target ]; then \
echo "Profiling $$target..."; \
ncu --metrics gpu__time_duration.avg,dram__throughput.avg.pct_of_peak_sustained_elapsed,sm__sass_thread_inst_executed_op_fp32_pred_on.sum,tensor__inst_executed.sum --log-file $(PROFILE_DIR)/$$(basename $$target).ncu-rep $$target --profile-mode; \
fi; \
done
.PHONY: profile_hip
profile_hip: hip
@echo "Profiling HIP domain applications with ROCProfiler..."
@for target in $(HIP_TARGETS); do \
if [ -f $$target ]; then \
echo "Profiling $$target..."; \
rocprof --stats --hsa-trace --output-file $(PROFILE_DIR)/$$(basename $$target).csv $$target --profile-mode; \
fi; \
done
# Comprehensive domain-specific benchmarking
.PHONY: benchmark_all
benchmark_all: production
@echo "Running comprehensive domain application benchmarks..."
@echo "Domain-Specific Applications Benchmark Results" > $(PROFILE_DIR)/domain_benchmark_results.txt
@echo "Generated on: $$(date)" >> $(PROFILE_DIR)/domain_benchmark_results.txt
@echo "=============================================" >> $(PROFILE_DIR)/domain_benchmark_results.txt
@for target in $(CUDA_TARGETS) $(HIP_TARGETS); do \
if [ -f $$target ]; then \
echo ""; \
echo "Benchmarking $$target..." | tee -a $(PROFILE_DIR)/domain_benchmark_results.txt; \
echo "-------------------------------------------" >> $(PROFILE_DIR)/domain_benchmark_results.txt; \
$$target --comprehensive-benchmark | tee -a $(PROFILE_DIR)/domain_benchmark_results.txt; \
echo "" >> $(PROFILE_DIR)/domain_benchmark_results.txt; \
fi; \
done
# Domain-specific benchmarking by category
.PHONY: benchmark_deep_learning
benchmark_deep_learning: deep_learning
@echo "Deep Learning Inference Benchmarks:"
@for target in $(BUILD_DIR)/01_deep_learning_*; do \
if [ -f $$target ]; then \
echo "$$target throughput test:"; \
$$target --throughput-benchmark; \
fi; \
done
.PHONY: benchmark_scientific
benchmark_scientific: scientific
@echo "Scientific Computing Benchmarks:"
@for target in $(BUILD_DIR)/02_scientific_computing_*; do \
if [ -f $$target ]; then \
echo "$$target solver performance:"; \
$$target --solver-benchmark; \
fi; \
done
.PHONY: benchmark_image_processing
benchmark_image_processing: image_processing
@echo "Image Processing Pipeline Benchmarks:"
@for target in $(BUILD_DIR)/03_image_signal_processing_*; do \
if [ -f $$target ]; then \
echo "$$target real-time performance:"; \
$$target --realtime-benchmark; \
fi; \
done
.PHONY: benchmark_monte_carlo
benchmark_monte_carlo: monte_carlo
@echo "Monte Carlo Simulation Benchmarks:"
@for target in $(BUILD_DIR)/04_monte_carlo_*; do \
if [ -f $$target ]; then \
echo "$$target convergence rate:"; \
$$target --convergence-benchmark; \
fi; \
done
.PHONY: benchmark_finance
benchmark_finance: finance
@echo "Computational Finance Benchmarks:"
@for target in $(BUILD_DIR)/05_computational_finance_*; do \
if [ -f $$target ]; then \
echo "$$target latency test:"; \
$$target --latency-benchmark; \
fi; \
done
# Large-scale problem testing
.PHONY: test_large_scale
test_large_scale: production
@echo "Running large-scale domain application tests..."
@for target in $(CUDA_TARGETS) $(HIP_TARGETS); do \
if [ -f $$target ]; then \
echo "Large-scale test for $$target..."; \
$$target --large-scale-test 2>&1 | tee $(PROFILE_DIR)/$$(basename $$target)_large_scale.txt || true; \
fi; \
done
# Multi-GPU scaling tests
.PHONY: test_multi_gpu_scaling
test_multi_gpu_scaling: production
@echo "Testing multi-GPU scaling for domain applications..."
@nvidia-smi --list-gpus | wc -l > $(PROFILE_DIR)/gpu_count.txt || echo "0" > $(PROFILE_DIR)/gpu_count.txt
@for target in $(CUDA_TARGETS) $(HIP_TARGETS); do \
if [ -f $$target ]; then \
echo "Multi-GPU scaling test for $$target..."; \
$$target --multi-gpu-scaling 2>&1 | tee $(PROFILE_DIR)/$$(basename $$target)_multi_gpu.txt || true; \
fi; \
done
# Cross-platform comparison
.PHONY: compare_platforms
compare_platforms: all
@echo "Cross-Platform Performance Comparison for Domain Applications:"
@echo "============================================================"
@for cuda_target in $(CUDA_TARGETS); do \
if [ -f $$cuda_target ]; then \
base_name=$$(basename $$cuda_target _cuda); \
hip_target=$(BUILD_DIR)/$${base_name}_hip; \
if [ -f $$hip_target ]; then \
echo "Comparing $$cuda_target vs $$hip_target"; \
echo "CUDA Performance:"; \
$$cuda_target --platform-benchmark 2>&1 || true; \
echo "HIP Performance:"; \
$$hip_target --platform-benchmark 2>&1 || true; \
echo ""; \
fi; \
fi; \
done
# Domain-specific performance analysis
.PHONY: analyze_performance_targets
analyze_performance_targets:
@echo "Domain-Specific Performance Target Analysis:"
@echo "==========================================="
@echo "Deep Learning:"
@echo " Target: >90% Tensor Core utilization, >1000x CPU speedup"
@echo " Metric: Samples/second, inference latency"
@echo ""
@echo "Scientific Computing:"
@echo " Target: 10-100x CPU speedup, numerical accuracy preservation"
@echo " Metric: Time-to-solution, relative error"
@echo ""
@echo "Image Processing:"
@echo " Target: 30-60 FPS real-time processing"
@echo " Metric: Frame rate, pipeline latency"
@echo ""
@echo "Monte Carlo:"
@echo " Target: 100-1000x CPU speedup, fast convergence"
@echo " Metric: Samples/second, convergence rate"
@echo ""
@echo "Computational Finance:"
@echo " Target: Sub-millisecond latency, high throughput"
@echo " Metric: Transactions/second, latency percentiles"
# Memory and compute analysis
.PHONY: analyze_memory_compute
analyze_memory_compute: all
@echo "Memory-Compute Analysis for Domain Applications:"
@echo "=============================================="
@for target in $(CUDA_TARGETS); do \
if [ -f $$target ]; then \
echo "Analyzing $$target..."; \
cuda-memcheck --tool=memcheck --log-file $(PROFILE_DIR)/$$(basename $$target).memcheck $$target --memory-analysis 2>/dev/null || echo "Memory analysis failed for $$target"; \
fi; \
done
# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
rm -rf $(BUILD_DIR)
rm -rf $(PROFILE_DIR)
rm -rf $(DATA_DIR)
# System requirements check
.PHONY: check_requirements
check_requirements:
@echo "Checking system requirements for domain applications:"
@echo "=================================================="
@echo "GPU Memory Requirements:"
@nvidia-smi --query-gpu=name,memory.total --format=csv,noheader,nounits 2>/dev/null || echo "NVIDIA GPU not detected"
@rocm-smi --showmeminfo vram 2>/dev/null || echo "AMD GPU not detected"
@echo ""
@echo "Library Requirements:"
@echo "CUDA Libraries:"
@ls /usr/local/cuda/lib64/libcublas* 2>/dev/null | head -1 || echo " cuBLAS not found"
@ls /usr/local/cuda/lib64/libcurand* 2>/dev/null | head -1 || echo " cuRAND not found"
@ls /usr/local/cuda/lib64/libcufft* 2>/dev/null | head -1 || echo " cuFFT not found"
@ls /usr/local/cuda/lib64/libcudnn* 2>/dev/null | head -1 || echo " cuDNN not found"
@echo ""
@echo "ROCm Libraries:"
@ls /opt/rocm/lib/librocblas* 2>/dev/null | head -1 || echo " rocBLAS not found"
@ls /opt/rocm/lib/librocrand* 2>/dev/null | head -1 || echo " rocRAND not found"
@ls /opt/rocm/lib/librocfft* 2>/dev/null | head -1 || echo " rocFFT not found"
# Generate comprehensive domain applications report
.PHONY: report
report: benchmark_all profile_cuda profile_hip
@echo "Generating comprehensive domain applications performance report..."
@echo "Module 8: Domain-Specific Applications - Performance Report" > $(PROFILE_DIR)/domain_performance_report.md
@echo "=========================================================" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "## System Information" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "- Date: $$(date)" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "- GPU: $$(nvidia-smi --query-gpu=name --format=csv,noheader,nounits 2>/dev/null || echo 'Unknown')" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "- GPU Memory: $$(nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits 2>/dev/null || echo 'Unknown') MB" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "- CUDA Version: $$(nvcc --version | grep release | awk '{print $$6}' 2>/dev/null || echo 'Not available')" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "## Domain Applications" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "- Deep Learning: Neural network inference with Tensor Core optimization" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "- Scientific Computing: High-precision numerical simulations" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "- Image Processing: Real-time computer vision pipelines" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "- Monte Carlo: Stochastic simulation and risk analysis" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "- Computational Finance: High-frequency trading and risk management" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "- Library Integration: Optimized library usage patterns" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "## Benchmark Results" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "\`\`\`" >> $(PROFILE_DIR)/domain_performance_report.md
@cat $(PROFILE_DIR)/domain_benchmark_results.txt >> $(PROFILE_DIR)/domain_performance_report.md
@echo "\`\`\`" >> $(PROFILE_DIR)/domain_performance_report.md
@echo "Domain applications performance report generated: $(PROFILE_DIR)/domain_performance_report.md"
# System information
.PHONY: system_info
system_info:
@echo "System Information for Module 8:"
@echo "================================="
@echo "CUDA Configuration:"
@if command -v nvcc > /dev/null 2>&1; then \
echo " NVCC Version: $$(nvcc --version | grep release)"; \
echo " GPU Information:"; \
nvidia-smi --query-gpu=name,memory.total,compute_cap --format=csv,noheader,nounits | head -1; \
echo " Tensor Core Support: $$(nvidia-smi --query-gpu=name --format=csv,noheader,nounits | grep -i 'V100\|A100\|RTX' >/dev/null && echo 'Available' || echo 'Not Available')"; \
else \
echo " NVCC not found"; \
fi
@echo ""
@echo "HIP Configuration:"
@if command -v hipcc > /dev/null 2>&1; then \
echo " HIPCC Version: $$(hipcc --version | head -1)"; \
echo " GPU Information:"; \
rocm-smi --showproductname 2>/dev/null | head -3 || echo " ROCm not available"; \
else \
echo " HIPCC not found"; \
fi
# Help target
.PHONY: help
help:
@echo "Module 8: Domain-Specific Applications - Build System"
@echo "=================================================="
@echo ""
@echo "Build Targets:"
@echo " all - Build all CUDA and HIP domain applications"
@echo " cuda - Build CUDA applications only"
@echo " hip - Build HIP applications only"
@echo " debug - Build with debug flags"
@echo " professional - Build with maximum optimization"
@echo " clean - Remove build artifacts"
@echo ""
@echo "Domain Application Targets:"
@echo " deep_learning - Build deep learning inference examples"
@echo " scientific - Build scientific computing examples"
@echo " image_processing - Build image and signal processing examples"
@echo " monte_carlo - Build Monte Carlo simulation examples"
@echo " finance - Build computational finance examples"
@echo " library_integration - Build library integration examples"
@echo ""
@echo "Testing Targets:"
@echo " test - Run all domain application tests"
@echo " test_<domain> - Run specific domain application tests"
@echo " validate_performance - Validate production performance targets"
@echo " validate_accuracy - Validate numerical accuracy"
@echo " test_large_scale - Run large-scale problem tests"
@echo " test_multi_gpu_scaling - Test multi-GPU scaling"
@echo ""
@echo "Benchmarking Targets:"
@echo " benchmark_all - Comprehensive domain application benchmarks"
@echo " benchmark_<domain> - Domain-specific benchmarks"
@echo " compare_platforms - Compare CUDA vs HIP performance"
@echo " analyze_performance_targets - Show domain performance targets"
@echo ""
@echo "Analysis Targets:"
@echo " profile_cuda - Profile with Nsight Compute (domain-specific metrics)"
@echo " profile_hip - Profile with ROCProfiler"
@echo " analyze_memory_compute - Memory and compute analysis"
@echo " check_requirements - Check system requirements"
@echo " report - Generate comprehensive domain performance report"
@echo ""
@echo "Examples:"
@echo " make deep_learning && make test_deep_learning"
@echo " make production && make validate_performance"
@echo " make benchmark_all"
@echo " make report # Complete domain application analysis"