view TaskManager/Gpu/GpuThreads.cc @ 1477:5ca4e9469c65 draft

remove GpuTaskManagerImpl
author Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
date Thu, 19 Jul 2012 14:03:49 +0900
parents 5b79077e4e1f
children f2512fb94223
line wrap: on
line source

#include "GpuThreads.h"
#include "GpuScheduler.h"
#include "TaskManagerImpl.h"
#include "SpeTaskManagerImpl.h"

GpuThreads::GpuThreads()
{
    threads = new pthread_t;
    args = new gpu_arg;
}

GpuThreads::~GpuThreads()
{
    delete threads;
    delete args;

    clReleaseCommandQueue(command_queue);
    clReleaseContext(context);
}

void
GpuThreads::init()
{
    clGetPlatformIDs(1, &platform_id, &ret_num_platforms); 
    clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id, &ret_num_devices);
    // unavailable GPU
    if( ret_num_devices == 0) {
        exit(EXIT_FAILURE);
    }
    context = clCreateContext(NULL, 1, &device_id, NULL, NULL, &ret);
    command_queue = clCreateCommandQueue(context, device_id, 0, &ret);

    args->scheduler = new GpuScheduler();
    args->useRefDma = use_refdma;

    // pthread_create(threads, NULL, &gpu_thread_run, args);

}

void *
GpuThreads::gpu_thread_run(void *args)
{
    gpu_arg *argt = (gpu_arg *) args;
    Scheduler *g_scheduler = argt->scheduler;

    TaskManagerImpl *manager = new SpeTaskManagerImpl();
    g_scheduler->init(manager, argt->useRefDma);

    manager->set_scheduler(g_scheduler);

    g_scheduler->run();
    g_scheduler->finish();

    return NULL;
}

int
GpuThreads::get_mail(int speid, int count, memaddr *ret)
{
    *ret = args->scheduler->mail_read_from_host();
    return 1;
}

int
GpuThreads::has_mail(int speid, int count, memaddr *ret)
{
    if (args->scheduler->has_mail_from_host() != 0) {
        return get_mail(0, 0, ret);
    } else {
        return 0;
    }
}

void
GpuThreads::send_mail(int speid, int num, memaddr *data)
{
    args->scheduler->mail_write_from_host(*data);
}

void
GpuThreads::add_output_tasklist(int command, memaddr buff, int alloc_size)
{
}