OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomese-simd commits / cdb394f

Expand design notes
cdb394fc9fd9ff0bd942d994777ece765c2b2da8
by Linas Vepštas <linasvepstas@gmail.com> · 2025-09-12T15:45:51.000Z

Changed files (1) +55 -0

Design-E.md +55 -0
……@@ -45,4 +45,59 @@ implementing a library for the core AtomSpace arithmetic functions is
4545a reasonable next step: so, having `PlusLink` and `TimesLink run on the
4646GPU.
4747
48Rewriting
49---------
50Consider the task of mapping the Atomese `PlusLink` so that, when
51invoked/executed in the right way, it runs on the GPU. There are several
52ways to implement this. The knee-jerk, brute-force but stupid way is to
53write a bunch of C++ code that intercepts the attempt to execute
54`PlusLink`, dependent on the context, and re-route it to the GPU.
55Of course this can be made to work; its brute-forcing the solution.
56
57The other way is to treat it as a re-write. That is, create a `RuleLink`
58that accepts (recognizes) `(Plus a b)` and turns it into
59```
60 (Section (Item "vec_add")
61 (FloatValue rslt) (FloatValue a) (FloatValue b))
4862----
63Well, not that literally, because we'd have to wire `rslt` into
64something; its more complicated. Also `Plus` is unbounded, so it would
65need to be some arithmetic fold. But you get the idea...
66
67So this becomes a graph-rewrite problem: Accept as input functional
68expressions involving `PlusLink` etc and rewrite thehm into Opencl
69Atomese. Once rewritten, they can be executed.
70
71Perhaps easier to map are `LambdaLink` because they have explicit
72`VariableList` declarations, with each being a `TypedVariable`, and so
73this maps more smoothly and easily to the OpenCL C/C++ style interfaces.
74
75GenIDL
76------
77The above thoughts also suggest that the implementation of GenIDL is
78wrong. The original vision (described in [Design-C](./Design-C.md)) was
79to convert OpenCL function prototype declarations like
80```
81 kernel void vec_mult(global double *prod,
82 global const double *a,
83 global const double *b,
84 const unsigned long sz)
85```
86into Atomese
87```
88 (Section
89 (ItemNode "vec_mult")
90 (ConnectorSeq
91 (Connector (Type 'FloatValue) (Sex "output"))
92 (Connector (Type 'FloatValue) (Sex "input"))
93 (Connector (Type 'FloatValue) (Sex "input"))
94 (Connector (Type 'FloatValue) (Sex "size"))))
95```
96And that's what it does. However, it might be better to convert the
97OpenCL declaration into Atomese that is much much more faithful to
98it's original form, and then rewrite *that* (using `RuleLink`) into
99the atomese-simd interfaces.
100
101Malleability
102------------
103What's the point of doing this? Its to