Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
121 lines (101 loc) · 4.26 KB
/
Copy pathCMakeLists.txt
File metadata and controls
121 lines (101 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Copyright 2023 The OpenCL Kernel Profiler authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required (VERSION 3.24)
project (opencl-kernel-profiler)
set(CMAKE_CXX_STANDARD 17)
# cmake quirk - needed to pick up perfetto when compiled as a shared library on windows
if (WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll" ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
if (NOT PERFETTO_SDK_PATH)
message(FATAL_ERROR "PERFETTO_SDK_PATH not defined")
endif ()
if (NOT PERFETTO_LIBRARY)
add_library(perfetto STATIC ${PERFETTO_SDK_PATH}/perfetto.cc)
set_target_properties(perfetto PROPERTIES POSITION_INDEPENDENT_CODE ON)
set(PERFETTO_LIBRARY perfetto)
endif()
option(SPIRV_DISASSEMBLY "Enable SPIR-V disassembly support" OFF)
if (SPIRV_DISASSEMBLY)
find_library(SPIRV_TOOLS_LIBRARY NAMES SPIRV-Tools libSPIRV-Tools)
find_path(SPIRV_TOOLS_INCLUDE_DIR NAMES spirv-tools/libspirv.hpp)
if (NOT SPIRV_TOOLS_LIBRARY)
message(FATAL_ERROR "SPIRV-Tools library not found")
endif()
if (NOT SPIRV_TOOLS_INCLUDE_DIR)
message(FATAL_ERROR "SPIRV-Tools headers not found")
endif()
endif()
add_library (opencl-kernel-profiler SHARED layer/layer.cpp)
target_include_directories(opencl-kernel-profiler PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${PERFETTO_SDK_PATH})
if (OPENCL_HEADER_PATH)
target_include_directories(opencl-kernel-profiler PUBLIC ${OPENCL_HEADER_PATH})
endif()
target_link_libraries(opencl-kernel-profiler ${PERFETTO_LIBRARY})
if (ANDROID)
target_link_libraries(opencl-kernel-profiler log)
endif()
if (WIN32)
target_link_libraries(opencl-kernel-profiler ws2_32)
endif()
if (SPIRV_DISASSEMBLY)
target_include_directories(opencl-kernel-profiler PUBLIC ${SPIRV_TOOLS_INCLUDE_DIR})
target_link_libraries(opencl-kernel-profiler ${SPIRV_TOOLS_LIBRARY})
target_compile_definitions(opencl-kernel-profiler PRIVATE SPIRV_DISASSEMBLY)
endif()
set(BACKEND "InProcess"
CACHE STRING "Select perfetto backend")
set(BACKEND_OPTIONS
System
InProcess
)
set_property(CACHE BACKEND PROPERTY STRINGS ${BACKEND_OPTIONS})
if (${BACKEND} STREQUAL InProcess)
target_compile_definitions(opencl-kernel-profiler PUBLIC BACKEND_INPROCESS)
endif()
set(TRACE_MAX_SIZE 1024 CACHE STRING "Perfetto trace maximum size")
target_compile_options(opencl-kernel-profiler PUBLIC "-DTRACE_MAX_SIZE=${TRACE_MAX_SIZE}")
set(TRACE_DEST "opencl-kernel-profiler.trace" CACHE STRING "Perfetto trace filename")
target_compile_options(opencl-kernel-profiler PUBLIC "-DTRACE_DEST=\"${TRACE_DEST}\"")
target_compile_options(opencl-kernel-profiler PUBLIC "-DCLKP_PERFETTO_AMALGAMATED")
install(TARGETS opencl-kernel-profiler
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR ANDROID)
add_executable(clkp-extractor extractor/extractor.cpp)
target_include_directories(clkp-extractor PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${PERFETTO_SDK_PATH})
target_link_libraries(clkp-extractor ${PERFETTO_LIBRARY})
target_compile_options(clkp-extractor PUBLIC "-DCLKP_PERFETTO_AMALGAMATED")
if (ANDROID)
target_link_libraries(clkp-extractor log)
endif()
add_executable(clkp-runner runner/runner.cpp)
target_include_directories(clkp-runner PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${PERFETTO_SDK_PATH})
if (OPENCL_HEADER_PATH)
target_include_directories(clkp-runner PUBLIC ${OPENCL_HEADER_PATH})
endif()
if (OPENCL_LIBRARY_PATH)
target_link_directories(clkp-runner PUBLIC ${OPENCL_LIBRARY_PATH})
endif()
target_link_libraries(clkp-runner OpenCL ${PERFETTO_LIBRARY})
target_compile_options(clkp-runner PUBLIC "-DCLKP_PERFETTO_AMALGAMATED")
if (ANDROID)
target_link_libraries(clkp-runner log)
endif()
install(TARGETS clkp-extractor clkp-runner
RUNTIME DESTINATION bin)
endif()
if (CLKP_BUILD_TESTS)
add_subdirectory(tests)
endif ()