Skip to content

Commit 56584ee

Browse files
Update CXX and C compilers (#140)
1 parent d06919c commit 56584ee

File tree

2 files changed

+108
-47
lines changed

2 files changed

+108
-47
lines changed

CMakeLists.txt

Lines changed: 77 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,9 @@ else()
3636
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
3737
endif()
3838

39-
# Define required compilers for Windows before project
40-
if(WIN32)
41-
set(CMAKE_CXX_COMPILER "clang-cl")
42-
set(CMAKE_C_COMPILER "clang-cl")
43-
endif()
44-
45-
project(oneMKL VERSION 0.1.0 LANGUAGES CXX)
46-
39+
# Build options
4740
option(BUILD_SHARED_LIBS "Build dynamic libraries" ON)
4841

49-
# Override default CXX compile/link lines for Windows after project
50-
if(WIN32)
51-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function -w")
52-
foreach (flag_var
53-
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
54-
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
55-
string(REPLACE "/MD" "" ${flag_var} "${${flag_var}}")
56-
endforeach()
57-
set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> -fsycl /nologo <DEFINES> <INCLUDES> /EHsc <FLAGS> /Fo<OBJECT> -c <SOURCE>")
58-
set(CMAKE_CXX_CREATE_STATIC_LIBRARY "lib /nologo <OBJECTS> /out:<TARGET>")
59-
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> -fsycl /nologo <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
60-
endif()
61-
62-
# Temporary disable sycl 2020 deprecations warnings
63-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSYCL2020_DISABLE_DEPRECATION_WARNINGS")
64-
6542
## Backends
6643
option(ENABLE_MKLCPU_BACKEND "" ON)
6744
option(ENABLE_MKLGPU_BACKEND "" ON)
@@ -73,7 +50,13 @@ option(ENABLE_CURAND_BACKEND "" OFF)
7350
option(ENABLE_NETLIB_BACKEND "" OFF)
7451
set(ONEMKL_SYCL_IMPLEMENTATION "dpc++" CACHE STRING "Name of the SYCL compiler")
7552

76-
## Domains
53+
## Testing
54+
option(BUILD_FUNCTIONAL_TESTS "" ON)
55+
56+
## Documentation
57+
option(BUILD_DOC "" OFF)
58+
59+
## Supported domains
7760
set(DOMAINS_LIST "")
7861
if(ENABLE_MKLCPU_BACKEND
7962
OR ENABLE_MKLGPU_BACKEND
@@ -91,6 +74,75 @@ if(ENABLE_MKLCPU_BACKEND
9174
list(APPEND DOMAINS_LIST "rng")
9275
endif()
9376

77+
# Define required CXX compilers before project
78+
if(CMAKE_CXX_COMPILER OR NOT ONEMKL_SYCL_IMPLEMENTATION STREQUAL "dpc++")
79+
if(WIN32)
80+
string(REPLACE "\\" "/" CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER})
81+
endif()
82+
else()
83+
if(ENABLE_CUBLAS_BACKEND OR ENABLE_CURAND_BACKEND)
84+
set(CMAKE_CXX_COMPILER "clang++")
85+
elseif(ENABLE_MKLGPU_BACKEND)
86+
set(CMAKE_CXX_COMPILER "dpcpp")
87+
else()
88+
find_program(DPCPP_PATH dpcpp)
89+
if(DPCPP_PATH)
90+
message(STATUS "CXX compiler: dpcpp was found in PATH, using dpcpp")
91+
set(CMAKE_CXX_COMPILER "dpcpp")
92+
else()
93+
if(WIN32)
94+
message(STATUS "CXX compiler: dpcpp was not found in PATH, using clang-cl instead")
95+
set(CMAKE_CXX_COMPILER "clang-cl")
96+
else()
97+
message(STATUS "CXX compiler: dpcpp was not found in PATH, using clang++ instead")
98+
set(CMAKE_CXX_COMPILER "clang++")
99+
endif()
100+
endif()
101+
endif()
102+
endif()
103+
104+
# Define required C compilers before project
105+
if(CMAKE_C_COMPILER OR NOT ONEMKL_SYCL_IMPLEMENTATION STREQUAL "dpc++")
106+
if(WIN32)
107+
string(REPLACE "\\" "/" CMAKE_C_COMPILER ${CMAKE_C_COMPILER})
108+
endif()
109+
else()
110+
find_program(ICX_PATH icx)
111+
if(ICX_PATH)
112+
message(STATUS "C compiler: icx was found in PATH, using icx")
113+
set(CMAKE_C_COMPILER "icx")
114+
else()
115+
if(WIN32)
116+
message(STATUS "C compiler: icx was not found in PATH, using clang-cl instead")
117+
set(CMAKE_C_COMPILER "clang-cl")
118+
else()
119+
message(STATUS "C compiler: icx was not found in PATH, using clang instead")
120+
set(CMAKE_C_COMPILER "clang")
121+
endif()
122+
endif()
123+
endif()
124+
125+
project(oneMKL VERSION 0.2.0 LANGUAGES CXX)
126+
127+
# Override default CXX compile/link lines for Windows after project
128+
if(WIN32 AND ONEMKL_SYCL_IMPLEMENTATION STREQUAL "dpc++")
129+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function -w")
130+
foreach (flag_var
131+
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
132+
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
133+
string(REPLACE "/MD" "" ${flag_var} "${${flag_var}}")
134+
endforeach()
135+
set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> -fsycl /nologo <DEFINES> <INCLUDES> /EHsc <FLAGS> /Fo<OBJECT> -c <SOURCE>")
136+
set(CMAKE_CXX_CREATE_STATIC_LIBRARY "lib /nologo <OBJECTS> /out:<TARGET>")
137+
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> -fsycl /nologo <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
138+
endif()
139+
140+
# Temporary disable sycl 2020 deprecations warnings
141+
if(ONEMKL_SYCL_IMPLEMENTATION STREQUAL "dpc++")
142+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSYCL2020_DISABLE_DEPRECATION_WARNINGS")
143+
endif()
144+
145+
# Target domains
94146
if(NOT TARGET_DOMAINS OR TARGET_DOMAINS STREQUAL "None")
95147
# Set to all by default
96148
set(TARGET_DOMAINS ${DOMAINS_LIST})
@@ -111,12 +163,6 @@ else()
111163
endif()
112164
message(STATUS "TARGET_DOMAINS: ${TARGET_DOMAINS}")
113165

114-
## Testing
115-
option(BUILD_FUNCTIONAL_TESTS "" ON)
116-
117-
## Documentation
118-
option(BUILD_DOC "" OFF)
119-
120166
# Set output directories for the project
121167
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
122168
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

README.md

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ oneMKL is part of [oneAPI](https://oneapi.io).
4545
## Table of Contents
4646

4747
- [Support and Requirements](#support-and-requirements)
48+
- [Selection of Compilers](#selection-of-compilers)
4849
- [Build Setup](#build-setup)
4950
- [Building with Conan](#building-with-conan)
5051
- [Building with CMake](#building-with-cmake)
@@ -80,8 +81,8 @@ oneapi::mkl::blas::column_major::gemm(gpu_queue, transA, transB, m, ...);
8081
How to build an application with run-time dispatching:
8182
8283
```cmd
83-
$> clang++ -fsycl –I$ONEMKL/include app.cpp
84-
$> clang++ -fsycl app.o –L$ONEMKL/lib –lonemkl
84+
$> dpcpp -fsycl –I$ONEMKL/include app.cpp
85+
$> dpcpp -fsycl app.o –L$ONEMKL/lib –lonemkl
8586
```
8687

8788
- **Compile-time dispatching**: The application uses a templated backend selector API where the template parameters specify the required backends and third-party libraries and the application is linked with the required oneMKL backend wrapper libraries (libraries can be static or dynamic).
@@ -110,6 +111,8 @@ $> clang++ -fsycl –I$ONEMKL/include app.cpp
110111
$> clang++ -fsycl app.o –L$ONEMKL/lib –lonemkl_blas_mklcpu –lonemkl_blas_cublas
111112
```
112113

114+
*Refer to [Selection of Compilers](#selection-of-compilers) for the choice between `dpcpp` and `clang++` compilers.*
115+
113116
### Supported Configurations:
114117

115118
Supported domains: BLAS, LAPACK, RNG
@@ -366,6 +369,16 @@ Python | 3.6 or higher | No | *N/A* | *Pre-installed or Installed by user* | [PS
366369

367370
---
368371

372+
## Selection of Compilers
373+
374+
A compiler needs to be chosen according to the required backend of your application.
375+
376+
- If your application requires Intel GPU, use [Intel(R) oneAPI DPC++ Compiler](https://software.intel.com/en-us/oneapi/dpc-compiler) `dpcpp`.
377+
- If your application requires NVIDIA GPU, use the latest release of `clang++` from [Intel project for LLVM* technology](https://github.com/intel/llvm/releases).
378+
- If neither Intel GPU nor NVIDIA GPU is required, you can use either [Intel(R) oneAPI DPC++ Compiler](https://software.intel.com/en-us/oneapi/dpc-compiler) `dpcpp` or `clang++` on Linux and `clang-cl` on Windows from [Intel project for LLVM* technology](https://github.com/intel/llvm/releases).
379+
380+
---
381+
369382
## Build Setup
370383

371384
1. Install Intel(R) oneAPI DPC++ Compiler (select variant as per requirement).
@@ -515,10 +528,11 @@ conan build ..
515528
```bash
516529
# Inside <path to onemkl>
517530
mkdir build && cd build
518-
export CXX=<path_to_dpcpp_compiler>/bin/dpcpp;
519-
cmake .. [-DMKL_ROOT=<mkl_install_prefix>] \ # required only if environment variable MKLROOT is not set
520-
[-DREF_BLAS_ROOT=<reference_blas_install_prefix>] \ # required only for testing
521-
[-DREF_LAPACK_ROOT=<reference_lapack_install_prefix>] # required only for testing
531+
cmake .. [-DCMAKE_CXX_COMPILER=<path_to_dpcpp_compiler>/bin/dpcpp] \ # required only if dpcpp is not found in environment variable PATH
532+
[-DCMAKE_C_COMPILER=<path_to_icx_compiler>/bin/icx] \ # required only if icx is not found in environment variable PATH
533+
[-DMKL_ROOT=<mkl_install_prefix>] \ # required only if environment variable MKLROOT is not set
534+
[-DREF_BLAS_ROOT=<reference_blas_install_prefix>] \ # required only for testing
535+
[-DREF_LAPACK_ROOT=<reference_lapack_install_prefix>] # required only for testing
522536
cmake --build .
523537
ctest
524538
cmake --install . --prefix <path_to_install_dir>
@@ -527,11 +541,11 @@ cmake --install . --prefix <path_to_install_dir>
527541
```bash
528542
# Inside <path to onemkl>
529543
md build && cd build
530-
cmake .. -G Ninja
531-
[-DMKL_ROOT=<mkl_install_prefix>] \ # required only if environment variable MKLROOT is not set
532-
[-DREF_BLAS_ROOT=<reference_blas_install_prefix>] \ # required only for testing
533-
[-DREF_LAPACK_ROOT=<reference_lapack_install_prefix>] # required only for testing
534-
544+
cmake .. -G Ninja [-DCMAKE_CXX_COMPILER=<path_to_dpcpp_compiler>\bin\dpcpp] \ # required only if dpcpp is not found in environment variable PATH
545+
[-DCMAKE_C_COMPILER=<path_to_icx_compiler>\bin\icx] \ # required only if icx is not found in environment variable PATH
546+
[-DMKL_ROOT=<mkl_install_prefix>] \ # required only if environment variable MKLROOT is not set
547+
[-DREF_BLAS_ROOT=<reference_blas_install_prefix>] \ # required only for testing
548+
[-DREF_LAPACK_ROOT=<reference_lapack_install_prefix>] # required only for testing
535549
ninja
536550
ctest
537551
cmake --install . --prefix <path_to_install_dir>
@@ -546,11 +560,12 @@ With the cuBLAS backend:
546560
```bash
547561
# Inside <path to onemkl>
548562
mkdir build && cd build
549-
export CXX=<path_to_dpcpp_compiler>/bin/dpcpp;
550-
cmake .. -DENABLE_CUBLAS_BACKEND=True \
551-
-DENABLE_MKLCPU_BACKEND=False \ # disable Intel MKL CPU backend
552-
-DENABLE_MKLGPU_BACKEND=False \ # disable Intel MKL GPU backend
553-
[-DREF_BLAS_ROOT=<reference_blas_install_prefix>] \ # required only for testing
563+
cmake .. [-DCMAKE_CXX_COMPILER=<path_to_clang++_compiler>/bin/clang++] \ # required only if clang++ is not found in environment variable PATH
564+
[-DCMAKE_C_COMPILER=<path_to_clang_compiler>/bin/clang] \ # required only if clang is not found in environment variable PATH
565+
-DENABLE_CUBLAS_BACKEND=True \
566+
-DENABLE_MKLCPU_BACKEND=False \ # disable Intel MKL CPU backend
567+
-DENABLE_MKLGPU_BACKEND=False \ # disable Intel MKL GPU backend
568+
[-DREF_BLAS_ROOT=<reference_blas_install_prefix>] \ # required only for testing
554569
cmake --build .
555570
ctest
556571
cmake --install . --prefix <path_to_install_dir>

0 commit comments

Comments
 (0)