-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforge_accel_model_example.cpp
More file actions
49 lines (45 loc) · 1.33 KB
/
Copy pathforge_accel_model_example.cpp
File metadata and controls
49 lines (45 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <forge/accel.hpp>
#include <execution>
#include <cstddef>
#include <iostream>
#include <span>
#include <tuple>
#include <vector>
int main() {
forge::accel::mock::context ctx;
forge::accel::mock::model model{forge::accel::mock::model_descriptor{
.inputs = {
forge::accel::model_io_descriptor{
.byte_size = 4,
.rank = 1,
.extents = {4, 0, 0, 0},
},
},
.outputs = {
forge::accel::model_io_descriptor{
.byte_size = 4,
.rank = 1,
.extents = {4, 0, 0, 0},
},
},
}};
auto session = model.open_session(ctx.get_device());
forge::accel::mock::model_bindings bindings{model};
std::vector<std::byte> input{
std::byte{1},
std::byte{2},
std::byte{3},
std::byte{4},
};
std::vector<std::byte> output(4);
bindings.bind_input(0, std::span<const std::byte>{input});
bindings.bind_output(0, std::span<std::byte>{output});
auto result = std::execution::sync_wait(
forge::accel::mock::execute(session, std::move(bindings)));
if (!result) {
return 1;
}
std::cout << "mock model output[0]="
<< std::to_integer<int>(output[0]) << "\n";
return output[0] == std::byte{10} ? 0 : 1;
}