Skip to content

Commit 779f60b

Browse files
committed
revise code guidelines
1 parent 4cd8382 commit 779f60b

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

README.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -270,36 +270,42 @@ Join our community in the `#gpu-cpp` channel on the [AnswerDotAI Discord with th
270270
271271
Feedback, issues and pull requests are welcome.
272272
273-
## Style and Design Guidelines
273+
## Code Guidelines for Contributors
274274
275275
For contributors, here are general rules of thumb regarding the design and
276276
style of the gpu.cpp library:
277277
278-
Aesthetics - Maximize Leverage and Account for Various Sources of Friction:
278+
Aesthetics - Maximize Leverage and Account for Sources of Friction:
279279
280280
- In addition to performance, time-to-grok the codebase, compilation time,
281281
number of failure modes for builds are things worth optimizing for.
282282
- Increase the implementation surface area only when there's a clear goal
283283
behind doing so. This maximizes leverage per unit effort, increases
284284
optionality in how the library can be used, and keeps compile times low.
285+
- Taking inspiration from the time-tested horizontal extensibility
286+
of neural network libraries like PyTorch, to a first approximation the library
287+
architecture could be described as a bag of composable functions.
288+
- Design choices general attempt to blend the composability of functional
289+
programming with the performance awareness of data oriented design.
285290
286291
Overloads and Templates:
287292
288-
- Particularly for core implementation code, prefer value types over templates
289-
where possible. It's generally easy to add a more typesafe templated wrapper
290-
around a value type core implementation. Whereas reversing a core
291-
implementation that's templated often leads to a more significant refactor.
292-
- For comptime polymorphism prefer trivial function overloads over templates.
293-
Besides compile time benefits, this makes it trivial to reason about which
294-
version of a function is being called.
293+
- Prefer value-level types over type-level templates, especially for core
294+
implementation code. It's easy to add a more typesafe templated wrapper
295+
around a value type core implementation. Whereas moving templated core
296+
implementations from comptime to runtime leads to a more significant
297+
refactor.
298+
- For comptime polymorphism, prefer trivial function overloads over templates.
299+
Besides compile time benefits, this reasoning about which version of a
300+
function is being called becomes explicit and scanable in the codebase.
295301
296302
Avoid Encapsulation and Methods:
297303
298304
- To build systems effectively, we need to construct them out of subsystems for
299-
which the behavior is known and thereby composable and predictable.
300-
- Prefer transparency over encapsulation. Don't use abstract classes as
301-
interface specifications, the library and its function signatures is the
302-
interface.
305+
which the behavior is known and thereby composable and predictable.
306+
Therefore, we prefer transparency and avoid encapsulation. Don't use abstract
307+
classes as interface specifications, the library and its function signatures
308+
is the interface.
303309
- Use struct as a default over class unless there's a clear reason otherwise.
304310
- Instead of methods, pass the "owning object" object as a reference to a
305311
function. In general this convention can perform any operation that a method

0 commit comments

Comments
 (0)