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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#ifndef _HW_SCHED_H
#define _HW_SCHED_H
typedef struct HWSchedT *HWSched;
#include "dict_hw.h"
#include "hw_thread.h"
enum HWSchedModeT {
HW_SCHED_MODE_PREALLOCATED = 0,
HW_SCHED_MODE_SEQUENTIAL
};
typedef enum HWSchedModeT HWSchedMode;
#define HW_SINGLE_MODE
//#define HW_DETECT_CPU_CORES
#define HW_MAX_THREADS DICT_HW_MAX_DEVICES
//#define HW_MAX_THREADS 128
#ifdef HW_SINGLE_MODE
typedef HWRunFunction HWEntry;
#else /* HW_SINGLE_MODE */
typedef int HWEntry;
#endif /* HW_SINGLE_MODE */
#ifndef HW_HIDE_DETAILS
#include <glib.h>
struct HWSchedT {
int status;
int started;
int n_threads, n_threads_actual;
HWThread thread[HW_MAX_THREADS];
GCond *job_cond, *compl_cond;
GMutex *job_cond_mutex, *compl_cond_mutex, *data_mutex;
HWSchedMode mode;
int *n_blocks;
int *cur_block;
HWEntry entry;
void *ctx;
};
typedef struct HWSchedT HWSchedS;
#endif /* HW_HIDE_DETAILS */
# ifdef __cplusplus
extern "C" {
# endif
HWSched hw_sched_create(int ppu_count);
void hw_sched_destroy(HWSched ctx);
int hw_sched_limit_num_threads(HWSched ctx, int count);
int hw_sched_set_sequential_mode(HWSched ctx, int *n_blocks, int *cur_block);
int hw_sched_get_chunk(HWSched ctx, int thread_id);
int hw_sched_schedule_task(HWSched ctx, void *appctx, HWEntry entry);
int hw_sched_wait_task(HWSched ctx);
#define hw_sched_lock(ctx, type) g_mutex_lock(ctx->type##_mutex)
#define hw_sched_unlock(ctx, type) g_mutex_unlock(ctx->type##_mutex)
#define hw_sched_broadcast(ctx, type) g_cond_broadcast(ctx->type##_cond)
#define hw_sched_signal(ctx, type) g_cond_signal(ctx->type##_cond)
#define hw_sched_wait(ctx, type) g_cond_wait(ctx->type##_cond, ctx->type##_cond_mutex)
# ifdef __cplusplus
}
# endif
#endif /* _HW_SCHED_H */
|