Skip to content
Open
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
37 changes: 37 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# SPDX-License-Identifier: Apache-2.0

# A clang-format style derived from Python's PEP 7 (4-space indent, Stroustrup braces,
# return type on its own line), except that the column limit is 120 rather than 79.
# Based on https://gist.github.com/pganssle/0e3a5f828b4d07d79447f6ced8e7e4db
BasedOnStyle: Google
AlwaysBreakAfterReturnType: All
AllowShortIfStatementsOnASingleLine: false
BreakBeforeBraces: Stroustrup
ColumnLimit: 120
DerivePointerAlignment: false
IndentWidth: 4
Language: Cpp
PointerAlignment: Right
ReflowComments: true
SpaceBeforeParens: ControlStatements
SpacesInParentheses: false
TabWidth: 4
UseTab: Never

# Keep include order as written; reordering can break order-sensitive builds.
SortIncludes: Never

# Ruff-like wrapping: break after "(", indent arguments, put ")" on its own line.
# This does not contradict PEP7, but extends it to the consistent style where
# calls either fit on a single line or they are broken across multiple lines with
# one argument per line (indented).
AlignAfterOpenBracket: BlockIndent
BinPackArguments: false
BinPackParameters: false
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false

# Don't put short lambdas on a single line.
AllowShortLambdasOnASingleLine: None
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ repos:
- id: ruff-format
exclude: .*\.pyi$

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: 98ad4ddb9c057de2f5b9e93e44e6db959807d68c # frozen: v23.1.3
hooks:
- id: clang-format
types_or: [c, c++, cuda]
exclude: ^cuda_core/(cuda/core/_include/(dlpack|aoti_shim)\.h|third_party/)

- repo: local
hooks:
- id: check-precommit-installed
Expand Down
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ between commits, leaving stale headers or out-of-date stubs in the history.
If the hook isn't installed, `pre-commit run` will print a visible warning
reminding you to run `pre-commit install`.

C, C++ and CUDA sources are formatted with `clang-format` using the
[`.clang-format`](.clang-format) at the repository root, which follows PEP 7
except for a 120-column limit. The
pre-commit hook installs its own pinned `clang-format` (from PyPI) into the
hook environment, so no system-wide installation is required. Vendored code
(for example `dlpack.h` and `cuda_core/third_party/`) is excluded in
`.pre-commit-config.yaml`. To format in your editor, install the same version
with `pip install clang-format==23.1.3`.

Windows contributors: see [Pre-commit lychee workaround](#pre-commit-lychee-workaround) under Development on Windows.

## Pixi lockfiles
Expand Down
22 changes: 9 additions & 13 deletions benchmarks/cuda_bindings/benchmarks/cpp/bench_ctx_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@
#include <cstdlib>
#include <iostream>


static void check_cu(CUresult status, const char* message) {
static void
check_cu(CUresult status, const char *message)
{
if (status != CUDA_SUCCESS) {
const char* error_name = nullptr;
const char *error_name = nullptr;
cuGetErrorName(status, &error_name);
std::cerr << message << ": " << (error_name ? error_name : "unknown") << '\n';
std::exit(1);
}
}


int main(int argc, char** argv) {
int
main(int argc, char **argv)
{
bench::Options options = bench::parse_args(argc, argv);

// Setup: init CUDA and create a context
Expand Down Expand Up @@ -80,21 +82,15 @@ int main(int argc, char** argv) {
// --- device_primary_ctx_retain ---
// Outer retain so the benchmarked retain/release pair just bumps the refcount.
CUcontext primary_outer = nullptr;
check_cu(
cuDevicePrimaryCtxRetain(&primary_outer, device),
"cuDevicePrimaryCtxRetain (setup) failed"
);
check_cu(cuDevicePrimaryCtxRetain(&primary_outer, device), "cuDevicePrimaryCtxRetain (setup) failed");
{
CUcontext primary = nullptr;
suite.run("ctx_device.device_primary_ctx_retain", [&]() {
check_cu(cuDevicePrimaryCtxRetain(&primary, device), "cuDevicePrimaryCtxRetain failed");
check_cu(cuDevicePrimaryCtxRelease(device), "cuDevicePrimaryCtxRelease failed");
});
}
check_cu(
cuDevicePrimaryCtxRelease(device),
"cuDevicePrimaryCtxRelease (teardown) failed"
);
check_cu(cuDevicePrimaryCtxRelease(device), "cuDevicePrimaryCtxRelease (teardown) failed");

// Cleanup
check_cu(cuCtxDestroy(ctx), "cuCtxDestroy failed");
Expand Down
12 changes: 7 additions & 5 deletions benchmarks/cuda_bindings/benchmarks/cpp/bench_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@
#include <cstdlib>
#include <iostream>


static void check_cu(CUresult status, const char* message) {
static void
check_cu(CUresult status, const char *message)
{
if (status != CUDA_SUCCESS) {
const char* error_name = nullptr;
const char *error_name = nullptr;
cuGetErrorName(status, &error_name);
std::cerr << message << ": " << (error_name ? error_name : "unknown") << '\n';
std::exit(1);
}
}


int main(int argc, char** argv) {
int
main(int argc, char **argv)
{
bench::Options options = bench::parse_args(argc, argv);

// Setup
Expand Down
Loading
Loading