MCPcopy Create free account
hub / github.com/AnswerDotAI/gpu.cpp / testResidual

Function testResidual

experimental/legacy/transformer/test_kernels.cpp:15–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13using namespace gpu;
14
15void testResidual(Context &ctx) {
16 constexpr size_t N = 200000;
17 constexpr size_t workgroupSize = 256;
18 std::array<float, N> input1Arr;
19 std::array<float, N> input2Arr;
20 range(input1Arr);
21 range(input2Arr);
22 std::array<float, N> outputArr;
23 Tensor input1 = createTensor(ctx, {N}, kf32, input1Arr.data());
24 Tensor input2 = createTensor(ctx, {N}, kf32, input2Arr.data());
25 Tensor output = createTensor(ctx, {N}, kf32, outputArr.data());
26 std::promise<void> promise;
27 std::future<void> future = promise.get_future();
28 KernelCode shaderCode = {kShaderResidual, workgroupSize, kf32};
29 LOG(kDefLog, kInfo, "Shader Code :\n%s", shaderCode.data.c_str());
30 Kernel op =
31 createKernel(ctx, {kShaderResidual, workgroupSize, kf32},
32 Bindings{input1, input2, output}, {cdiv(N, workgroupSize), 1, 1});
33 dispatchKernel(ctx, op, promise);
34 wait(ctx, future);
35 toCPU(ctx, output, outputArr.data(), sizeof(outputArr));
36 LOG(kDefLog, kInfo, "%s",
37 show<float, N, 1>(outputArr, "Residual Output").c_str());
38 std::array<float, N> outputRef;
39 ref::residual_forward_cpu(outputRef.data(), input1Arr.data(),
40 input2Arr.data(), N);
41 LOG(kDefLog, kInfo, "%s",
42 show<float, N, 1>(outputRef, "Residual Reference Output").c_str());
43 assert(isclose(outputArr.data(), outputRef.data(), N));
44 LOG(kDefLog, kInfo, "Done with Residual Test");
45}
46
47void testHadamard(Context &ctx) {
48 constexpr size_t N = 200000;

Callers 1

mainFunction · 0.85

Calls 9

rangeFunction · 0.85
createTensorFunction · 0.85
LOGFunction · 0.85
createKernelFunction · 0.85
cdivFunction · 0.85
dispatchKernelFunction · 0.85
waitFunction · 0.85
toCPUFunction · 0.85
iscloseFunction · 0.85

Tested by

no test coverage detected