Mercurial > hg > Game > Cerium
view TaskManager/Cuda/CudaThreads.cc @ 2022:fac44ad2867d draft
make a sound
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 16 Jul 2014 02:50:32 +0900 |
parents | fdffcf8feeab |
children |
line wrap: on
line source
#include "CudaThreads.h" #include "CudaScheduler.h" #include "TaskManagerImpl.h" #include "SpeTaskManagerImpl.h" const int gpu_num = 1; CudaThreads::CudaThreads(int useRefDma) : use_refdma(useRefDma) { threads = new pthread_t[gpu_num]; args = new cuda_thread_arg_t; } CudaThreads::~CudaThreads() { memaddr mail = (memaddr)MY_SPE_COMMAND_EXIT; send_mail(0,1,&mail); pthread_join(threads[0], NULL); delete args->scheduler; delete[] threads; delete args; } /** Called from CpuThreads::init() This Semaphore tells that GpuThreads is initalized. */ void CudaThreads::set_wait(SemPtr wait) { args->wait=wait; } void CudaThreads::init() { args->scheduler = new CudaScheduler(); args->useRefDma = use_refdma; pthread_create(&threads[0], NULL, &cuda_thread_run, args); } void CudaThreads::set_mail_waiter(SemPtr w) { args->scheduler->connector->set_mail_waiter(w); } void * CudaThreads::cuda_thread_run(void *args) { cuda_thread_arg_t *argt = (cuda_thread_arg_t *) args; Scheduler *g_scheduler = argt->scheduler; TaskManagerImpl *manager = new SpeTaskManagerImpl(); g_scheduler->init(manager, argt->useRefDma); manager->set_scheduler(g_scheduler); argt->wait->sem_v(); g_scheduler->run(); g_scheduler->finish(); return NULL; } int CudaThreads::spawn_task(int id, TaskListPtr p) { send_mail(id, 1, (memaddr*)p); return 0; } int CudaThreads::get_mail(int speid, int count, memaddr *ret) { *ret = args->scheduler->mail_read_from_host(); return 1; } int CudaThreads::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 CudaThreads::send_mail(int speid, int num, memaddr *data) { args->scheduler->mail_write_from_host(*data); } void CudaThreads::add_output_tasklist(int command, memaddr buff, int alloc_size) { }