Skip to content

Commit 361cc08

Browse files
committed
cmake changes for overriding flags
1 parent bb98c9b commit 361cc08

File tree

3 files changed

+79
-33
lines changed

3 files changed

+79
-33
lines changed

sobel_filter/CUDA/CMakeLists.txt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,25 @@ set(CMAKE_CXX_EXTENSIONS OFF)
3131

3232
option(USE_SM "Build for specific SM" OFF)
3333

34-
# CMAKE_CXX_FLAGS
35-
if("${CMAKE_CXX_FLAGS}" STREQUAL "")
34+
set(DEF_WL_CXX_FLAGS " -m64 -DUSE_CUDA ")
35+
set(DEF_GENERAL_CXX_FLAGS " -O3 -ffast-math ")
36+
set(DEF_COMBINED_CXX_FLAGS "${DEF_GENERAL_CXX_FLAGS} ${DEF_WL_CXX_FLAGS}")
37+
38+
# -DCMAKE_CXX_FLAGS=" -blah -blah " overrides the default flags (BOTH general and WL specific)
39+
# -DOVERRIDE_GENERAL_CXX_FLAGS=" -blah -blah " overrides the general flags only (and not the workload specific flags)
40+
# passing in both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS is not allowed, in order to prevent ambiguity
41+
42+
if(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "" AND NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
43+
message(FATAL_ERROR "Both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS cannot be passed in together")
44+
elseif("${CMAKE_CXX_FLAGS}" STREQUAL "" AND "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
3645
message(STATUS "Using DEFAULT compilation flags")
37-
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} " -O3 -ffast-math -m64 -DUSE_CUDA ")
38-
else()
39-
message(STATUS "OVERRIDING DEFAULT compilation flags")
46+
set(CMAKE_CXX_FLAGS "${DEF_COMBINED_CXX_FLAGS}")
47+
elseif(NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
48+
message(STATUS "OVERRIDING GENERAL compilation flags")
49+
set(CMAKE_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS}")
50+
string(APPEND CMAKE_CXX_FLAGS ${DEF_WL_CXX_FLAGS})
51+
elseif(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "")
52+
message(STATUS "OVERRIDING GENERAL and WORKLOAD SPECIFIC compilation flags")
4053
endif()
4154

4255
# CUDA_NVCC_FLAGS

sobel_filter/HIP/CMakeLists.txt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,25 @@ set(CMAKE_MODULE_PATH "${ROCM_PATH}/hip/cmake" ${CMAKE_MODULE_PATH})
4040
set(HIP_INCLUDE_DIRS "${ROCM_PATH}/include" ${HIP_INCLUDE_DIRS})
4141
set(HIP_LIBRARIES "${ROCM_PATH}/lib" ${HIP_LIBRARIES})
4242

43-
# CMAKE_CXX_FLAGS
44-
if("${CMAKE_CXX_FLAGS}" STREQUAL "")
45-
message(STATUS "Using DEFAULT compilation flags for the application")
46-
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} " -O3 -std=c++17 -ffast-math -D__HIP_PLATFORM_AMD__ ")
47-
else()
48-
message(STATUS "OVERRIDING compilation flags")
43+
set(DEF_WL_CXX_FLAGS " -D__HIP_PLATFORM_AMD__ ")
44+
set(DEF_GENERAL_CXX_FLAGS " -O3 -std=c++17 -ffast-math ")
45+
set(DEF_COMBINED_CXX_FLAGS "${DEF_GENERAL_CXX_FLAGS} ${DEF_WL_CXX_FLAGS}")
46+
47+
# -DCMAKE_CXX_FLAGS=" -blah -blah " overrides the default flags (BOTH general and WL specific)
48+
# -DOVERRIDE_GENERAL_CXX_FLAGS=" -blah -blah " overrides the general flags only (and not the workload specific flags)
49+
# passing in both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS is not allowed, in order to prevent ambiguity
50+
51+
if(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "" AND NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
52+
message(FATAL_ERROR "Both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS cannot be passed in together")
53+
elseif("${CMAKE_CXX_FLAGS}" STREQUAL "" AND "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
54+
message(STATUS "Using DEFAULT compilation flags")
55+
set(CMAKE_CXX_FLAGS "${DEF_COMBINED_CXX_FLAGS}")
56+
elseif(NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
57+
message(STATUS "OVERRIDING GENERAL compilation flags")
58+
set(CMAKE_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS}")
59+
string(APPEND CMAKE_CXX_FLAGS ${DEF_WL_CXX_FLAGS})
60+
elseif(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "")
61+
message(STATUS "OVERRIDING GENERAL and WORKLOAD SPECIFIC compilation flags")
4962
endif()
5063

5164
find_package(HIP REQUIRED)

sobel_filter/SYCL/CMakeLists.txt

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,51 +35,71 @@ option(USE_NVIDIA_BACKEND "Build for NVIDIA backend" OFF)
3535
option(USE_AMDHIP_BACKEND "Build for AMD HIP backend" OFF)
3636
option(USE_SM "Build for specific SM" OFF)
3737

38-
set(INTEL_GPU_CXX_FLAGS " -O2 -fsycl -Wall -Wextra -Wno-unused-parameter ")
39-
set(NVIDIA_GPU_CXX_FLAGS " -O3 -fsycl -Wall -Wextra -Wno-unused-parameter ")
40-
set(AMD_GPU_CXX_FLAGS " -O3 -fsycl -Wall -Wextra -Wno-unused-parameter ")
38+
set(DEF_INTEL_WL_CXX_FLAGS " ")
39+
set(DEF_NVIDIA_WL_CXX_FLAGS " ")
40+
set(DEF_AMD_WL_CXX_FLAGS " ")
4141

42-
set(USE_DEFAULT_FLAGS ON)
43-
if("${CMAKE_CXX_FLAGS}" STREQUAL "")
42+
set(DEF_INTEL_GENERAL_CXX_FLAGS " -O2 -fsycl -Wall -Wextra -Wno-unused-parameter ")
43+
set(DEF_NVIDIA_GENERAL_CXX_FLAGS " -O3 -fsycl -Wall -Wextra -Wno-unused-parameter ")
44+
set(DEF_AMD_GENERAL_CXX_FLAGS " -O3 -fsycl -Wall -Wextra -Wno-unused-parameter ")
45+
46+
# -DCMAKE_CXX_FLAGS=" -blah -blah " overrides the default flags (BOTH general and WL specific)
47+
# -DOVERRIDE_GENERAL_CXX_FLAGS=" -blah -blah " overrides the general flags only (and not the workload specific flags)
48+
# passing in both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS is not allowed, in order to prevent ambiguity
49+
50+
if(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "" AND NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
51+
message(FATAL_ERROR "Both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS cannot be passed in together")
52+
elseif("${CMAKE_CXX_FLAGS}" STREQUAL "" AND "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
4453
message(STATUS "Using DEFAULT compilation flags")
45-
else()
46-
message(STATUS "Overriding DEFAULT compilation flags")
47-
set(USE_DEFAULT_FLAGS OFF)
54+
set(INTEL_GPU_CXX_FLAGS "${DEF_INTEL_GENERAL_CXX_FLAGS} ${DEF_INTEL_WL_CXX_FLAGS}")
55+
set(NVIDIA_GPU_CXX_FLAGS "${DEF_NVIDIA_GENERAL_CXX_FLAGS} ${DEF_NVIDIA_WL_CXX_FLAGS}")
56+
set(AMD_GPU_CXX_FLAGS "${DEF_AMD_GENERAL_CXX_FLAGS} ${DEF_AMD_WL_CXX_FLAGS}")
57+
elseif(NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
58+
message(STATUS "OVERRIDING GENERAL compilation flags")
59+
set(INTEL_GPU_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS} ${DEF_INTEL_WL_CXX_FLAGS}")
60+
set(NVIDIA_GPU_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS} ${DEF_NVIDIA_WL_CXX_FLAGS}")
61+
set(AMD_GPU_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS} ${DEF_AMD_WL_CXX_FLAGS}")
62+
elseif(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "")
63+
message(STATUS "OVERRIDING GENERAL and WORKLOAD SPECIFIC compilation flags")
64+
set(INTEL_GPU_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
65+
set(NVIDIA_GPU_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
66+
set(AMD_GPU_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
4867
endif()
4968

50-
# AOT compilation
5169
if(GPU_AOT)
5270
message(STATUS "Enabling INTEL backend")
53-
if(USE_DEFAULT_FLAGS)
54-
set(CMAKE_CXX_FLAGS "${INTEL_GPU_CXX_FLAGS}") # Default flags for Intel backend
55-
endif()
56-
if( (${GPU_AOT} STREQUAL "pvc") OR (${GPU_AOT} STREQUAL "PVC") )
71+
set(CMAKE_CXX_FLAGS "${INTEL_GPU_CXX_FLAGS}")
72+
if((${GPU_AOT} STREQUAL "pvc") OR (${GPU_AOT} STREQUAL "PVC"))
5773
message(STATUS "Enabling Intel GPU AOT compilation for ${GPU_AOT}")
5874
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=spir64_gen -Xs \"-device 0x0bd5 -revision_id 0x2f\" ")
5975
else()
6076
message(STATUS "Using custom AOT compilation flag ${GPU_AOT}")
61-
string(APPEND CMAKE_CXX_FLAGS " ${GPU_AOT} ")
77+
string(APPEND CMAKE_CXX_FLAGS " ${GPU_AOT} ") # User should be aware of advanced AOT compilation flags
6278
endif()
6379
elseif(USE_NVIDIA_BACKEND)
6480
message(STATUS "Enabling NVIDIA backend")
65-
if(USE_DEFAULT_FLAGS)
66-
set(CMAKE_CXX_FLAGS "${NVIDIA_GPU_CXX_FLAGS}") # Default flags for NV backend
67-
endif()
81+
set(CMAKE_CXX_FLAGS "${NVIDIA_GPU_CXX_FLAGS}")
6882
if(USE_SM)
6983
message("-- Building for SM_${USE_SM} compatibility")
70-
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_${USE_SM}")
84+
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_${USE_SM} ")
7185
else()
7286
message("-- Building for SM_80 compatibility (DEFAULT)")
73-
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_80")
87+
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_80 ")
7488
endif()
89+
string(APPEND CMAKE_CXX_FLAGS " -DUSE_NVIDIA_BACKEND")
7590
elseif(USE_AMDHIP_BACKEND)
7691
message(STATUS "Enabling AMD HIP backend for ${USE_AMDHIP_BACKEND} AMD architecture")
77-
if(USE_DEFAULT_FLAGS)
78-
set(CMAKE_CXX_FLAGS "${AMD_GPU_CXX_FLAGS}") # Default flags for AMD backend (gfx908 for MI100)
79-
endif()
92+
set(CMAKE_CXX_FLAGS "${AMD_GPU_CXX_FLAGS}")
8093
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=${USE_AMDHIP_BACKEND} ")
94+
string(APPEND CMAKE_CXX_FLAGS " -DUSE_AMDHIP_BACKEND")
95+
else()
96+
# JIT case
97+
message(STATUS "Enabling INTEL backend")
98+
set(CMAKE_CXX_FLAGS "${INTEL_GPU_CXX_FLAGS}")
8199
endif()
82100

101+
message(STATUS "CXX Compilation flags set to: ${CMAKE_CXX_FLAGS}")
102+
83103
find_package( OpenCV REQUIRED )
84104

85105
set(SOURCES

0 commit comments

Comments
 (0)