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