Research Article

Multi-GPU Support on Single Node Using Directive-Based Programming Model

Algorithm 8

typedef struct _task_s
{
int type; //task type (e.g. memory allocation and kernel launch, etc.)
void  (routine)(void); // the task routine
_work_args args; // point to the task argument
int work_done; // indicate whether the task is done
int async; // whether the task is asynchronous
struct _task_s next; // next task in the task queue
}  _task;
typedef struct
{
int destroyed; // whether this thread is destroyed
int queue_size; // the task queue size
pthread_t thread; // the thread identity
context_t context; // the GPU context associated with this thread
int context_id; // the GPU context id
_task queue_head; // head of the FIFO task queue
_task queue_tail; // tail of the FIFO task queue
pthread_mutex_t queue_lock;
pthread_cond_t queue_ready; // the task queue is not empty and ready
pthread_cond_t work_done;
pthread_cond_t queue_empty;
}  _gpu_thread;