Skip to content

Commit ab52ed1

Browse files
committed
Use AllDefinitions
1 parent fd13151 commit ab52ed1

7 files changed

Lines changed: 153 additions & 281 deletions

File tree

‎.clang-format‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# return type on its own line), except that the column limit is 120 rather than 79.
77
# Based on https://gist.github.com/pganssle/0e3a5f828b4d07d79447f6ced8e7e4db
88
BasedOnStyle: Google
9-
BreakAfterReturnType: All
9+
BreakAfterReturnType: AllDefinitions
1010
AllowShortIfStatementsOnASingleLine: Never
1111
BreakBeforeBraces: Stroustrup
1212
ColumnLimit: 120

‎cuda_core/cuda/core/_cpp/rt/api.hpp‎

Lines changed: 115 additions & 206 deletions
Large diffs are not rendered by default.

‎cuda_core/cuda/core/_cpp/rt/context_scope.hpp‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@
1515
namespace cuda_core::rt::detail {
1616

1717
// Implemented in context.cpp
18-
CUresult
19-
enter_context(const ContextHandle &h_context, CUcontext *previous, int *changed) noexcept;
18+
CUresult enter_context(const ContextHandle &h_context, CUcontext *previous, int *changed) noexcept;
2019
// Implemented in context.cpp
21-
CUresult
22-
restore_context(CUcontext previous) noexcept;
20+
CUresult restore_context(CUcontext previous) noexcept;
2321
// Implemented in context.cpp
24-
CUresult
25-
exit_context(CUcontext previous, int changed, CUresult operation_status) noexcept;
22+
CUresult exit_context(CUcontext previous, int changed, CUresult operation_status) noexcept;
2623

2724
// Require a callable to be invocable without throwing.
2825
#define ASSERT_NOTHROW_INVOCABLE(...) \

‎cuda_core/cuda/core/_cpp/rt/driver_api.hpp‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,10 @@ struct FnEntry {
171171
};
172172

173173
// The entries of a table. Implemented in driver_api.cpp.
174-
const FnEntry *
175-
fn_table_entries(FnTable table, std::size_t *count) noexcept;
174+
const FnEntry *fn_table_entries(FnTable table, std::size_t *count) noexcept;
176175

177176
// Whether a table is filled. An acquire load: a true result orders the slots.
178-
bool
179-
fn_table_ready(FnTable table) noexcept;
177+
bool fn_table_ready(FnTable table) noexcept;
180178

181179
// Fill a table from cuda-bindings if it is not ready. The fill acquires the
182180
// GIL, imports cuda.bindings._internal.<lib>, calls
@@ -191,21 +189,18 @@ fn_table_ready(FnTable table) noexcept;
191189
// A failed fill is latched: later calls return false at once and do not
192190
// retry. The fill preserves a pending Python exception and never leaves one
193191
// set. Implemented in py_driver_fns.cpp.
194-
bool
195-
ensure_fn_table(FnTable table) noexcept;
192+
bool ensure_fn_table(FnTable table) noexcept;
196193

197194
// Copy the reason the fill of `table` failed into `buffer`. Return false if
198195
// it did not fail. Implemented in py_driver_fns.cpp.
199-
bool
200-
fn_table_error(FnTable table, char *buffer, std::size_t size) noexcept;
196+
bool fn_table_error(FnTable table, char *buffer, std::size_t size) noexcept;
201197

202198
// Record a call to `name` while it is unavailable. After a failed fill, this
203199
// function attaches the fill's reason to the error the caller raises. The fill
204200
// reported that reason when it failed. A null entry in a filled table is a gate
205201
// bug, which this function reports once per table. Implemented in
206202
// py_driver_fns.cpp.
207-
void
208-
report_unavailable_fn(FnTable table, const char *name) noexcept;
203+
void report_unavailable_fn(FnTable table, const char *name) noexcept;
209204

210205
namespace detail {
211206

‎cuda_core/cuda/core/_cpp/rt/error.hpp‎

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@ namespace cuda_core::rt {
1313
// ============================================================================
1414

1515
// Get and clear the last CUDA error (like cudaGetLastError)
16-
CUresult
17-
get_last_error() noexcept;
16+
CUresult get_last_error() noexcept;
1817

1918
// Get the last CUDA error without clearing it (like cudaPeekAtLastError)
20-
CUresult
21-
peek_last_error() noexcept;
19+
CUresult peek_last_error() noexcept;
2220

2321
// Explicitly clear the last error
24-
void
25-
clear_last_error() noexcept;
22+
void clear_last_error() noexcept;
2623

2724
// Thread-local status of the most recent CUDA API call in this module. Defined
2825
// in error.cpp; every family source writes it.
@@ -43,25 +40,21 @@ extern thread_local CUresult err;
4340
// Report a failed CUDA call. `detail` replaces the default "failed" wording,
4441
// e.g. "skipped (context activation failed; resource leaked)".
4542
// CUDA_ERROR_DEINITIALIZED (driver shutting down) is never reported.
46-
void
47-
report_cuda_error(const char *operation, CUresult status, const char *detail = nullptr) noexcept;
43+
void report_cuda_error(const char *operation, CUresult status, const char *detail = nullptr) noexcept;
4844

4945
// Report a message that is not tied to a CUresult.
5046
// Implemented in py_report.cpp
51-
void
52-
report_message(const char *message) noexcept;
47+
void report_message(const char *message) noexcept;
5348

5449
// Report a failed NVRTC/NVVM/nvJitLink call by raw status code.
55-
void
56-
report_status_code(const char *operation, long code) noexcept;
50+
void report_status_code(const char *operation, long code) noexcept;
5751

5852
// Attach a failed CUDA call to the Python exception currently being handled
5953
// (PEP 678 note, Python 3.11+): for rollback failures inside `except` blocks
6054
// whose original exception is about to be re-raised. When no exception is
6155
// being handled or notes are unavailable, falls back to report_cuda_error().
6256
// Implemented in py_report.cpp
63-
void
64-
attach_rollback_failure(const char *operation, CUresult status, const char *detail = nullptr) noexcept;
57+
void attach_rollback_failure(const char *operation, CUresult status, const char *detail = nullptr) noexcept;
6558

6659
// Detail recorded by a context-scoped helper for the CUresult it is about to
6760
// return, e.g. that the caller's context could not be restored. The Cython
@@ -70,22 +63,18 @@ attach_rollback_failure(const char *operation, CUresult status, const char *deta
7063
// thread) and clears it when `status` is the CUresult it was recorded for, and
7164
// returns nullptr otherwise, so a detail whose status was never raised cannot
7265
// attach to an unrelated error.
73-
const char *
74-
take_last_error_detail(CUresult status) noexcept;
75-
void
76-
clear_last_error_detail() noexcept;
66+
const char *take_last_error_detail(CUresult status) noexcept;
67+
void clear_last_error_detail() noexcept;
7768

7869
// Record why the driver function table is unavailable. The reason becomes the
7970
// detail of the CUDA_ERROR_NOT_INITIALIZED that the trampoline is about to
8071
// return (see driver_api.hpp), so the raised CUDAError explains the failed
8172
// fill and does not suggest a missed cuInit() call. Implemented in error.cpp.
82-
void
83-
note_driver_table_failure(const char *reason) noexcept;
73+
void note_driver_table_failure(const char *reason) noexcept;
8474

8575
// Tests only: make the next context restoration on this thread fail with
8676
// `status`, leaving the target context current as a real failure would.
8777
// Implemented in context.cpp
88-
void
89-
set_context_restore_fault_for_testing(CUresult status) noexcept;
78+
void set_context_restore_fault_for_testing(CUresult status) noexcept;
9079

9180
} // namespace cuda_core::rt

‎cuda_core/cuda/core/_cpp/rt/internal.hpp‎

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@
2121
namespace cuda_core::rt::detail {
2222

2323
// Implemented in error.cpp
24-
void
25-
format_cuda_error(char *buffer, size_t size, const char *operation, CUresult status, const char *detail) noexcept;
24+
void format_cuda_error(char *buffer, size_t size, const char *operation, CUresult status, const char *detail) noexcept;
2625
// Implemented in error.cpp
27-
void
28-
note_context_not_restored(CUcontext previous, CUresult operation_status, CUresult restore_status) noexcept;
26+
void note_context_not_restored(CUcontext previous, CUresult operation_status, CUresult restore_status) noexcept;
2927
// Implemented in error.cpp
30-
void
31-
format_operation(char *buffer, size_t size, const char *operation, unsigned long long handle) noexcept;
28+
void format_operation(char *buffer, size_t size, const char *operation, unsigned long long handle) noexcept;
3229

3330
// Bits of a resource handle for diagnostics: a pointer as its address, an
3431
// integer handle (CUdeviceptr, CUtexObject, ...) as its value, and a pointer
@@ -63,18 +60,15 @@ struct DeallocationStream {
6360
};
6461

6562
// Implemented in stream.cpp
66-
ContextHandle
67-
deallocation_context(const DeallocationStream &stream) noexcept;
63+
ContextHandle deallocation_context(const DeallocationStream &stream) noexcept;
6864
// Implemented in stream.cpp
69-
bool
70-
make_deallocation_stream(const StreamHandle &h, DeallocationStream &out) noexcept;
65+
bool make_deallocation_stream(const StreamHandle &h, DeallocationStream &out) noexcept;
7166

7267
// Implemented in virtual_memory.cpp. Synchronize the stream a VMM buffer
7368
// recorded before its mappings are released. Skips the sync, with a report
7469
// when a capture is the reason, if no stream was recorded, the interpreter is
7570
// finalizing, or the sync would disturb a graph capture (VMM_DESIGN.md).
76-
void
77-
vmm_sync_before_release(const DeallocationStream &stream) noexcept;
71+
void vmm_sync_before_release(const DeallocationStream &stream) noexcept;
7872

7973
// Decorate a status-returning cleanup call to report whenever it fails. CUDA
8074
// calls (CUresult) are reported with the error name and description; NVRTC,
@@ -168,11 +162,9 @@ struct DeferredCleanupItem {
168162
};
169163

170164
// Implemented in py_deferred_cleanup.cpp
171-
void
172-
ensure_deferred_cleanup_ready();
165+
void ensure_deferred_cleanup_ready();
173166
// Implemented in py_deferred_cleanup.cpp
174-
void
175-
enqueue_cleanup(void *item) noexcept;
167+
void enqueue_cleanup(void *item) noexcept;
176168

177169
// ============================================================================
178170
// Handle reverse-lookup registry

‎cuda_core/cuda/core/_cpp/rt/py.hpp‎

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
namespace cuda_core::rt {
1313

1414
#if PY_VERSION_HEX < 0x030D0000
15-
extern "C" int
16-
_Py_IsFinalizing(void);
15+
extern "C" int _Py_IsFinalizing(void);
1716
#endif
1817

1918
// Best-effort probe for interpreter shutdown.
@@ -63,8 +62,7 @@ class GILReleaseGuard {
6362
}
6463

6564
GILReleaseGuard(const GILReleaseGuard &) = delete;
66-
GILReleaseGuard &
67-
operator=(const GILReleaseGuard &) = delete;
65+
GILReleaseGuard &operator=(const GILReleaseGuard &) = delete;
6866

6967
private:
7068
PyThreadState *tstate_ = nullptr;
@@ -99,8 +97,7 @@ class GILAcquireGuard {
9997

10098
// Non-copyable, non-movable
10199
GILAcquireGuard(const GILAcquireGuard &) = delete;
102-
GILAcquireGuard &
103-
operator=(const GILAcquireGuard &) = delete;
100+
GILAcquireGuard &operator=(const GILAcquireGuard &) = delete;
104101

105102
private:
106103
PyGILState_STATE gstate_;
@@ -136,8 +133,7 @@ class PendingExceptionGuard {
136133
}
137134

138135
PendingExceptionGuard(const PendingExceptionGuard &) = delete;
139-
PendingExceptionGuard &
140-
operator=(const PendingExceptionGuard &) = delete;
136+
PendingExceptionGuard &operator=(const PendingExceptionGuard &) = delete;
141137

142138
private:
143139
#if PY_VERSION_HEX >= 0x030C0000
@@ -332,23 +328,20 @@ as_py(const VaMappingHandle &h) noexcept
332328

333329
// Register the Python warning category used by report_* (cuda.core.CUDAWarning).
334330
// Implemented in py_report.cpp
335-
void
336-
register_warning_category(PyObject *category) noexcept;
331+
void register_warning_category(PyObject *category) noexcept;
337332

338333
// Create a non-owning stream handle that prevents a Python owner from being GC'd.
339334
// The owner's refcount is incremented; decremented when handle is released.
340335
// The owner is responsible for keeping the stream's context alive.
341336
// Implemented in stream.cpp
342-
StreamHandle
343-
create_stream_handle_with_owner(CUstream stream, PyObject *owner);
337+
StreamHandle create_stream_handle_with_owner(CUstream stream, PyObject *owner);
344338

345339
// Create a non-owning device pointer handle that prevents a Python owner from being GC'd.
346340
// The owner's refcount is incremented; decremented when handle is released.
347341
// The pointer will NOT be freed when the handle is released.
348342
// If owner is nullptr, equivalent to deviceptr_create_ref.
349343
// Implemented in memory.cpp
350-
DevicePtrHandle
351-
deviceptr_create_with_owner(CUdeviceptr ptr, PyObject *owner);
344+
DevicePtrHandle deviceptr_create_with_owner(CUdeviceptr ptr, PyObject *owner);
352345

353346
// Callback type for MemoryResource deallocation.
354347
// Called from the shared_ptr deleter when a handle created via
@@ -359,21 +352,18 @@ using MRDeallocCallback = void (*)(PyObject *mr, CUdeviceptr ptr, size_t size, c
359352

360353
// Register the MR deallocation callback.
361354
// Implemented in memory.cpp
362-
void
363-
register_mr_dealloc_callback(MRDeallocCallback cb);
355+
void register_mr_dealloc_callback(MRDeallocCallback cb);
364356

365357
// Create a device pointer handle whose destructor calls mr.deallocate()
366358
// via the registered callback. The mr's refcount is incremented and
367359
// decremented when the handle is released.
368360
// If mr is nullptr, equivalent to deviceptr_create_ref.
369361
// Implemented in memory.cpp
370-
DevicePtrHandle
371-
deviceptr_create_with_mr(CUdeviceptr ptr, size_t size, PyObject *mr);
362+
DevicePtrHandle deviceptr_create_with_mr(CUdeviceptr ptr, size_t size, PyObject *mr);
372363

373364
// Build an OpaqueHandle from a Python object: increments its refcount now and
374365
// decrements it (under the GIL) on release. The caller must hold the GIL.
375366
// Implemented in graph.cpp
376-
OpaqueHandle
377-
make_opaque_py(PyObject *obj);
367+
OpaqueHandle make_opaque_py(PyObject *obj);
378368

379369
} // namespace cuda_core::rt

0 commit comments

Comments
 (0)