Skip to content

Commit 18bc218

Browse files
committed
cmake changes for overriding flags
1 parent f2394bb commit 18bc218

File tree

3 files changed

+75
-33
lines changed

3 files changed

+75
-33
lines changed

bitcracker/CUDA/CMakeLists.txt

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

2727
option(USE_SM "Build for specific SM" OFF)
2828

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

3750
# CUDA_NVCC_FLAGS

bitcracker/HIP/CMakeLists.txt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ set(CMAKE_CXX_STANDARD 17)
2424
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2525
set(CMAKE_CXX_EXTENSIONS OFF)
2626

27+
set(DEF_WL_CXX_FLAGS " -D__HIP_PLATFORM_AMD__ ")
28+
set(DEF_GENERAL_CXX_FLAGS " -O3 -std=c++17 -ffast-math ")
29+
set(DEF_COMBINED_CXX_FLAGS "${DEF_GENERAL_CXX_FLAGS} ${DEF_WL_CXX_FLAGS}")
30+
2731
if(NOT DEFINED ROCM_PATH)
2832
if(NOT DEFINED ENV{ROCM_PATH})
2933
set(ROCM_PATH "/opt/rocm" CACHE PATH "Path to which HIP has been installed")
@@ -35,12 +39,21 @@ set(CMAKE_MODULE_PATH "${ROCM_PATH}/hip/cmake" ${CMAKE_MODULE_PATH})
3539
set(HIP_INCLUDE_DIRS "${ROCM_PATH}/include" ${HIP_INCLUDE_DIRS})
3640
set(HIP_LIBRARIES "${ROCM_PATH}/lib" ${HIP_LIBRARIES})
3741

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

4659
find_package(HIP REQUIRED)
@@ -58,5 +71,3 @@ include_directories(
5871
)
5972

6073
add_executable(bitcracker ${SOURCES})
61-
62-
# target_link_libraries(bitcracker ${HIP_LIBRARIES})

bitcracker/SYCL/CMakeLists.txt

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

33-
set(INTEL_GPU_CXX_FLAGS " -O2 -fsycl -Wall -Wextra -Wno-unused-parameter ")
34-
set(NVIDIA_GPU_CXX_FLAGS " -O3 -fsycl -Wall -Wextra -Wno-unused-parameter ")
35-
set(AMD_GPU_CXX_FLAGS " -O3 -fsycl -Wall -Wextra -Wno-unused-parameter ")
33+
set(DEF_INTEL_WL_CXX_FLAGS " ")
34+
set(DEF_NVIDIA_WL_CXX_FLAGS " ")
35+
set(DEF_AMD_WL_CXX_FLAGS " ")
3636

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

45-
# AOT compilation
4664
if(GPU_AOT)
4765
message(STATUS "Enabling INTEL backend")
48-
if(USE_DEFAULT_FLAGS)
49-
set(CMAKE_CXX_FLAGS "${INTEL_GPU_CXX_FLAGS}") # Default flags for Intel backend
50-
endif()
51-
if( (${GPU_AOT} STREQUAL "pvc") OR (${GPU_AOT} STREQUAL "PVC") )
66+
set(CMAKE_CXX_FLAGS "${INTEL_GPU_CXX_FLAGS}")
67+
if((${GPU_AOT} STREQUAL "pvc") OR (${GPU_AOT} STREQUAL "PVC"))
5268
message(STATUS "Enabling Intel GPU AOT compilation for ${GPU_AOT}")
5369
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=spir64_gen -Xs \"-device 0x0bd5 -revision_id 0x2f -options -ze-opt-large-register-file\" ")
5470
else()
5571
message(STATUS "Using custom AOT compilation flag ${GPU_AOT}")
56-
string(APPEND CMAKE_CXX_FLAGS " ${GPU_AOT} ")
72+
string(APPEND CMAKE_CXX_FLAGS " ${GPU_AOT} ") # User should be aware of advanced AOT compilation flags
5773
endif()
5874
elseif(USE_NVIDIA_BACKEND)
5975
message(STATUS "Enabling NVIDIA backend")
60-
if(USE_DEFAULT_FLAGS)
61-
set(CMAKE_CXX_FLAGS "${NVIDIA_GPU_CXX_FLAGS}") # Default flags for NV backend
62-
endif()
76+
set(CMAKE_CXX_FLAGS "${NVIDIA_GPU_CXX_FLAGS}")
6377
if(USE_SM)
6478
message("-- Building for SM_${USE_SM} compatibility")
6579
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_${USE_SM}")
@@ -70,13 +84,17 @@ elseif(USE_NVIDIA_BACKEND)
7084
string(APPEND CMAKE_CXX_FLAGS " -DUSE_NVIDIA_BACKEND")
7185
elseif(USE_AMDHIP_BACKEND)
7286
message(STATUS "Enabling AMD HIP backend for ${USE_AMDHIP_BACKEND} AMD architecture")
73-
if(USE_DEFAULT_FLAGS)
74-
set(CMAKE_CXX_FLAGS "${AMD_GPU_CXX_FLAGS}") # Default flags for AMD backend (gfx908 for MI100)
75-
endif()
87+
set(CMAKE_CXX_FLAGS "${AMD_GPU_CXX_FLAGS}")
7688
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=${USE_AMDHIP_BACKEND} ")
7789
string(APPEND CMAKE_CXX_FLAGS " -DUSE_AMDHIP_BACKEND")
90+
else()
91+
# JIT case
92+
message(STATUS "Enabling INTEL backend")
93+
set(CMAKE_CXX_FLAGS "${INTEL_GPU_CXX_FLAGS}")
7894
endif()
7995

96+
message(STATUS "CXX Compilation flags set to: ${CMAKE_CXX_FLAGS}")
97+
8098
set(SOURCES
8199
${CMAKE_SOURCE_DIR}/src/main.cpp
82100
${CMAKE_SOURCE_DIR}/src/utils.cpp

0 commit comments

Comments
 (0)