Skip to content
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
31 changes: 24 additions & 7 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
- main
pull_request:

permissions:
contents: read

jobs:
format:
name: Check code formatting
Expand All @@ -14,20 +17,20 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y clang-format clang-format-18
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
- name: Check format
run: |
git-clang-format --binary clang-format-18 --diff origin/main --extensions cpp,hpp,c,cl > output.txt
git-clang-format --binary clang-format-18 --diff origin/main --extensions cpp,hpp,c,cl > output.txt || true
cat output.txt
grep -E "(no modified files to format|clang-format did not modify any files)" output.txt
build-android:
name: Android Build
needs: format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
- name: Install dependencies
Expand All @@ -38,12 +41,23 @@ jobs:
run: |
git clone --depth 1 --branch v51.2 https://github.com/google/perfetto third_party/perfetto
git clone --depth 1 --branch v2026.05.29 https://github.com/KhronosGroup/OpenCL-Headers.git third_party/opencl-headers
git clone --depth 1 --branch v2026.05.29 https://github.com/KhronosGroup/OpenCL-ICD-Loader.git third_party/opencl-icd-loader
- name: Download and extract Android NDK
run: |
wget https://dl.google.com/android/repository/android-ndk-r27d-linux.zip -O android-ndk.zip
unzip android-ndk.zip -d .
rm android-ndk.zip
ls -l
- name: Build OpenCL-ICD-Loader
shell: bash
run: |
cmake -B third_party/opencl-icd-loader/build -S third_party/opencl-icd-loader -G Ninja \
-DCMAKE_TOOLCHAIN_FILE="$(pwd)/android-ndk-r27d/build/cmake/android.toolchain.cmake" \
-DANDROID_ABI="arm64-v8a" \
-DANDROID_PLATFORM="35" \
-DOPENCL_ICD_LOADER_HEADERS_DIR="$(pwd)/third_party/opencl-headers" \
-DCMAKE_BUILD_TYPE=Release
cmake --build third_party/opencl-icd-loader/build
- name: Build
shell: bash
run: |
Expand All @@ -53,14 +67,15 @@ jobs:
-DANDROID_PLATFORM="35" \
-DPERFETTO_SDK_PATH="third_party/perfetto/sdk" \
-DOPENCL_HEADER_PATH="third_party/opencl-headers" \
-DOPENCL_LIBRARY_PATH="$(pwd)/third_party/opencl-icd-loader/build" \
-DCMAKE_BUILD_TYPE=Release
cmake --build build
build-macos:
name: MacOS Build
needs: format
runs-on: macos-latest
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
- name: Clone dependencies
Expand All @@ -80,7 +95,7 @@ jobs:
needs: format
runs-on: windows-latest
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
- name: Clone dependencies
Expand All @@ -102,15 +117,15 @@ jobs:
needs: format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install ninja-build clang-18
- name: Setup ccache
uses: hendrikmuhs/[email protected]
uses: hendrikmuhs/ccache-action@5ebbd400eff9e74630f759d94ddd7b6c26299639 # v1.2
with:
variant: ccache
max-size: 2G
Expand Down Expand Up @@ -161,6 +176,7 @@ jobs:
cmake -B build_debug -S . -G Ninja \
-DPERFETTO_SDK_PATH="${{ github.workspace }}/third_party/perfetto/sdk/" \
-DOPENCL_HEADER_PATH="$(pwd)/third_party/opencl-headers" \
-DOPENCL_LIBRARY_PATH="$(pwd)/third_party/opencl-icd-loader/build" \
-DCMAKE_CXX_COMPILER="$(which clang++)" \
-DCMAKE_BUILD_TYPE=Debug
cmake --build build_debug
Expand All @@ -169,6 +185,7 @@ jobs:
cmake -B build_release -S . -G Ninja \
-DPERFETTO_SDK_PATH="${{ github.workspace }}/third_party/perfetto/sdk/" \
-DOPENCL_HEADER_PATH="$(pwd)/third_party/opencl-headers" \
-DOPENCL_LIBRARY_PATH="$(pwd)/third_party/opencl-icd-loader/build" \
-DCMAKE_CXX_COMPILER="$(which clang++)" \
-DCMAKE_C_COMPILER="$(which clang)" \
-DCLKP_BUILD_TESTS=1 \
Expand Down
26 changes: 25 additions & 1 deletion Android.bp.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,37 @@ license {

cc_library_shared {
name: "opencl-kernel-profiler",
srcs: ["src/opencl-kernel-profiler.cpp"],
srcs: ["layer/layer.cpp"],
local_include_dirs: ["include"],
shared_libs: ["liblog"],
static_libs: ["libperfetto_client_experimental"],
header_libs: ["OpenCL-Headers"],
soc_specific: true,
}

cc_binary {
name: "clkp-extractor",
host_supported: true,
srcs: ["extractor/extractor.cpp"],
local_include_dirs: ["include"],
shared_libs: ["liblog"],
static_libs: ["libperfetto_client_experimental"],
soc_specific: true,
}

cc_binary {
name: "clkp-runner",
srcs: ["runner/runner.cpp"],
local_include_dirs: ["include"],
shared_libs: [
"//external/OpenCL-ICD-Loader:libOpenCL",
"liblog",
],
static_libs: ["libperfetto_client_experimental"],
header_libs: ["OpenCL-Headers"],
soc_specific: true,
}

cc_genrule {
name: "opencl-kernel-profiler-path",
out: ["opencl-kernel-profiler.lay"],
Expand Down
31 changes: 29 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ if (SPIRV_DISASSEMBLY)
endif()
endif()

add_library (opencl-kernel-profiler SHARED src/opencl-kernel-profiler.cpp)
target_include_directories(opencl-kernel-profiler PUBLIC ${PERFETTO_SDK_PATH})
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()
Expand Down Expand Up @@ -89,6 +89,33 @@ 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 ()
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ Then run the application using `opencl-kernel-profiler.sh`. This script will tak
# Wait for the device to reboot, then:
adb root
adb remount
adb shell mkdir -p /vendor/etc/Khronos/OpenCL/layers/
adb push $OUT/vendor/lib64/opencl-kernel-profiler.so /vendor/lib64/
adb push $OUT/vendor/etc/Khronos/OpenCL/layers/opencl-kernel-profiler.lay /vendor/etc/Khronos/OpenCL/layers/
adb shell chcon u:object_r:same_process_hal_file:s0 /vendor/lib64/opencl-kernel-profiler.so
```

Any application using the `OpenCL-ICD-Loader` will go through the `opencl-kernel-profiler`.
Expand Down
Loading
Loading