Coverage Report

Created: 2021-04-06 03:49

/home/liu/buildslave/linux-x64-runtests/build/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/khash/khash.h"
16
#include <pthread.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
} ccv_nnc_stream_resource_container_t;
26
27
typedef struct {
28
  pthread_mutex_t mutex;
29
  ccv_array_t* empty;
30
} ccv_nnc_signal_container_t;
31
32
struct ccv_nnc_stream_context_s {
33
  int type;
34
  // For resource container
35
  ccv_nnc_stream_resource_container_t* _inline_container[1];
36
  ccv_nnc_stream_resource_container_t** resource_container;
37
  // For scheduler
38
  co_routine_t* main; // main task.
39
  co_scheduler_t* scheduler;
40
  // For neighbor discovery
41
  ccv_nnc_stream_context_neighbor_discovery_f neighbor_discovery;
42
  void* neighbor_discovery_context;
43
  ccv_nnc_signal_container_t* container;
44
  // For hooks
45
  ccv_array_t* destructor_hooks;
46
  int reuse_destructor_hook;
47
};
48
49
typedef struct {
50
  ccv_nnc_signal_container_t* container;
51
  ccv_nnc_stream_signal_t* signal;
52
} ccv_nnc_signal_handler_t;
53
KHASH_MAP_INIT_INT64(signal_container, ccv_nnc_signal_container_t*)
54
// Return the scheduler from a stream (if not created, create one).
55
CCV_WARN_UNUSED(co_scheduler_t*) ccv_nnc_stream_context_get_scheduler(ccv_nnc_stream_context_t* const stream_context);
56
57
26
#define co_stream_await(_stream) do 
{ if (14
!_co_stream_await(_self_, 14
_stream12
))
{ return (co_state_t){ __LINE__, 0 }; }7
case __LINE__: ; }14
while (
014
)
58
int _co_stream_await(co_routine_t* const self, ccv_nnc_stream_context_t* const stream);
59
60
ccv_nnc_stream_signal_t* ccv_nnc_stream_context_emit_signal_new(ccv_nnc_stream_context_t* const stream);
61
62
typedef struct {
63
  ccv_nnc_callback_f fn;
64
  void* callback_context;
65
} ccv_nnc_async_callback_t;
66
67
typedef void(*ccv_nnc_async_callback_f)(ccv_nnc_async_callback_t* const async);
68
69
typedef struct {
70
  ccv_nnc_stream_context_t* stream;
71
  ccv_nnc_stream_signal_t* synced;
72
} ccv_nnc_synced_stream_t;
73
74
KHASH_MAP_INIT_INT(synced_stream, ccv_nnc_synced_stream_t);
75
76
#endif