-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforge_accel_callback_example.cpp
More file actions
37 lines (32 loc) · 1.25 KB
/
Copy pathforge_accel_callback_example.cpp
File metadata and controls
37 lines (32 loc) · 1.25 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
#include <forge/accel.hpp>
#include <execution>
#include "example_support.hpp"
#include <vector>
int main() {
forge::accel::mock::context ctx{forge::accel::mock::context_options{
.thread_count = 2,
}};
forge::accel::mock::host_callback_dispatcher_options callback_options;
callback_options.completion_capacity = 4;
forge::accel::mock::host_callback_dispatcher callbacks{callback_options};
auto q = ctx.get_queue(forge::accel::queue_kind::compute);
std::vector<int> order;
auto callback = callbacks.register_callback([&] {
order.push_back(2);
});
std::execution::sync_wait(forge::accel::mock::submit(q, [&] {
order.push_back(1);
}));
std::execution::sync_wait(
forge::accel::mock::enqueue_callback(q, callbacks, callback));
std::execution::sync_wait(forge::accel::mock::submit(q, [&] {
order.push_back(3);
}));
forge_example::require((order == std::vector<int>{1, 2, 3}));
auto completions = callbacks.completions();
forge_example::require(completions.size() == 1);
forge_example::require(completions[0].callback == callback);
forge_example::require(completions[0].status == forge::accel::callback_status::ok);
callbacks.shutdown();
callbacks.wait();
}