MCPcopy Create free account
hub / github.com/KomputeProject/kompute / TEST

Function TEST

test/TestAsyncOperations.cpp:11–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#include "shaders/Utils.hpp"
10
11TEST(TestAsyncOperations, TestManagerParallelExecution)
12{
13 // This test is built for NVIDIA 1650. It assumes:
14 // * Queue family 0 and 2 have compute capabilities
15 // * GPU is able to process parallel shader code across different families
16 uint32_t size = 10;
17
18 uint32_t numParallel = 2;
19
20 std::string shader(R"(
21 #version 450
22
23 layout (local_size_x = 1) in;
24
25 layout(set = 0, binding = 0) buffer b { float pb[]; };
26
27 shared uint sharedTotal[1];
28
29 void main() {
30 uint index = gl_GlobalInvocationID.x;
31
32 sharedTotal[0] = 0;
33
34 for (int i = 0; i < 100000000; i++)
35 {
36 atomicAdd(sharedTotal[0], 1);
37 }
38
39 pb[index] = sharedTotal[0];
40 }
41 )");
42
43 std::vector<uint32_t> spirv = compileSource(shader);
44
45 std::vector<float> data(size, 0.0);
46 std::vector<float> resultSync(size, 100000000);
47 std::vector<float> resultAsync(size, 100000000);
48
49 kp::Manager mgr;
50
51 std::shared_ptr<kp::Sequence> sq = mgr.sequence();
52
53 std::vector<std::shared_ptr<kp::Tensor>> inputsSyncB;
54 std::vector<std::shared_ptr<kp::Algorithm>> algorithms;
55
56 for (uint32_t i = 0; i < numParallel; i++) {
57 inputsSyncB.push_back(mgr.tensor(data));
58 algorithms.push_back(mgr.algorithm({ inputsSyncB[i] }, spirv));
59 }
60
61 sq->eval<kp::OpTensorSyncDevice>(inputsSyncB);
62
63 mgr.sequence()->eval<kp::OpTensorSyncDevice>(inputsSyncB);
64
65 auto startSync = std::chrono::high_resolution_clock::now();
66
67 for (uint32_t i = 0; i < numParallel; i++) {
68 sq->eval<kp::OpAlgoDispatch>(algorithms[i]);

Callers

nothing calls this directly

Calls 6

sequenceMethod · 0.80
tensorMethod · 0.80
algorithmMethod · 0.80
evalAwaitMethod · 0.80
compileSourceFunction · 0.50
vectorMethod · 0.45

Tested by

no test coverage detected