Skip to content

C API build script improvements to build dpctl with a custom DPC++ and other changes #319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ __pycache__/
# C extensions and binary files
*.o
*.so
*.so.*
*.exe
*.lib
*.dll
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ installed:
- `cmake` - for building C API
- `ninja` - only on Windows

Activate DPC++ compiler:
You need DPC++ to build dpctl. If you want to build using the DPC++ in a
oneAPI distribution, activate DPC++ compiler as follows:
```bash
export ONEAPI_ROOT=/opt/intel/oneapi
source ${ONEAPI_ROOT}/compiler/latest/env/vars.sh
Expand Down
157 changes: 106 additions & 51 deletions dpctl-capi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project("dpctl C API - A C wrapper for a subset of SYCL")

# Load our CMake modules to search for DPCPP and Level Zero
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
find_package(Git REQUIRED)
include(GetProjectVersion)
# the get_version function is defined in the GetProjectVersion module and
# defines: VERSION, SEMVER, MAJOR, MINOR, PATCH. These variables are populated
# by parsing the output of git describe.
get_version()
project(
"libDPCTLSYCLInterface"
DESCRIPTION "A C API for a subset of SYCL"
)

option(DPCTL_CUSTOM_DPCPP_INSTALL_DIR
"Use a custom version of DPCPP installed at the provided location."
OFF
)
# Option to turn on support for creating Level Zero interoperability programs
# from a SPIR-V binary file.
option(DPCTL_ENABLE_LO_PROGRAM_CREATION
Expand All @@ -23,40 +39,82 @@ option(DPCTL_BUILD_CAPI_TESTS
OFF
)

# Load our CMake modules to search for DPCPP and Level Zero
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
find_package(DPCPP 2021.2.0 REQUIRED)
# Minimum version requirement only when oneAPI dpcpp is used.
if(DPCTL_CUSTOM_DPCPP_INSTALL_DIR)
find_package(IntelSycl REQUIRED)
else()
find_package(IntelSycl 2021.2.0 REQUIRED)
endif()

if(DPCTL_ENABLE_LO_PROGRAM_CREATION)
set(DPCTL_ENABLE_LO_PROGRAM_CREATION 1)
find_package(LevelZero REQUIRED)
include(GetLevelZeroHeaders)
get_level_zero_headers()
endif()

configure_file(${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h.in
${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h)
configure_file(
${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h.in
${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h
)

# Set the C++ standard to C++17
set(CMAKE_CXX_STANDARD 17)

if(WIN32)
set(CMAKE_CXX_COMPILER:PATH "${DPCPP_ROOT}/bin/dpcpp")
set(CMAKE_C_COMPILER:PATH "${DPCPP_ROOT}/bin/clang-cl")
set(CMAKE_LINKER:PATH "${DPCPP_ROOT}/bin/lld-link")
message(STATUS "Resetting CXX compiler to: " ${CMAKE_CXX_COMPILER})
message(STATUS "Resetting C compiler to: " ${CMAKE_C_COMPILER})
message(STATUS "Resetting Linker to: " ${CMAKE_LINKER})
set(WARNING_FLAGS "-Wall -Wextra -Winit-self -Wunused-function -Wuninitialized -Wmissing-declarations")
string(CONCAT WARNING_FLAGS
"-Wall "
"-Wextra "
"-Winit-self "
"-Wunused-function "
"-Wuninitialized "
"-Wmissing-declarations "
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} -Qstd=c++17")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG -Qstd=c++17")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG
"${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG"
)
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG"
)
elseif(UNIX)
set(CMAKE_CXX_COMPILER:PATH "${DPCPP_ROOT}/bin/dpcpp")
set(CMAKE_C_COMPILER:PATH "${DPCPP_ROOT}/bin/clang")
set(CMAKE_LINKER:PATH "${DPCPP_ROOT}/bin/lld")
set(SDL_FLAGS "-fstack-protector -fstack-protector-all -fpic -fPIC -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -fno-strict-overflow -fno-delete-null-pointer-checks")
set(WARNING_FLAGS "-Wall -Wextra -Winit-self -Wunused-function -Wuninitialized -Wmissing-declarations -fdiagnostics-color=auto")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${SDL_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} ${SDL_FLAGS} -std=c++17 -fsycl")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG -std=c++17 -fsycl")
string(CONCAT WARNING_FLAGS
"-Wall "
"-Wextra "
"-Winit-self "
"-Wunused-function "
"-Wuninitialized "
"-Wmissing-declarations "
"-fdiagnostics-color=auto "
)
string(CONCAT SDL_FLAGS
"-fstack-protector "
"-fstack-protector-all "
"-fpic "
"-fPIC "
"-D_FORTIFY_SOURCE=2 "
"-Wformat "
"-Wformat-security "
"-fno-strict-overflow "
"-fno-delete-null-pointer-checks "
)
string(CONCAT CFLAGS
"${WARNING_FLAGS}"
"${SDL_FLAGS}"
)
string(CONCAT CXXFLAGS
"${WARNING_FLAGS}"
"${SDL_FLAGS}"
"-fsycl "
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAGS}")
set(CMAKE_CXX_FLAGS "${CXXFLAGS}")
set(CMAKE_C_FLAGS_DEBUG
"${CMAKE_C_FLAGS_DEBUG} ${CFLAGS} -ggdb3 -DDEBUG"
)
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} ${CXXFLAGS} -ggdb3 -DDEBUG"
)
else()
message(FATAL_ERROR "Unsupported system.")
endif()
Expand Down Expand Up @@ -85,31 +143,30 @@ target_include_directories(DPCTLSyclInterface
PRIVATE
${CMAKE_SOURCE_DIR}/include/
${CMAKE_SOURCE_DIR}/helper/include/
${DPCPP_SYCL_INCLUDE_DIR}
${IntelSycl_SYCL_INCLUDE_DIR}
)

target_link_libraries(DPCTLSyclInterface
PRIVATE ${DPCPP_SYCL_LIBRARY}
PRIVATE ${DPCPP_OPENCL_LIBRARY}
PRIVATE ${IntelSycl_SYCL_LIBRARY}
PRIVATE ${IntelSycl_OPENCL_LIBRARY}
)

if(DPCTL_ENABLE_LO_PROGRAM_CREATION)
if(UNIX)
target_include_directories(DPCTLSyclInterface
PRIVATE
${LEVEL_ZERO_INCLUDE_DIR}
)
else()
message(WARNING
"DPCTL support Level Zero program creation not supported "
"on this system."
)
endif()
target_include_directories(DPCTLSyclInterface
PRIVATE
${LEVEL_ZERO_INCLUDE_DIR}
)
endif()

install(
TARGETS DPCTLSyclInterface
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/
# NOTE: Till we hit 1.0.0 we will keep using the MINOR version to set the API
# version of the library.
set_target_properties(DPCTLSyclInterface PROPERTIES VERSION ${VERSION_MINOR})
set_target_properties(DPCTLSyclInterface PROPERTIES SOVERSION 1)

install(TARGETS
DPCTLSyclInterface
LIBRARY
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/
)

# Install all headers
Expand All @@ -132,16 +189,14 @@ endforeach()

# Enable code coverage related settings
if(DPCTL_GENERATE_COVERAGE)
# check if llvm-cov and lcov are available
# check if lcov is available
find_package(Lcov REQUIRED)
# These flags are set inside FindDPCPP
if(NOT (${LLVM_COV_FOUND} AND ${LLVM_PROFDATA_FOUND}))
message(FATAL_ERROR
"llvm-cov and llvm-profdata are needed to generate coverage."
)
endif()
# check if llvm-cov version 11 is available
find_package(LLVMCov 11 REQUIRED)
# check if llvm-profdata is available
find_package(LLVMProfdata REQUIRED)
# Turn on DPCTL_BUILD_CAPI_TESTS as building tests is needed to generate
# coverage reports
# coverage reports.
set(DPCTL_BUILD_CAPI_TESTS "ON")
if(DPCTL_COVERAGE_REPORT_OUTPUT_DIR)
set(COVERAGE_OUTPUT_DIR ${DPCTL_COVERAGE_REPORT_OUTPUT_DIR})
Expand Down
139 changes: 0 additions & 139 deletions dpctl-capi/cmake/modules/FindDPCPP.cmake

This file was deleted.

Loading