Skip to content
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

Profiler class and native code to support self-profiling #2066

Merged
merged 9 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 21 additions & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,24 @@ 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.
limitations under the License.

--------------------------------------------------------------------------------

This project includes code from flatbuffers (https://github.com/google/flatbuffers).

Copyright 2021 Google Inc. All rights reserved.

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.

--------------------------------------------------------------------------------
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<BUILD_TESTS>OFF</BUILD_TESTS>
<BUILD_BENCHMARKS>OFF</BUILD_BENCHMARKS>
<BUILD_FAULTINJ>ON</BUILD_FAULTINJ>
<BUILD_PROFILER>ON</BUILD_PROFILER>
<ai.rapids.cudf.nvtx.enabled>false</ai.rapids.cudf.nvtx.enabled>
<ai.rapids.refcount.debug>false</ai.rapids.refcount.debug>
<cuda.version>cuda11</cuda.version>
Expand Down Expand Up @@ -345,6 +346,8 @@
</activation>
<properties>
<jni.classifier>${cuda.version}-arm64</jni.classifier>
<!-- CUPTI does not have a static library for arm64 yet -->
<BUILD_PROFILER>OFF</BUILD_PROFILER>
</properties>
</profile>
</profiles>
Expand Down Expand Up @@ -457,6 +460,7 @@
<arg value="-DBUILD_TESTS=${BUILD_TESTS}"/>
<arg value="-DBUILD_BENCHMARKS=${BUILD_BENCHMARKS}"/>
<arg value="-DBUILD_FAULTINJ=${BUILD_FAULTINJ}"/>
<arg value="-DBUILD_PROFILER=${BUILD_PROFILER}"/>
</exec>
<exec dir="${native.build.path}"
failonerror="true"
Expand Down Expand Up @@ -548,6 +552,12 @@
<include>libcufilejni.so</include>
</includes>
</resource>
<resource>
<directory>${native.build.path}/profiler</directory>
<includes>
<include>libprofilerjni.so</include>
</includes>
</resource>
<resource>
<directory>${libcudfjni.build.path}</directory>
<includes>
Expand Down
28 changes: 27 additions & 1 deletion src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ option(USE_GDS "Build with GPUDirect Storage (GDS)/cuFile support" OFF)
option(BUILD_TESTS "Configure CMake to build tests" OFF)
option(BUILD_BENCHMARKS "Configure CMake to build (google) benchmarks" OFF)
option(BUILD_FAULTINJ "Configure CMake to build fault injection" ON)
option(BUILD_PROFILER "Configure CMake to build profiler" ON)

message(
VERBOSE "SPARK_RAPIDS_JNI: Build with per-thread default stream:
Expand All @@ -60,6 +61,12 @@ set(SPARK_RAPIDS_JNI_CUDA_DEFINITIONS "")
set(SPARK_RAPIDS_JNI_BUILD_TESTS ${BUILD_TESTS})
set(SPARK_RAPIDS_JNI_BUILD_BENCHMARKS ${BUILD_BENCHMARKS})
set(SPARK_RAPIDS_JNI_BUILD_FAULTINJ ${BUILD_FAULTINJ})
if(NOT SPARK_RAPIDS_JNI_GENERATED_INCLUDE_DIR)
set(SPARK_RAPIDS_JNI_GENERATED_INCLUDE_DIR ${SPARK_RAPIDS_JNI_BINARY_DIR}/generated/include)
endif()
if(NOT SPARK_RAPIDS_JNI_GENERATED_SOURCE_DIR)
set(SPARK_RAPIDS_JNI_GENERATED_SOURCE_DIR ${SPARK_RAPIDS_JNI_BINARY_DIR}/generated/src)
endif()

# Set RMM logging level
set(RMM_LOGGING_LEVEL
Expand Down Expand Up @@ -94,6 +101,21 @@ include(cmake/Modules/ConfigureCUDA.cmake) # set other CUDA compilation flags
# ##################################################################################################
# * dependencies ----------------------------------------------------------------------------------

# version header
find_package(Git REQUIRED)
execute_process(COMMAND
"${GIT_EXECUTABLE}" describe --abbrev=40 --always --dirty --long
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE SPARK_RAPIDS_JNI_COMMIT_DETAILS
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
configure_file(
src/spark_rapids_jni_version.cpp.in
"${SPARK_RAPIDS_JNI_GENERATED_SOURCE_DIR}/spark_rapids_jni_version.cpp"
@ONLY
)

# find NVTX
include(${CUDF_DIR}/cpp/cmake/thirdparty/get_nvtx.cmake)

Expand Down Expand Up @@ -256,7 +278,7 @@ add_dependencies(cudfjnistub spark_rapids_jni)
if(USE_GDS)
include(${CUDF_DIR}/cpp/cmake/Modules/FindcuFile.cmake)
find_library(CUFILEJNI_LIB "libcufilejni.a" REQUIRED NO_DEFAULT_PATH
HINTS "${PROJECT_BINARY_DIR}/../libcudfjni"
HINTS "${SPARK_RAPIDS_JNI_BINARY_DIR}/../libcudfjni"
)
add_library(cufilejni SHARED src/emptyfile.cpp)
set_target_properties(
Expand Down Expand Up @@ -300,3 +322,7 @@ endif()
if(SPARK_RAPIDS_JNI_BUILD_FAULTINJ)
add_subdirectory(faultinj)
endif()

if(BUILD_PROFILER)
add_subdirectory(profiler)
endif()
33 changes: 33 additions & 0 deletions src/main/cpp/cmake/get_flatbuffers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# =============================================================================
# Copyright (c) 2024, NVIDIA CORPORATION.
#
# 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.
# =============================================================================

# Use CPM to find or clone flatbuffers
function(find_and_configure_flatbuffers VERSION)

rapids_cpm_find(
flatbuffers ${VERSION}
GLOBAL_TARGETS flatbuffers
CPM_ARGS
GIT_REPOSITORY https://github.com/google/flatbuffers.git
GIT_TAG v${VERSION}
GIT_SHALLOW TRUE
)

rapids_export_find_package_root(
BUILD flatbuffers "${flatbuffers_BINARY_DIR}" EXPORT_SET profilerjni-exports
)

endfunction()

find_and_configure_flatbuffers(24.3.25)
98 changes: 98 additions & 0 deletions src/main/cpp/profiler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# =============================================================================
# Copyright (c) 2024, NVIDIA CORPORATION.
#
# 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.
# =============================================================================

include(../cmake/get_flatbuffers.cmake)

# ##################################################################################################
# * flatbuffer generation---------------------------------------------------------------------------

set(SPARK_RAPIDS_JNI_FBS_DIR "${SPARK_RAPIDS_JNI_SOURCE_DIR}/../fbs")
add_custom_command(
OUTPUT ${SPARK_RAPIDS_JNI_GENERATED_INCLUDE_DIR}/profiler_generated.h
DEPENDS "${SPARK_RAPIDS_JNI_FBS_DIR}/profiler.fbs"
WORKING_DIRECTORY "${SPARK_RAPIDS_JNI_FBS_DIR}"
VERBATIM
COMMAND ${CMAKE_COMMAND} -E make_directory "${SPARK_RAPIDS_JNI_GENERATED_INCLUDE_DIR}"
COMMAND
$<TARGET_FILE:flatbuffers::flatc> --cpp -o "${SPARK_RAPIDS_JNI_GENERATED_INCLUDE_DIR}" profiler.fbs
COMMENT "Generating profiler flatbuffer code"
)

# ##################################################################################################
# * profiler JNI -----------------------------------------------------------------------------------

add_library(profilerjni SHARED
ProfilerJni.cpp
profiler_debug.cpp
profiler_serializer.cpp
"${SPARK_RAPIDS_JNI_GENERATED_SOURCE_DIR}/spark_rapids_jni_version.cpp"
"${SPARK_RAPIDS_JNI_GENERATED_INCLUDE_DIR}/profiler_generated.h"
)

set_target_properties(
profilerjni
PROPERTIES BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN"
# set target compile options
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_VISIBILITY_PRESET "hidden"
VISIBILITY_INLINES_HIDDEN TRUE
)

target_include_directories(
profilerjni
PRIVATE "${JNI_INCLUDE_DIRS}"
"${CUDAToolkit_INCLUDE_DIRS}"
"${SPARK_RAPIDS_JNI_GENERATED_INCLUDE_DIR}"
"${SPARK_RAPIDS_JNI_SOURCE_DIR}/src"
)

find_library(CUPTI_LIBRARY_PATH cupti_static PATHS
"/usr/local/cuda/lib64"
"/usr/local/cuda/extras/CUPTI/lib64"
)

target_link_libraries(profilerjni
PRIVATE ${CUPTI_LIBRARY_PATH} nvtx3-cpp flatbuffers::flatbuffers
)

file(READ "${SPARK_RAPIDS_JNI_FBS_DIR}/profiler.fbs" SPARK_RAPIDS_JNI_PROFILER_SCHEMA)
configure_file(
profiler_schema.cpp.in
"${SPARK_RAPIDS_JNI_GENERATED_SOURCE_DIR}/profiler_schema.cpp"
@ONLY
)

add_executable(spark_rapids_profile_converter
spark_rapids_profile_converter.cpp
"${SPARK_RAPIDS_JNI_GENERATED_SOURCE_DIR}/profiler_schema.cpp"
"${SPARK_RAPIDS_JNI_GENERATED_SOURCE_DIR}/spark_rapids_jni_version.cpp"
"${SPARK_RAPIDS_JNI_GENERATED_INCLUDE_DIR}/profiler_generated.h"
)

target_include_directories(
spark_rapids_profile_converter
PRIVATE
"${CUDAToolkit_INCLUDE_DIRS}"
"${SPARK_RAPIDS_JNI_SOURCE_DIR}/src"
"${SPARK_RAPIDS_JNI_GENERATED_INCLUDE_DIR}"
)

target_link_libraries(spark_rapids_profile_converter
"${CUPTI_LIBRARY_PATH}"
flatbuffers::flatbuffers
dl
pthread
rt)
Loading
Loading