/home/liu/actions-runner/_work/ccv/ccv/lib/nnc/_ccv_nnc_stream.h
Line | Count | Source |
1 | | /********************************************************** |
2 | | * C-based/Cached/Core Computer Vision Library |
3 | | * Liu Liu, 2010-02-01 |
4 | | **********************************************************/ |
5 | | |
6 | | /********************************************************** |
7 | | * CCV - Neural Network Collection |
8 | | **********************************************************/ |
9 | | |
10 | | #ifndef GUARD_ccv_nnc_stream_internal_h |
11 | | #define GUARD_ccv_nnc_stream_internal_h |
12 | | |
13 | | #include "ccv_nnc.h" |
14 | | #include "co.h" |
15 | | #include "3rdparty/sfmt/SFMT.h" |
16 | | #include "3rdparty/khash/khash.h" |
17 | | |
18 | | struct ccv_nnc_stream_signal_s { |
19 | | int type; |
20 | | ccv_nnc_stream_context_t* emit_context; |
21 | | }; |
22 | | |
23 | | typedef struct { |
24 | | // Empty, this will hold things such as NCCL communicator in subclass. |
25 | | // Putting dummy because C / C++ treats empty struct differently. |
26 | | int dummy; |
27 | | } ccv_nnc_stream_resource_container_t; |
28 | | |
29 | | struct ccv_nnc_stream_context_s { |
30 | | int type; |
31 | | // For resource container |
32 | | ccv_nnc_stream_resource_container_t* _inline_container[1]; |
33 | | ccv_nnc_stream_resource_container_t** resource_container; |
34 | | // For scheduler |
35 | | co_routine_t* main; // main task. |
36 | | co_scheduler_t* scheduler; |
37 | | // For neighbor discovery |
38 | | ccv_nnc_stream_context_neighbor_discovery_f neighbor_discovery; |
39 | | void* neighbor_discovery_context; |
40 | | // For hooks |
41 | | ccv_array_t* destructor_hooks; |
42 | | int reuse_destructor_hook; |
43 | | ccv_nnc_stream_signal_t* event; |
44 | | // For random number generator. |
45 | | sfmt_t* sfmt; |
46 | | }; |
47 | | |
48 | | // Return the scheduler from a stream (if not created, create one). |
49 | | CCV_WARN_UNUSED(co_scheduler_t*) ccv_nnc_stream_context_get_scheduler(ccv_nnc_stream_context_t* const stream_context); |
50 | | |
51 | 26 | #define co_stream_await(_stream) do { if (14 !_co_stream_await(_self_, 14 _stream24 )) { return (co_state_t){ __LINE__, 0 }; }7 case __LINE__: ; }14 while (014 ) |
52 | | int _co_stream_await(co_routine_t* const self, ccv_nnc_stream_context_t* const stream); |
53 | | |
54 | | typedef struct { |
55 | | ccv_nnc_callback_f fn; |
56 | | void* callback_context; |
57 | | } ccv_nnc_async_callback_t; |
58 | | |
59 | | typedef void(*ccv_nnc_async_callback_f)(ccv_nnc_async_callback_t* const async); |
60 | | |
61 | | KHASH_MAP_INIT_INT(stream_map, ccv_nnc_stream_context_t*); |
62 | | |
63 | | #endif |