2022-01-12 00:01:42 +08:00
|
|
|
#ifndef C_STRUCTURES_H
|
|
|
|
#define C_STRUCTURES_H
|
|
|
|
|
2022-06-21 11:03:01 +08:00
|
|
|
#include "blockingconcurrentqueue.h"
|
2022-05-04 20:59:38 +08:00
|
|
|
#include "cuda_runtime.h"
|
2022-01-12 00:01:42 +08:00
|
|
|
#include "pthread.h"
|
2022-05-04 20:59:38 +08:00
|
|
|
|
2022-06-21 11:03:01 +08:00
|
|
|
typedef struct device {
|
2022-01-12 00:01:42 +08:00
|
|
|
int max_compute_units;
|
|
|
|
int device_id;
|
|
|
|
} cu_device;
|
|
|
|
|
2022-06-21 11:03:01 +08:00
|
|
|
typedef struct c_thread {
|
2022-01-12 00:01:42 +08:00
|
|
|
pthread_t thread;
|
|
|
|
unsigned long executed_commands;
|
|
|
|
unsigned index;
|
|
|
|
bool exit;
|
2022-06-21 10:51:12 +08:00
|
|
|
bool busy;
|
2022-06-21 11:57:51 +08:00
|
|
|
int completeTask;
|
2022-01-12 00:01:42 +08:00
|
|
|
} cu_ptd;
|
|
|
|
|
2022-06-21 07:01:28 +08:00
|
|
|
// kernel information
|
2022-06-21 11:03:01 +08:00
|
|
|
typedef struct kernel {
|
2022-06-21 07:01:28 +08:00
|
|
|
|
|
|
|
void *(*start_routine)(void *);
|
|
|
|
|
|
|
|
void **args;
|
|
|
|
|
|
|
|
dim3 gridDim;
|
|
|
|
dim3 blockDim;
|
|
|
|
|
|
|
|
size_t shared_mem;
|
|
|
|
|
|
|
|
cudaStream_t stream;
|
|
|
|
|
|
|
|
struct event *barrier;
|
|
|
|
|
|
|
|
int status;
|
|
|
|
|
|
|
|
int totalBlocks;
|
|
|
|
|
|
|
|
int blockSize;
|
|
|
|
|
|
|
|
int startBlockId;
|
|
|
|
int endBlockId;
|
|
|
|
|
2022-06-21 11:03:01 +08:00
|
|
|
kernel(const kernel &obj)
|
|
|
|
: start_routine(obj.start_routine), args(obj.args),
|
|
|
|
shared_mem(obj.shared_mem), blockSize(obj.blockSize),
|
|
|
|
gridDim(obj.gridDim), blockDim(obj.blockDim),
|
|
|
|
totalBlocks(obj.totalBlocks) {}
|
2022-06-21 07:01:28 +08:00
|
|
|
} cu_kernel;
|
|
|
|
|
|
|
|
using kernel_queue = moodycamel::BlockingConcurrentQueue<kernel *>;
|
|
|
|
|
2022-06-21 11:03:01 +08:00
|
|
|
typedef struct scheduler_pool {
|
2022-01-12 00:01:42 +08:00
|
|
|
|
|
|
|
struct c_thread *thread_pool;
|
|
|
|
|
|
|
|
size_t num_worker_threads;
|
|
|
|
size_t local_mem_size;
|
|
|
|
int num_kernel_launch;
|
|
|
|
int num_kernel_finished;
|
|
|
|
int num_kernel_queued;
|
|
|
|
size_t idle_threads;
|
|
|
|
|
|
|
|
pthread_cond_t wake_pool;
|
2022-05-04 20:59:38 +08:00
|
|
|
pthread_cond_t wake_host;
|
2022-01-12 00:01:42 +08:00
|
|
|
|
|
|
|
int threadpool_shutdown_requested;
|
|
|
|
|
|
|
|
// lock for scheduler
|
|
|
|
pthread_mutex_t work_queue_lock;
|
|
|
|
|
2022-06-21 07:01:28 +08:00
|
|
|
kernel_queue *kernelQueue;
|
2022-01-12 00:01:42 +08:00
|
|
|
|
|
|
|
} cu_pool;
|
|
|
|
|
2022-06-21 11:03:01 +08:00
|
|
|
typedef struct command {
|
2022-01-12 00:01:42 +08:00
|
|
|
|
|
|
|
struct kernel *ker;
|
|
|
|
|
|
|
|
struct command *next;
|
|
|
|
struct command *prev;
|
|
|
|
|
|
|
|
} cu_command;
|
|
|
|
|
2022-06-21 11:03:01 +08:00
|
|
|
typedef struct argument {
|
2022-01-12 00:01:42 +08:00
|
|
|
// size of the argument to allocation
|
|
|
|
size_t size;
|
|
|
|
void *value;
|
|
|
|
unsigned int index;
|
|
|
|
} cu_argument;
|
|
|
|
|
2022-06-21 11:03:01 +08:00
|
|
|
typedef struct input_arg {
|
2022-01-12 00:01:42 +08:00
|
|
|
// real values for the input
|
|
|
|
char *p;
|
|
|
|
struct argument *argus[];
|
|
|
|
// (TODO): implement meta_data
|
|
|
|
// the type of metadata will need to change to list of ints or something
|
|
|
|
// so that we can parse the arguments p
|
|
|
|
} cu_input;
|
|
|
|
|
2022-06-21 11:03:01 +08:00
|
|
|
enum StreamType {
|
2022-01-12 00:01:42 +08:00
|
|
|
DEFAULT,
|
|
|
|
LOW,
|
|
|
|
HIGH,
|
|
|
|
EXT,
|
|
|
|
};
|
|
|
|
|
2022-06-21 11:03:01 +08:00
|
|
|
struct cStreamDataInternal {
|
2022-01-12 00:01:42 +08:00
|
|
|
/*
|
|
|
|
status of the stream (run , wait)
|
|
|
|
Run: Stream will asynchronously assign the kernel assign with this stream
|
|
|
|
Wait: Stream will halt kernels from exiting the scheduler
|
|
|
|
*/
|
|
|
|
int status;
|
|
|
|
/*
|
|
|
|
if status == wait, wait on the number of kernels to wait to become 0
|
|
|
|
*/
|
|
|
|
unsigned long numKernelsToWait;
|
|
|
|
unsigned int lastKernelIdToWait;
|
|
|
|
unsigned int count; // number of task left in the stream
|
|
|
|
};
|
|
|
|
|
2022-06-21 11:03:01 +08:00
|
|
|
typedef struct streamData {
|
2022-01-12 00:01:42 +08:00
|
|
|
|
|
|
|
// execution status of current event monitor
|
|
|
|
struct cStreamDataInternal ev;
|
|
|
|
pthread_mutex_t stream_lock; // lock on the stream
|
|
|
|
StreamType stream_priority;
|
|
|
|
unsigned int id;
|
|
|
|
unsigned int stream_flags;
|
|
|
|
|
2022-06-21 07:01:28 +08:00
|
|
|
kernel_queue *kernelQueue;
|
2022-01-12 00:01:42 +08:00
|
|
|
|
|
|
|
} cstreamData;
|
|
|
|
|
2022-06-21 11:03:01 +08:00
|
|
|
typedef struct asyncKernel {
|
2022-01-12 00:01:42 +08:00
|
|
|
unsigned int numBlocks;
|
|
|
|
unsigned int numThreads;
|
|
|
|
struct event *evt;
|
|
|
|
struct kernel *ker;
|
|
|
|
|
|
|
|
struct asyncKernel *prev;
|
|
|
|
struct asyncKernel *next;
|
|
|
|
|
|
|
|
} asyncKernel;
|
|
|
|
|
|
|
|
// command queue of command nodes
|
|
|
|
|
2022-06-21 11:03:01 +08:00
|
|
|
typedef struct kernel_arg_array {
|
2022-01-12 00:01:42 +08:00
|
|
|
size_t size;
|
|
|
|
unsigned int index;
|
|
|
|
} karg_arr;
|
|
|
|
|
2022-06-21 11:03:01 +08:00
|
|
|
typedef struct kernel_image_arg {
|
2022-01-12 00:01:42 +08:00
|
|
|
size_t size;
|
|
|
|
unsigned int index;
|
|
|
|
} k_arg;
|
|
|
|
|
2022-06-21 11:03:01 +08:00
|
|
|
typedef struct callParams {
|
2022-05-04 20:59:38 +08:00
|
|
|
dim3 gridDim;
|
|
|
|
dim3 blockDim;
|
|
|
|
size_t shareMem;
|
|
|
|
void *stream;
|
|
|
|
} callParams;
|
|
|
|
|
2022-01-12 00:01:42 +08:00
|
|
|
#endif // HEADER_FILE
|