fixed global obejct sharing between cores
This commit is contained in:
@@ -6,35 +6,61 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define NUM_CORES_MAX 8
|
||||
|
||||
typedef struct {
|
||||
func_t function;
|
||||
void * arguments;
|
||||
int nthreads;
|
||||
} spawn_t;
|
||||
|
||||
spawn_t* g_spawn = NULL;
|
||||
spawn_t* g_spawn[NUM_CORES_MAX];
|
||||
|
||||
void spawn_warp_runonce() {
|
||||
void spawn_warp_all() {
|
||||
// active all threads
|
||||
vx_tmc(g_spawn->nthreads);
|
||||
int num_threads = vx_num_threads();
|
||||
vx_tmc(num_threads);
|
||||
|
||||
int core_id = vx_core_id();
|
||||
spawn_t* p_spawn = g_spawn[core_id];
|
||||
|
||||
// call user routine
|
||||
g_spawn->function(g_spawn->arguments);
|
||||
p_spawn->function(p_spawn->arguments);
|
||||
|
||||
// resume single-thread execution on exit
|
||||
// resume single-warp execution on exit
|
||||
int wid = vx_warp_id();
|
||||
unsigned tmask = (0 == wid) ? 0x1 : 0x0;
|
||||
vx_tmc(tmask);
|
||||
}
|
||||
|
||||
void spawn_warp_threads(int num_threads) {
|
||||
// active all threads
|
||||
vx_tmc(num_threads);
|
||||
|
||||
int core_id = vx_core_id();
|
||||
spawn_t* p_spawn = g_spawn[core_id];
|
||||
|
||||
// call user routine
|
||||
p_spawn->function(p_spawn->arguments);
|
||||
|
||||
// resume single-warp execution on exit
|
||||
int wid = vx_warp_id();
|
||||
unsigned tmask = (0 == wid) ? 0x1 : 0x0;
|
||||
vx_tmc(tmask);
|
||||
}
|
||||
|
||||
void vx_spawn_warps(int num_warps, int num_threads, func_t func_ptr , void * args) {
|
||||
spawn_t spawn = { func_ptr, args, num_threads };
|
||||
g_spawn = &spawn;
|
||||
int core_id = vx_core_id();
|
||||
if (core_id >= NUM_CORES_MAX)
|
||||
return;
|
||||
|
||||
spawn_t spawn = { func_ptr, args, num_threads };
|
||||
g_spawn[core_id] = &spawn;
|
||||
|
||||
if (num_warps > 1) {
|
||||
vx_wspawn(num_warps, (unsigned)spawn_warp_runonce);
|
||||
vx_wspawn(num_warps, (unsigned)spawn_warp_all);
|
||||
}
|
||||
spawn_warp_runonce();
|
||||
spawn_warp_threads(num_threads);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user