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
166 changes: 166 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# =============================================================================
# cmake-format: off
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# cmake-format: on
# =============================================================================

cmake_minimum_required(VERSION 4.0 FATAL_ERROR)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
include(cmake/rapids_config.cmake)
include(rapids-cmake)
include(rapids-cpm)
include(rapids-export)
include(rapids-find)
rapids_cpm_init()
endif()

project(
rtcx
VERSION 0.1.0
LANGUAGES CXX
)

option(RTCX_STATIC_LINK_NVRTC "Use static linking for NVRTC" OFF)
option(RTCX_STATIC_LINK_NVJITLINK "Use static linking for nvJitLink" OFF)

rapids_find_package(
CUDAToolkit REQUIRED
BUILD_EXPORT_SET rtcx-exports
INSTALL_EXPORT_SET rtcx-exports
)

if(NOT TARGET zstd)
set(CPM_DOWNLOAD_zstd ON)
rapids_cpm_find(
zstd 1.5.7
GLOBAL_TARGETS zstd
CPM_ARGS
GIT_REPOSITORY https://github.com/facebook/zstd.git
GIT_TAG v1.5.7
GIT_SHALLOW FALSE SOURCE_SUBDIR build/cmake
OPTIONS "ZSTD_BUILD_STATIC ON" "ZSTD_BUILD_SHARED OFF" "ZSTD_BUILD_TESTS OFF"
"ZSTD_BUILD_PROGRAMS OFF" "BUILD_SHARED_LIBS OFF"
)

if(zstd_ADDED)
# disable weak symbols support to hide tracing APIs as well
target_compile_definitions(libzstd_static PRIVATE ZSTD_HAVE_WEAK_SYMBOLS=0)
# expose experimental API
target_compile_definitions(libzstd_static PUBLIC ZSTD_STATIC_LINKING_ONLY=0N)
# suppress warnings from uninitialized variables and redefining ZSTD_STATIC_LINKING_ONLY
target_compile_options(libzstd_static PRIVATE -w)
add_library(zstd ALIAS libzstd_static)
endif()
endif()

if(NOT TARGET nvtx3::nvtx3-cpp)
include(${rapids-cmake-dir}/cpm/nvtx3.cmake)
rapids_cpm_nvtx3()
endif()

add_library(rtcx STATIC hash.cpp rtcx.cpp)
add_library(rtcx::rtcx ALIAS rtcx)

set_target_properties(
rtcx
PROPERTIES CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN YES
POSITION_INDEPENDENT_CODE ON
)

target_include_directories(
rtcx
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
PRIVATE ${CUDAToolkit_INCLUDE_DIRS}
)

target_link_libraries(rtcx PRIVATE zstd ${CMAKE_DL_LIBS} nvtx3::nvtx3-cpp)

if(RTCX_STATIC_LINK_NVRTC)
target_link_libraries(rtcx PRIVATE CUDA::nvrtc_static CUDA::nvrtc_builtins_static)
target_compile_definitions(rtcx PRIVATE RTCX_STATIC_LINK_LIBNVRTC=1)
else()
target_compile_definitions(rtcx PRIVATE RTCX_STATIC_LINK_LIBNVRTC=0)
endif()

if(RTCX_STATIC_LINK_NVJITLINK)
target_link_libraries(rtcx PRIVATE CUDA::nvJitLink_static)
target_compile_definitions(rtcx PRIVATE RTCX_STATIC_LINK_LIBNVJITLINK=1)
else()
target_compile_definitions(rtcx PRIVATE RTCX_STATIC_LINK_LIBNVJITLINK=0)
endif()

# =============================================================================
# Install / Export
# =============================================================================
include(GNUInstallDirs)
include(${rapids-cmake-dir}/cmake/install_lib_dir.cmake)
rapids_cmake_install_lib_dir(lib_dir)

# Option to control install (default ON when built standalone, OFF when used as subdirectory)
option(RTCX_INSTALL "Enable installation of rtcx targets" ${PROJECT_IS_TOP_LEVEL})

set(rtcx_install_code_string
[=[
# Embed functions (add_embed, embed_includes, embed_blob, embed)
# are included automatically so consumers don't need explicit include().
include("${CMAKE_CURRENT_LIST_DIR}/embed.cmake")

# Set rtcx_LIBCXX_DIR for consumers using embed_includes with libcxx headers.
set(rtcx_LIBCXX_DIR "${PACKAGE_PREFIX_DIR}/share/rtcx/libcxx")
]=]
)

string(
CONFIGURE
[=[
# Embed functions (add_embed, embed_includes, embed_blob, embed)
# are included automatically so consumers don't need explicit include().
include("@CMAKE_CURRENT_SOURCE_DIR@/embed.cmake")

# Set rtcx_LIBCXX_DIR for consumers using embed_includes with libcxx headers.
set(rtcx_LIBCXX_DIR "@CMAKE_CURRENT_SOURCE_DIR@/libcxx")
]=]
rtcx_build_code_string
@ONLY
)

if(NOT RTCX_INSTALL)
set(rtcx_exclude_from_install EXCLUDE_FROM_ALL)
endif()

install(
TARGETS rtcx
EXPORT rtcx-exports
ARCHIVE DESTINATION ${lib_dir}
INCLUDES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
${rtcx_exclude_from_install}
)

if(RTCX_INSTALL)
install(FILES rtcx.hpp hash.hpp embed.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rtcx)
install(FILES embed.cmake embed.in.cpp DESTINATION ${lib_dir}/cmake/rtcx)
install(DIRECTORY libcxx/ DESTINATION ${CMAKE_INSTALL_DATADIR}/rtcx/libcxx)

rapids_export(
INSTALL rtcx
EXPORT_SET rtcx-exports
GLOBAL_TARGETS rtcx
NAMESPACE rtcx::
FINAL_CODE_BLOCK rtcx_install_code_string
)
endif()

# Build-tree export (always, so CPM consumers can find_package from the build tree)
rapids_export(
BUILD rtcx
EXPORT_SET rtcx-exports
GLOBAL_TARGETS rtcx
NAMESPACE rtcx::
FINAL_CODE_BLOCK rtcx_build_code_string
)
58 changes: 58 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Contributing to librtcx

Contributions to librtcx fall into the following categories:

1. To report a bug, request a new feature, or report a problem with documentation, please file an
[issue](https://github.com/rapidsai/librtcx/issues/new/choose) describing the problem or new feature
in detail.
2. To propose and implement a new feature, please file a new feature request
[issue](https://github.com/rapidsai/librtcx/issues/new/choose). Describe the intended feature and
discuss the design and implementation with the team and community. Once the team agrees that the
plan looks good, go ahead and implement it, using the [code contributions](#code-contributions)
guide below.
3. To implement a feature or bug fix for an existing issue, please follow the [code
contributions](#code-contributions) guide below. If you need more context on a particular issue,
please ask in a comment.

As contributors and maintainers to this project, you are expected to abide by the
[Contributor Code of Conduct](https://docs.rapids.ai/resources/conduct/).

## Code contributions

1. Create a fork of the [librtcx repository](https://github.com/rapidsai/librtcx) and check out a branch
with a name that describes your planned work.
2. Write code to address the issue or implement the feature.
3. Add unit tests.
4. [Create your pull request](https://github.com/rapidsai/librtcx/compare).
5. Verify that CI passes all status checks. Fix if needed.
6. Wait for other developers to review your code and update code as needed.
7. Once reviewed and approved, a maintainer will merge your pull request.

If you are unsure about anything, don't hesitate to comment on issues and ask for clarification!

## Code Formatting

librtcx uses [pre-commit](https://pre-commit.com/) to execute code linters and formatters.
These tools ensure a consistent code format throughout the project.

To use `pre-commit`, install via `conda` or `pip`:

```bash
conda install -c conda-forge pre-commit
```

```bash
pip install pre-commit
```

Then run pre-commit hooks before committing code:

```bash
pre-commit run
```

Optionally, you may set up the pre-commit hooks to run automatically when you make a git commit:

```bash
pre-commit install
```
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2020 NVIDIA Corporation
Copyright 2026 NVIDIA Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
1 change: 1 addition & 0 deletions RAPIDS_BRANCH
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# librtcx

RTCX (runtime-compiler extended) is a wrapper around NVRTC and nvJitLink designed to provide:

- User-controlled compilation, linking, caching, and pre-loading of CUDA kernels
- Zero-copy interfaces to manage JIT compilation and linking
- CMake script to embed **compressed** headers directly into an executable without incurring overhead at runtime on every compilation request
- Facilities to pre-load and teardown dynamic library dependencies (`libcuda`, `libnvrtc`, and `libnvJitLink`)

## Platforms Supported
- Linux

## Build-time Requirements
- CMake >= 4.0
- libzstd
- xxHash
- CUDA >= 12.2

# Dependencies
- nvJitlink >= 12.2
- NVRTC >= 12.2
- LibCUDA >= 12.2
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0
83 changes: 83 additions & 0 deletions cmake/RAPIDS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# =============================================================================
# cmake-format: off
# SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION.
# SPDX-License-Identifier: Apache-2.0
# cmake-format: on
# =============================================================================
#
# This is the preferred entry point for projects using rapids-cmake
#
# Enforce the minimum required CMake version for all users
cmake_minimum_required(VERSION 4.0 FATAL_ERROR)

# Allow users to control which version is used
if(NOT (rapids-cmake-branch OR rapids-cmake-version))
message(
FATAL_ERROR "The CMake variable `rapids-cmake-branch` or `rapids-cmake-version` must be defined"
)
endif()

# Allow users to control which GitHub repo is fetched
if(NOT rapids-cmake-repo)
# Define a default repo if the user doesn't set one
set(rapids-cmake-repo rapidsai/rapids-cmake)
endif()

# Allow users to control which branch is fetched
if(NOT rapids-cmake-branch)
# Define a default branch if the user doesn't set one
set(rapids-cmake-branch "release/${rapids-cmake-version}")
endif()

# Allow users to control the exact URL passed to FetchContent
if(NOT rapids-cmake-url)
# Construct a default URL if the user doesn't set one
set(rapids-cmake-url "https://github.com/${rapids-cmake-repo}/")

# In order of specificity
if(rapids-cmake-fetch-via-git)
if(rapids-cmake-sha)
# An exact git SHA takes precedence over anything
set(rapids-cmake-value-to-clone "${rapids-cmake-sha}")
elseif(rapids-cmake-tag)
# Followed by a git tag name
set(rapids-cmake-value-to-clone "${rapids-cmake-tag}")
else()
# Or if neither of the above two were defined, use a branch
set(rapids-cmake-value-to-clone "${rapids-cmake-branch}")
endif()
else()
if(rapids-cmake-sha)
# An exact git SHA takes precedence over anything
set(rapids-cmake-value-to-clone "archive/${rapids-cmake-sha}.zip")
elseif(rapids-cmake-tag)
# Followed by a git tag name
set(rapids-cmake-value-to-clone "archive/refs/tags/${rapids-cmake-tag}.zip")
else()
# Or if neither of the above two were defined, use a branch
set(rapids-cmake-value-to-clone "archive/refs/heads/${rapids-cmake-branch}.zip")
endif()
endif()
endif()

include(FetchContent)
if(rapids-cmake-fetch-via-git)
FetchContent_Declare(
rapids-cmake
GIT_REPOSITORY "${rapids-cmake-url}"
GIT_TAG "${rapids-cmake-value-to-clone}"
)
else()
string(APPEND rapids-cmake-url "${rapids-cmake-value-to-clone}")
FetchContent_Declare(rapids-cmake URL "${rapids-cmake-url}")
endif()
FetchContent_GetProperties(rapids-cmake)
if(rapids-cmake_POPULATED)
# Something else has already populated rapids-cmake, only thing we need to do is setup the
# CMAKE_MODULE_PATH
if(NOT "${rapids-cmake-dir}" IN_LIST CMAKE_MODULE_PATH)
list(APPEND CMAKE_MODULE_PATH "${rapids-cmake-dir}")
endif()
else()
FetchContent_MakeAvailable(rapids-cmake)
endif()
38 changes: 38 additions & 0 deletions cmake/rapids_config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# =============================================================================
# cmake-format: off
# SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION.
# SPDX-License-Identifier: Apache-2.0
# cmake-format: on
# =============================================================================
file(READ "${CMAKE_CURRENT_LIST_DIR}/../VERSION" _rapids_version)
if(_rapids_version MATCHES [[^([0-9]+)\.([0-9]+)\.([0-9]+)]])
set(RAPIDS_VERSION_MAJOR "${CMAKE_MATCH_1}")
set(RAPIDS_VERSION_MINOR "${CMAKE_MATCH_2}")
set(RAPIDS_VERSION_PATCH "${CMAKE_MATCH_3}")
set(RAPIDS_VERSION_MAJOR_MINOR "${RAPIDS_VERSION_MAJOR}.${RAPIDS_VERSION_MINOR}")
set(RAPIDS_VERSION "${RAPIDS_VERSION_MAJOR}.${RAPIDS_VERSION_MINOR}.${RAPIDS_VERSION_PATCH}")
else()
string(REPLACE "\n" "\n " _rapids_version_formatted " ${_rapids_version}")
message(
FATAL_ERROR
"Could not determine RAPIDS version. Contents of VERSION file:\n${_rapids_version_formatted}"
)
endif()

file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/../RAPIDS_BRANCH" RAPIDS_BRANCH)
if(NOT RAPIDS_BRANCH)
message(
FATAL_ERROR
"Could not determine branch name to use for checking out rapids-cmake. The file \"${CMAKE_CURRENT_LIST_DIR}/../RAPIDS_BRANCH\" is missing."
)
endif()

if(NOT rapids-cmake-version)
set(rapids-cmake-version "${RAPIDS_VERSION_MAJOR_MINOR}")
endif()

if(NOT rapids-cmake-branch)
set(rapids-cmake-branch "${RAPIDS_BRANCH}")
endif()

include("${CMAKE_CURRENT_LIST_DIR}/RAPIDS.cmake")
Loading