CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
4.8 KiB
4.8 KiB
rocjitsu Code Style Guide
Conventions for writing C++ in the rocjitsu codebase. Prefer clarity and
consistency over cleverness.
Types (struct vs class)
- Use a
structonly for plain-old-data (POD) types where every member is public. - Use a
classwhenever you need constructors/destructors or any other non-POD behavior. - Within a
class, use a singlepublic:,protected:, andprivate:section (only the ones you need), and always in that order.
// POD: all members public, no behavior -> struct
struct Point {
int x;
int y;
};
// Has behavior (ctor/dtor/methods) -> class, sections in order
class Buffer {
public:
Buffer();
~Buffer();
void resize(std::size_t new_size);
protected:
// Available to derived buffer types.
void reallocate(std::size_t new_capacity);
private:
std::size_t current_size_;
};
Naming
- Prefix global constants with
k(e.g.kMaxThreads). - Use CamelCase for data types and snake_case for methods and members.
- Suffix non-public data members (private and protected) with a trailing
underscore (e.g.
current_size_); public members (such as PODstructfields) take no suffix. - Use clear, descriptive names. No single-letter variables.
constexpr int kMaxThreads = 64;
class ThreadPool { // CamelCase type
public:
void submit_task(); // snake_case method
private:
int active_thread_count_; // snake_case member, trailing _
};
Documentation & Comments
- Write long, verbose descriptions for variables and functions.
- Prefer clarity over conciseness.
- When documenting public APIs, use Doxygen
@brief/@details. - Comment the why, not the what. Skip comments that just restate the code.
- Avoid decorative comment lines (e.g.
// ----,// ====).
Headers
- Use
#pragma oncefor include guards.
#pragma once
// ... header contents ...
Namespaces
- Use one namespace per module/library, named after that library (matching its
lib/<name>/directory). For example,rocjitsu,simdojo, andutileach live in their own top-level namespace. - Do not scatter code across ad-hoc namespaces. Nest a sub-namespace only when
genuinely needed : for example, for arch/ISA specificity (
rocjitsu::amdgpu).
// Each library gets its own top-level namespace, named after its lib/<name>/ dir:
// lib/rocjitsu/ -> namespace rocjitsu
// lib/simdojo/ -> namespace simdojo
// lib/util/ -> namespace util
namespace simdojo {
// simdojo module code lives here
} // namespace simdojo
// Nest a sub-namespace only when justified, e.g. arch/ISA specificity:
namespace rocjitsu::amdgpu {
// gfx-specific code lives here
} // namespace rocjitsu::amdgpu
Language, STL & Preprocessor
- Always target C++20 and use the STL; prefer modern features such as concepts,
ranges, and
std::format. - Use
typenameinstead ofclasswhen declaring template type parameters. This makes occurrences of theclasskeyword easier to find when searching the codebase. - If you need performance and the STL is a poor fit, build custom data structures
in
util. - Never use
#define, C conventions, or macros unless absolutely necessary. - When you must use C standard library headers, prefer the
<c*>variants.
#include <cstdint> // not <stdint.h>
#include <cstdio> // not <stdio.h>
template <typename ValueType> // not template <class ValueType>
class Container {};
- Use
autoonly when the type is obvious from the immediate context (e.g. the RHS spells out the type, such as a constructor call or a cast). Do not useautowhen the type can't be determined by looking at the line itself.
auto x = foo(); // BAD, type not obvious
auto x = std::make_unique<Foo>(); // OK, can tell from the RHS
Foo foo = static_cast<Foo>(bar); // OK but could use auto instead to avoid repetitiveness
Logging
- Never use
fprintf,printf, orstd::cerr. UseLoggerfromutil/log.h(Logger::print<>()), which supports compile-time group filters for building with or without tracing.
Error Handling
- Exceptions are only for unrecoverable errors: initialization/configuration
failures (
ConfigError) and invalid or unimplemented instructions during code-object parsing (InvalidInst,UnimplementedInst). All exception types live inutil/except.h. - Do not throw in simulation hot paths (event handlers, instruction execution, cache lookups).
- Do not add
try/catchexcept at a boundary that must translate an error (e.g. the C API layer). Assume code is not exception-safe unless documented.
Formatting
- The repo uses pre-commit hooks : clang-format (C++), black (Python), and
gersemi (CMake). The config lives at the repo root
(
rocm-systems/.pre-commit-config.yaml). Install once, then run before every commit:
pip install pre-commit
pre-commit install
pre-commit run --all-files