Skip to content

Commit 7522781

Browse files
authored
[PTI-SDK] Use find_package to build samples (#3)
Instead of using environmental variables set by oneAPI, use the CMake `find_package` commands. This is one of the primary ways of adding a pre-built dependency to a CMake project. Also, I found sporadic build failures with the "manual" way of including dependencies. Fixes a task in the code comments. Improves documentation on existing custom "Find" modules. It also includes the copyright for CMake inside the third-party-programs.txt file. Fixes syntax error in `sdk/cmake/Modules/macros.cmake`. This causes a build error on machines where `spdlog` is pre-installed. Signed-off-by: Schilling, Matthew <[email protected]>
1 parent 6146ca2 commit 7522781

File tree

10 files changed

+341
-153
lines changed

10 files changed

+341
-153
lines changed

sdk/CMakeLists.txt

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -260,75 +260,41 @@ endif()
260260

261261
if(PTI_BUILD_SAMPLES)
262262
if(HAVE_SYCL)
263+
find_package(MKL CONFIG PATHS $ENV{MKLROOT} NO_DEFAULT_PATH)
264+
message(STATUS "Imported oneMKL targets: ${MKL_IMPORTED_TARGETS}")
265+
find_package(dnnl)
266+
find_package(oneDPL)
267+
find_package(TBB)
268+
find_package(DevUtilities)
269+
263270
add_subdirectory(samples/dpc_gemm)
264271
add_subdirectory(samples/dpc_gemm_threaded)
265272
add_subdirectory(samples/vector_sq_add)
266-
# TODO([email protected]): A better way to do this is to write
267-
# Find modules for each dependency. MKL, DNNL, DPL, etc..
268-
if(DEFINED ENV{MKLROOT})
269-
set(ONEMKL_IS_AVAILABLE TRUE)
270-
else()
271-
message(
272-
WARNING
273-
"Unable to detect oneMKL installation. All samples will not be built."
274-
)
275-
endif()
276-
277-
find_package(dnnl REQUIRED)
278273

279-
if(TARGET DNNL::dnnl)
280-
set(ONEDNNL_IS_AVAILABLE TRUE)
281-
else()
282-
message(
283-
WARNING
284-
"Unable to detect oneDNNL installation. All samples will not be built."
285-
)
274+
if(TARGET DevUtilities::utils)
275+
add_subdirectory(samples/iso3dfd_dpcpp)
286276
endif()
287277

288-
find_package(oneDPL)
289-
290-
if(TARGET oneDPL)
291-
set(ONEDPL_IS_AVAILABLE TRUE)
278+
if(TARGET MKL::MKL)
279+
add_subdirectory(samples/onemkl_gemm)
292280
else()
293281
message(
294282
WARNING
295-
"Unable to detect oneDPL installation. All samples will not be built."
283+
"Unable to build onemkl_gemm sample due to missing MKL installation"
296284
)
297285
endif()
298286

299-
find_package(TBB)
300-
301-
if(TARGET TBB::tbb)
302-
set(TBB_IS_AVAILABLE TRUE)
303-
else()
304-
message(
305-
WARNING
306-
"Unable to detect tbb installation. All samples will not be built.")
307-
endif()
308-
309-
if(DEFINED ENV{ONEAPI_ROOT})
310-
set(ONEAPI_IS_AVAILABLE TRUE)
287+
if(TARGET MKL::MKL
288+
AND TARGET DNNL::dnnl
289+
AND TARGET oneDPL
290+
AND TARGET TBB::tbb)
291+
add_subdirectory(samples/dlworkloads)
311292
else()
312293
message(
313294
WARNING
314-
"Unable to detect oneAPI installation. All samples will not be built."
295+
"Unable to build dlworkloads sample due to missing oneAPI component(s)"
315296
)
316297
endif()
317-
318-
if(DEFINED ONEMKL_IS_AVAILABLE)
319-
add_subdirectory(samples/onemkl_gemm)
320-
endif()
321-
322-
if(DEFINED ONEMKL_IS_AVAILABLE
323-
AND DEFINED ONEDNNL_IS_AVAILABLE
324-
AND DEFINED ONEDPL_IS_AVAILABLE
325-
AND DEFINED TBB_IS_AVAILABLE)
326-
add_subdirectory(samples/dlworkloads)
327-
endif()
328-
329-
if(DEFINED ONEAPI_IS_AVAILABLE)
330-
add_subdirectory(samples/iso3dfd_dpcpp)
331-
endif()
332298
endif()
333299
endif()
334300

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2+
# file Copyright.txt or https://cmake.org/licensing for details.
3+
4+
#[=======================================================================[.rst:
5+
FindDevUtilities
6+
-------
7+
8+
Finds the dpc_common library. This is a library that is part of the standard
9+
oneAPI installation but is not part of a oneAPI component.
10+
11+
It is a header-only library. This module just finds its include path.
12+
13+
It is primarily used in the
14+
`oneAPI samples <https://github.com/oneapi-src/oneAPI-samples>`_
15+
16+
Imported Targets
17+
^^^^^^^^^^^^^^^^
18+
19+
This module provides the following imported targets, if found:
20+
21+
``DevUtilities::utils``
22+
Common samples include path
23+
24+
Result Variables
25+
^^^^^^^^^^^^^^^^
26+
27+
This will define the following variables:
28+
29+
``DevUtilities_FOUND``
30+
True if the system has the DevUtilities library.
31+
``DevUtilities_INCLUDE_DIRS``
32+
Include directories needed to use DevUtilities.
33+
34+
Cache Variables
35+
^^^^^^^^^^^^^^^
36+
37+
The following cache variables may also be set:
38+
39+
``DevUtilities_INCLUDE_DIR``
40+
The directory containing ``dpc_common.hpp``.
41+
42+
#]=======================================================================]
43+
44+
# Based on tutorial found in CMake manual:
45+
# https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html
46+
if(UNIX)
47+
find_path(
48+
DevUtilities_INCLUDE_DIR
49+
NAMES dpc_common.hpp
50+
HINTS ENV CPATH ENV LD_LIBRARY_PATH ENV CMPLR_ROOT
51+
PATHS /opt/intel/oneapi/dev-utilities /opt/intel/oneapi/dev-utilities/latest
52+
/opt/intel/oneapi/dev-utilities/linux
53+
PATH_SUFFIXES include linux/include)
54+
endif()
55+
56+
include(FindPackageHandleStandardArgs)
57+
find_package_handle_standard_args(
58+
DevUtilities
59+
FOUND_VAR DevUtilities_FOUND
60+
REQUIRED_VARS DevUtilities_INCLUDE_DIR)
61+
62+
if(DevUtilities_FOUND AND NOT TARGET DevUtilities::utils)
63+
add_library(DevUtilities::utils INTERFACE IMPORTED)
64+
set_target_properties(
65+
DevUtilities::utils PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
66+
"${DevUtilities_INCLUDE_DIR}")
67+
endif()
68+
69+
mark_as_advanced(DevUtilities_INCLUDE_DIR)

sdk/cmake/Modules/FindXpti.cmake

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
FindXpti
66
-------
77
8-
Finds the Xpti library.
8+
Finds the Xpti library. Xpti is part of the Intel/LLVM project. It is also
9+
included as part of the standard oneAPI installation.
10+
11+
`Intel/LLVM <https://github.com/intel/llvm>`_
12+
13+
Further documentation on linking and using XPTI can be found here:
14+
https://github.com/intel/llvm/blob/sycl/xptifw/doc/XPTI_Framework.md.
915
1016
Imported Targets
1117
^^^^^^^^^^^^^^^^
@@ -43,7 +49,6 @@ The following cache variables may also be set:
4349

4450
# Based on tutorial found in CMake manual:
4551
# https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html
46-
# TODO: Change the copyright?
4752
if(UNIX)
4853
find_path(
4954
Xpti_INCLUDE_DIR

sdk/cmake/Modules/macros.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ endmacro()
767767
macro(GetSpdlog)
768768
find_package(spdlog 1.6.0 QUIET)
769769

770-
if(NOT spdlog::spdlog OR NOT spdlog::spdlog_header_only)
770+
if(NOT TARGET spdlog::spdlog OR NOT TARGET spdlog::spdlog_header_only)
771771
include(FetchContent)
772772
FetchContent_Declare(
773773
fmt
@@ -803,7 +803,7 @@ macro(GetSpdlog)
803803
endmacro()
804804

805805
macro(GetGTest)
806-
if(NOT GTest::gtest OR NOT GTest::gtest_main)
806+
if(NOT TARGET GTest::gtest OR NOT TARGET GTest::gtest_main)
807807
include(FetchContent)
808808
FetchContent_Declare(
809809
googletest

sdk/samples/dlworkloads/CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,22 @@ add_link_options(-fsycl -gline-tables-only)
1717
add_executable(dlworkload ${SOURCES})
1818
target_include_directories(dlworkload PRIVATE ../samples_utilities)
1919

20-
find_package(oneDPL REQUIRED)
21-
2220
# Allow building in-source and out-of-source
2321
if (NOT TARGET Pti::pti_view)
2422
find_package(Pti REQUIRED)
2523
endif()
2624

25+
if (NOT TARGET oneDPL)
26+
find_package(oneDPL REQUIRED)
27+
endif()
28+
2729
if (NOT TARGET DNNL::dnnl)
2830
find_package(dnnl REQUIRED)
2931
endif()
3032

31-
target_include_directories(dlworkload SYSTEM PUBLIC $ENV{MKLROOT}/include)
32-
33-
target_link_libraries(dlworkload PUBLIC DNNL::dnnl -lmkl_sycl -lmkl_intel_ilp64 -lmkl_core -lmkl_tbb_thread oneDPL Pti::pti_view)
33+
if (NOT TARGET MKL::MKL)
34+
find_package(MKL REQUIRED)
35+
endif()
3436

37+
target_include_directories(dlworkload SYSTEM PUBLIC $<TARGET_PROPERTY:MKL::MKL,INTERFACE_INCLUDE_DIRECTORIES>)
38+
target_link_libraries(dlworkload DNNL::dnnl -lmkl_sycl -lmkl_intel_ilp64 -lmkl_core -lmkl_tbb_thread oneDPL Pti::pti_view)

sdk/samples/iso3dfd_dpcpp/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ if (NOT TARGET Pti::pti_view)
2828
find_package(Pti REQUIRED)
2929
endif()
3030

31+
if (NOT TARGET DevUtilities::utils)
32+
find_package(DevUtilities REQUIRED)
33+
endif()
34+
35+
3136
add_subdirectory (src)

sdk/samples/iso3dfd_dpcpp/src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ target_link_options(iso3dfd.exe PUBLIC -O3 -fsycl --std=c++17)
1818
target_include_directories(
1919
iso3dfd.exe PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../samples_utilities
2020
${CMAKE_CURRENT_SOURCE_DIR}/../include)
21-
target_link_libraries(iso3dfd.exe PUBLIC Pti::pti_view sycl)
21+
target_link_libraries(iso3dfd.exe PUBLIC Pti::pti_view sycl DevUtilities::utils)
2222

2323
if(SHARED_KERNEL)
2424
target_compile_definitions(iso3dfd.exe PUBLIC USED_SHARED)

sdk/samples/iso3dfd_dpcpp/src/iso3dfd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include <iostream>
3535
#include <string>
3636
#include "device_selector.hpp"
37-
#include "dpc_common.hpp"
37+
#include <dpc_common.hpp>
3838
#include "pti_view.h"
3939
#include "samples_utils.h"
4040
namespace oneapi {}

sdk/samples/onemkl_gemm/CMakeLists.txt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,21 @@ if(NOT has_sycl)
1616
message(FATAL_ERROR "${PROJECT_NAME} requres a sycl compatible compiler")
1717
endif()
1818

19-
add_compile_options(-fsycl -gline-tables-only -mkl -I$MKLROOT/include/)
20-
add_link_options(-fsycl -gline-tables-only -mkl -L$MKLROOT/lib -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl -lmkl_sycl)
21-
2219
add_executable(onemkl_gemm_exe onemkl_gemm.cpp)
23-
target_include_directories(onemkl_gemm_exe PRIVATE ../samples_utilities)
2420

2521
if (NOT TARGET Pti::pti_view)
2622
find_package(Pti REQUIRED)
2723
endif()
2824

29-
target_link_libraries(onemkl_gemm_exe PUBLIC Pti::pti_view)
25+
if (NOT TARGET MKL::MKL)
26+
find_package(MKL REQUIRED)
27+
endif()
28+
29+
target_compile_options(onemkl_gemm_exe PUBLIC "-fsycl" "-mkl" "-gline-tables-only")
30+
target_link_options(onemkl_gemm_exe PUBLIC "-fsycl" "-mkl" "-gline-tables-only")
3031

32+
target_link_libraries(onemkl_gemm_exe PUBLIC mkl_intel_lp64 mkl_sequential mkl_core mkl_sycl Pti::pti_view)
33+
target_include_directories(onemkl_gemm_exe SYSTEM PUBLIC $<TARGET_PROPERTY:MKL::MKL,INTERFACE_INCLUDE_DIRECTORIES>)
3134
target_include_directories(onemkl_gemm_exe
32-
PRIVATE "${PROJECT_SOURCE_DIR}/../../src/utils")
33-
if(CMAKE_INCLUDE_PATH)
34-
target_include_directories(onemkl_gemm_exe PUBLIC "${CMAKE_INCLUDE_PATH}")
35-
endif()
35+
PRIVATE "${PROJECT_SOURCE_DIR}/../../src/utils"
36+
"${PROJECT_SOURCE_DIR}/../samples_utilities")

0 commit comments

Comments
 (0)