@@ -270,36 +270,42 @@ Join our community in the `#gpu-cpp` channel on the [AnswerDotAI Discord with th
270
270
271
271
Feedback, issues and pull requests are welcome.
272
272
273
- ## Style and Design Guidelines
273
+ ## Code Guidelines for Contributors
274
274
275
275
For contributors, here are general rules of thumb regarding the design and
276
276
style of the gpu.cpp library:
277
277
278
- Aesthetics - Maximize Leverage and Account for Various Sources of Friction:
278
+ Aesthetics - Maximize Leverage and Account for Sources of Friction:
279
279
280
280
- In addition to performance, time-to-grok the codebase, compilation time,
281
281
number of failure modes for builds are things worth optimizing for.
282
282
- Increase the implementation surface area only when there's a clear goal
283
283
behind doing so. This maximizes leverage per unit effort, increases
284
284
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.
285
290
286
291
Overloads and Templates:
287
292
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.
295
301
296
302
Avoid Encapsulation and Methods:
297
303
298
304
- 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.
303
309
- Use struct as a default over class unless there's a clear reason otherwise.
304
310
- Instead of methods, pass the "owning object" object as a reference to a
305
311
function. In general this convention can perform any operation that a method
0 commit comments