Skip to content

Commit db76b83

Browse files
committed
cmake changes for overriding flags
1 parent 24880a4 commit db76b83

File tree

3 files changed

+76
-32
lines changed

3 files changed

+76
-32
lines changed

hashtable/CUDA/CMakeLists.txt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,25 @@ set(CMAKE_CXX_EXTENSIONS OFF) # use std instead of gnu
1818

1919
option(USE_SM "Build for specific SM" OFF)
2020

21-
# CMAKE_CXX_FLAGS
22-
if("${CMAKE_CXX_FLAGS}" STREQUAL "")
23-
message(STATUS "Using DEFAULT compilation flags for the application")
24-
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} " -O3 -Wall -Wextra -Wno-unused-parameter ")
25-
else()
26-
message(STATUS "OVERRIDING compilation flags")
21+
set(DEF_WL_CXX_FLAGS " ")
22+
set(DEF_GENERAL_CXX_FLAGS " -O3 -Wall -Wextra -Wno-unused-parameter ")
23+
set(DEF_COMBINED_CXX_FLAGS "${DEF_GENERAL_CXX_FLAGS} ${DEF_WL_CXX_FLAGS}")
24+
25+
# -DCMAKE_CXX_FLAGS=" -blah -blah " overrides the default flags (BOTH general and WL specific)
26+
# -DOVERRIDE_GENERAL_CXX_FLAGS=" -blah -blah " overrides the general flags only (and not the workload specific flags)
27+
# passing in both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS is not allowed, in order to prevent ambiguity
28+
29+
if(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "" AND NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
30+
message(FATAL_ERROR "Both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS cannot be passed in together")
31+
elseif("${CMAKE_CXX_FLAGS}" STREQUAL "" AND "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
32+
message(STATUS "Using DEFAULT compilation flags")
33+
set(CMAKE_CXX_FLAGS "${DEF_COMBINED_CXX_FLAGS}")
34+
elseif(NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
35+
message(STATUS "OVERRIDING GENERAL compilation flags")
36+
set(CMAKE_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS}")
37+
string(APPEND CMAKE_CXX_FLAGS ${DEF_WL_CXX_FLAGS})
38+
elseif(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "")
39+
message(STATUS "OVERRIDING GENERAL and WORKLOAD SPECIFIC compilation flags")
2740
endif()
2841

2942
add_compile_options(-DUSE_CUDA)

hashtable/HIP/CMakeLists.txt

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

30-
# CMAKE_CXX_FLAGS
31-
if("${CMAKE_CXX_FLAGS}" STREQUAL "")
32-
message(STATUS "Using DEFAULT compilation flags for the application")
33-
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} " -O3 -std=c++17 -ffast-math -D__HIP_PLATFORM_AMD__ ")
34-
else()
35-
message(STATUS "OVERRIDING compilation flags")
30+
set(DEF_WL_CXX_FLAGS " -D__HIP_PLATFORM_AMD__ ")
31+
set(DEF_GENERAL_CXX_FLAGS " -O3 -std=c++17 -ffast-math ")
32+
set(DEF_COMBINED_CXX_FLAGS "${DEF_GENERAL_CXX_FLAGS} ${DEF_WL_CXX_FLAGS}")
33+
34+
# -DCMAKE_CXX_FLAGS=" -blah -blah " overrides the default flags (BOTH general and WL specific)
35+
# -DOVERRIDE_GENERAL_CXX_FLAGS=" -blah -blah " overrides the general flags only (and not the workload specific flags)
36+
# passing in both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS is not allowed, in order to prevent ambiguity
37+
38+
if(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "" AND NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
39+
message(FATAL_ERROR "Both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS cannot be passed in together")
40+
elseif("${CMAKE_CXX_FLAGS}" STREQUAL "" AND "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
41+
message(STATUS "Using DEFAULT compilation flags")
42+
set(CMAKE_CXX_FLAGS "${DEF_COMBINED_CXX_FLAGS}")
43+
elseif(NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
44+
message(STATUS "OVERRIDING GENERAL compilation flags")
45+
set(CMAKE_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS}")
46+
string(APPEND CMAKE_CXX_FLAGS ${DEF_WL_CXX_FLAGS})
47+
elseif(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "")
48+
message(STATUS "OVERRIDING GENERAL and WORKLOAD SPECIFIC compilation flags")
3649
endif()
3750

3851
find_package(HIP REQUIRED)

hashtable/SYCL/CMakeLists.txt

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,50 @@ option(USE_NVIDIA_BACKEND "Build for NVIDIA backend" OFF)
2121
option(USE_AMDHIP_BACKEND "Build for AMD HIP backend" OFF)
2222
option(USE_SM "Build for specific SM" OFF)
2323

24-
set(INTEL_GPU_CXX_FLAGS " -O2 -fsycl -Wall -Wextra -Wno-unused-parameter ")
25-
set(NVIDIA_GPU_CXX_FLAGS " -O3 -fsycl -Wall -Wextra -Wno-unused-parameter ")
26-
set(AMD_GPU_CXX_FLAGS " -O3 -fsycl -Wall -Wextra -Wno-unused-parameter ")
24+
set(DEF_INTEL_WL_CXX_FLAGS " ")
25+
set(DEF_NVIDIA_WL_CXX_FLAGS " ")
26+
set(DEF_AMD_WL_CXX_FLAGS " ")
2727

28-
set(USE_DEFAULT_FLAGS ON)
29-
if("${CMAKE_CXX_FLAGS}" STREQUAL "")
28+
set(DEF_INTEL_GENERAL_CXX_FLAGS " -O2 -fsycl -Wall -Wextra -Wno-unused-parameter ")
29+
set(DEF_NVIDIA_GENERAL_CXX_FLAGS " -O3 -fsycl -Wall -Wextra -Wno-unused-parameter ")
30+
set(DEF_AMD_GENERAL_CXX_FLAGS " -O3 -fsycl -Wall -Wextra -Wno-unused-parameter ")
31+
32+
# -DCMAKE_CXX_FLAGS=" -blah -blah " overrides the default flags (BOTH general and WL specific)
33+
# -DOVERRIDE_GENERAL_CXX_FLAGS=" -blah -blah " overrides the general flags only (and not the workload specific flags)
34+
# passing in both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS is not allowed, in order to prevent ambiguity
35+
36+
if(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "" AND NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
37+
message(FATAL_ERROR "Both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS cannot be passed in together")
38+
elseif("${CMAKE_CXX_FLAGS}" STREQUAL "" AND "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
3039
message(STATUS "Using DEFAULT compilation flags")
31-
else()
32-
message(STATUS "Overriding DEFAULT compilation flags")
33-
set(USE_DEFAULT_FLAGS OFF)
40+
set(INTEL_GPU_CXX_FLAGS "${DEF_INTEL_GENERAL_CXX_FLAGS} ${DEF_INTEL_WL_CXX_FLAGS}")
41+
set(NVIDIA_GPU_CXX_FLAGS "${DEF_NVIDIA_GENERAL_CXX_FLAGS} ${DEF_NVIDIA_WL_CXX_FLAGS}")
42+
set(AMD_GPU_CXX_FLAGS "${DEF_AMD_GENERAL_CXX_FLAGS} ${DEF_AMD_WL_CXX_FLAGS}")
43+
elseif(NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
44+
message(STATUS "OVERRIDING GENERAL compilation flags")
45+
set(INTEL_GPU_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS} ${DEF_INTEL_WL_CXX_FLAGS}")
46+
set(NVIDIA_GPU_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS} ${DEF_NVIDIA_WL_CXX_FLAGS}")
47+
set(AMD_GPU_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS} ${DEF_AMD_WL_CXX_FLAGS}")
48+
elseif(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "")
49+
message(STATUS "OVERRIDING GENERAL and WORKLOAD SPECIFIC compilation flags")
50+
set(INTEL_GPU_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
51+
set(NVIDIA_GPU_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
52+
set(AMD_GPU_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
3453
endif()
3554

36-
# AOT compilation
3755
if(GPU_AOT)
3856
message(STATUS "Enabling INTEL backend")
39-
if(USE_DEFAULT_FLAGS)
40-
set(CMAKE_CXX_FLAGS "${INTEL_GPU_CXX_FLAGS}") # Default flags for Intel backend
41-
endif()
42-
if( (${GPU_AOT} STREQUAL "pvc") OR (${GPU_AOT} STREQUAL "PVC") )
57+
set(CMAKE_CXX_FLAGS "${INTEL_GPU_CXX_FLAGS}")
58+
if((${GPU_AOT} STREQUAL "pvc") OR (${GPU_AOT} STREQUAL "PVC"))
4359
message(STATUS "Enabling Intel GPU AOT compilation for ${GPU_AOT}")
4460
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=spir64_gen -Xs \"-device 0x0bd5 -revision_id 0x2f\" ")
4561
else()
4662
message(STATUS "Using custom AOT compilation flag ${GPU_AOT}")
47-
string(APPEND CMAKE_CXX_FLAGS " ${GPU_AOT} ")
63+
string(APPEND CMAKE_CXX_FLAGS " ${GPU_AOT} ") # User should be aware of advanced AOT compilation flags
4864
endif()
4965
elseif(USE_NVIDIA_BACKEND)
5066
message(STATUS "Enabling NVIDIA backend")
51-
if(USE_DEFAULT_FLAGS)
52-
set(CMAKE_CXX_FLAGS "${NVIDIA_GPU_CXX_FLAGS}") # Default flags for NV backend
53-
endif()
67+
set(CMAKE_CXX_FLAGS "${NVIDIA_GPU_CXX_FLAGS}")
5468
if(USE_SM)
5569
message("-- Building for SM_${USE_SM} compatibility")
5670
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_${USE_SM} ")
@@ -60,12 +74,16 @@ elseif(USE_NVIDIA_BACKEND)
6074
endif()
6175
elseif(USE_AMDHIP_BACKEND)
6276
message(STATUS "Enabling AMD HIP backend for ${USE_AMDHIP_BACKEND} AMD architecture")
63-
if(USE_DEFAULT_FLAGS)
64-
set(CMAKE_CXX_FLAGS "${AMD_GPU_CXX_FLAGS}") # Default flags for AMD backend (gfx90a for MI250)
65-
endif()
77+
set(CMAKE_CXX_FLAGS "${AMD_GPU_CXX_FLAGS}")
6678
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=${USE_AMDHIP_BACKEND} ")
79+
else()
80+
# JIT case
81+
message(STATUS "Enabling INTEL backend")
82+
set(CMAKE_CXX_FLAGS "${INTEL_GPU_CXX_FLAGS}")
6783
endif()
6884

85+
message(STATUS "CXX Compilation flags set to: ${CMAKE_CXX_FLAGS}")
86+
6987
set(SOURCES
7088
${CMAKE_SOURCE_DIR}/src/main.cpp
7189
${CMAKE_SOURCE_DIR}/src/test.cpp

0 commit comments

Comments
 (0)