Skip to content

Commit 3bfe45e

Browse files
committed
cmake changes for overriding flags
1 parent 7555dbc commit 3bfe45e

File tree

3 files changed

+83
-30
lines changed

3 files changed

+83
-30
lines changed

tsne/CUDA/CMakeLists.txt

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

3939
option(USE_SM "Build for specific SM" OFF)
4040

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

4962
# CUDA_NVCC_FLAGS

tsne/HIP/CMakeLists.txt

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

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

5871
find_package(HIP REQUIRED)

tsne/SYCL/CMakeLists.txt

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,48 @@ option(ENABLE_KERNEL_PROFILING "Build using kernel profiling" OFF)
4040
option(GPU_AOT "Build AOT for Intel GPU" OFF)
4141
option(USE_NVIDIA_BACKEND "Build for NVIDIA backend" OFF)
4242
option(USE_AMDHIP_BACKEND "Build for AMD HIP backend" OFF)
43+
option(USE_SM "Build for specific SM" OFF)
4344

4445
if(ENABLE_KERNEL_PROFILING)
4546
message("-- Enabling kernel profiling")
4647
add_compile_options(-DENABLE_KERNEL_PROFILING)
4748
endif()
4849

49-
set(INTEL_GPU_CXX_FLAGS " -O2 -std=c++17 -fsycl -ffast-math -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-local-typedef ")
50-
set(NVIDIA_GPU_CXX_FLAGS " -O3 -std=c++17 -fsycl -ffast-math -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-local-typedef ")
51-
set(AMD_GPU_CXX_FLAGS " -O3 -std=c++17 -fsycl -ffast-math -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-local-typedef ")
50+
set(DEF_INTEL_WL_CXX_FLAGS " ")
51+
set(DEF_NVIDIA_WL_CXX_FLAGS " ")
52+
set(DEF_AMD_WL_CXX_FLAGS " ")
5253

53-
set(USE_DEFAULT_FLAGS ON)
54-
if("${CMAKE_CXX_FLAGS}" STREQUAL "")
54+
set(DEF_INTEL_GENERAL_CXX_FLAGS " -O2 -std=c++17 -fsycl -ffast-math -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-local-typedef ")
55+
set(DEF_NVIDIA_GENERAL_CXX_FLAGS " -O3 -std=c++17 -fsycl -ffast-math -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-local-typedef ")
56+
set(DEF_AMD_GENERAL_CXX_FLAGS " -O3 -std=c++17 -fsycl -ffast-math -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-local-typedef ")
57+
58+
# -DCMAKE_CXX_FLAGS=" -blah -blah " overrides the default flags (BOTH general and WL specific)
59+
# -DOVERRIDE_GENERAL_CXX_FLAGS=" -blah -blah " overrides the general flags only (and not the workload specific flags)
60+
# passing in both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS is not allowed, in order to prevent ambiguity
61+
62+
if(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "" AND NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
63+
message(FATAL_ERROR "Both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS cannot be passed in together")
64+
elseif("${CMAKE_CXX_FLAGS}" STREQUAL "" AND "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
5565
message(STATUS "Using DEFAULT compilation flags")
56-
else()
57-
message(STATUS "OVERRIDING DEFAULT compilation flags")
58-
set(USE_DEFAULT_FLAGS OFF)
66+
set(INTEL_GPU_CXX_FLAGS "${DEF_INTEL_GENERAL_CXX_FLAGS} ${DEF_INTEL_WL_CXX_FLAGS}")
67+
set(NVIDIA_GPU_CXX_FLAGS "${DEF_NVIDIA_GENERAL_CXX_FLAGS} ${DEF_NVIDIA_WL_CXX_FLAGS}")
68+
set(AMD_GPU_CXX_FLAGS "${DEF_AMD_GENERAL_CXX_FLAGS} ${DEF_AMD_WL_CXX_FLAGS}")
69+
elseif(NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
70+
message(STATUS "OVERRIDING GENERAL compilation flags")
71+
set(INTEL_GPU_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS} ${DEF_INTEL_WL_CXX_FLAGS}")
72+
set(NVIDIA_GPU_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS} ${DEF_NVIDIA_WL_CXX_FLAGS}")
73+
set(AMD_GPU_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS} ${DEF_AMD_WL_CXX_FLAGS}")
74+
elseif(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "")
75+
message(STATUS "OVERRIDING GENERAL and WORKLOAD SPECIFIC compilation flags")
76+
set(INTEL_GPU_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
77+
set(NVIDIA_GPU_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
78+
set(AMD_GPU_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
5979
endif()
6080

61-
# JIT compilation
6281
if(GPU_AOT)
6382
message(STATUS "Enabling INTEL backend")
64-
if(USE_DEFAULT_FLAGS)
65-
set(CMAKE_CXX_FLAGS "${INTEL_GPU_CXX_FLAGS}") # Default flags for Intel backend
66-
endif()
67-
if( (${GPU_AOT} STREQUAL "pvc") OR (${GPU_AOT} STREQUAL "PVC") )
83+
set(CMAKE_CXX_FLAGS "${INTEL_GPU_CXX_FLAGS}")
84+
if((${GPU_AOT} STREQUAL "pvc") OR (${GPU_AOT} STREQUAL "PVC"))
6885
message(STATUS "Enabling Intel GPU AOT compilation for ${GPU_AOT}")
6986
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=spir64_gen -Xs \"-device 0x0bd5 -revision_id 0x2f\" ")
7087
else()
@@ -73,18 +90,28 @@ if(GPU_AOT)
7390
endif()
7491
elseif(USE_NVIDIA_BACKEND)
7592
message(STATUS "Enabling NVIDIA backend")
76-
if(USE_DEFAULT_FLAGS)
77-
set(CMAKE_CXX_FLAGS "${NVIDIA_GPU_CXX_FLAGS}") # Default flags for NV backend
93+
set(CMAKE_CXX_FLAGS "${NVIDIA_GPU_CXX_FLAGS}")
94+
if(USE_SM)
95+
message("-- Building for SM_${USE_SM} compatibility")
96+
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_${USE_SM} ")
97+
else()
98+
message("-- Building for SM_80 compatibility (DEFAULT)")
99+
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_80 ")
78100
endif()
79-
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=nvptx64-nvidia-cuda ") # -O3 will be used, even though -O2 was set earlier
101+
string(APPEND CMAKE_CXX_FLAGS " -DUSE_NVIDIA_BACKEND")
80102
elseif(USE_AMDHIP_BACKEND)
81103
message(STATUS "Enabling AMD HIP backend for ${USE_AMDHIP_BACKEND} AMD architecture")
82-
if(USE_DEFAULT_FLAGS)
83-
set(CMAKE_CXX_FLAGS "${AMD_GPU_CXX_FLAGS}") # Default flags for AMD backend (gfx908 for MI100)
84-
endif()
104+
set(CMAKE_CXX_FLAGS "${AMD_GPU_CXX_FLAGS}")
85105
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=${USE_AMDHIP_BACKEND} ")
106+
string(APPEND CMAKE_CXX_FLAGS " -DUSE_AMDHIP_BACKEND")
107+
else()
108+
# JIT case
109+
message(STATUS "Enabling INTEL backend")
110+
set(CMAKE_CXX_FLAGS "${INTEL_GPU_CXX_FLAGS}")
86111
endif()
87112

113+
message(STATUS "CXX Compilation flags set to: ${CMAKE_CXX_FLAGS}")
114+
88115
if(GPU_AOT)
89116
set(MKL_LINK static)
90117
set(MKL_THREADING sequential)

0 commit comments

Comments
 (0)