exMatrix.cpp
Add two device matrices. Create two GPU-resident matrices, add them, and verify the result after the language-appropriate completion boundary.
ExSDK source-ownedC++Core
Source
Core · Vulkan compute
Example
1#include <oa/oa.h>23OA_MAIN("ExampleCoreMatrix") {4 auto one = oa::FnMatrix::ones({2, 3});56 auto two = oa::FnMatrix::full({2, 3}, 2.0F);78 auto sum = oa::FnMatrix::add(one, two);910 oa::Array<oa::F32, 6> values{};11 if (not oa::FnMatrix::copyToHost(sum, values.data(), sizeof(values)).isOk()) {12 return 1;13 }14 for (const oa::F32 value : values) {15 if (oa::abs(value - 3.0F) > 1e-06F) {16 return 1;17 }18 }1920 if (not oa::print("Matrix addition verified: every value is 3").isOk()) {21 return 1;22 }23 return 0;24}25
Output
Verified Python run. Runtime evidence from the source-owned Python example on an Intel Iris Xe Vulkan device. The batch loader creates only the two shader pipelines required by this graph.
Exmatrix.py · output
$ .venv/bin/python sdk/py/examples/core/matrix.py10:47:17.554 [INFO ] [RT ] ComputeDevice (0): Intel(R) Iris(R) Xe Graphics (TGL GT2), vulkan 1.4.354, 11 GB10:47:17.563 [INFO ] [RT ] bindless heap: buffers=262143 imageSlots=16383 samplerSlots=2047, UPDATE_AFTER_BIND10:47:17.577 [INFO ] [COMP] pipeline cache: loaded 10860399 bytes from $OA_ROOT/var/vk/pipeline.vcache10:47:17.589 [INFO ] [COMP] Loading 2 shader pipelines on demand (1 thread, warm cache)10:47:17.590 [INFO ] [COMP] Loaded 2/2 shader pipelines on demand (failed=0, threads=1, 0.96 ms)Matrix addition verified: every value is 3