Mercurial > hg > Game > Cerium
changeset 1441:50d2c1e85535 draft
change to get size for fstat
author | Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 23 Apr 2012 18:53:35 +0900 |
parents | d66dcb067c89 |
children | db8a954fcfb3 |
files | TaskManager/Gpu/GpuScheduler.cc TaskManager/test/GpuThreadTest/GpuScheduler.cc TaskManager/test/GpuThreadTest/GpuScheduler.h TaskManager/test/GpuThreadTest/GpuThreadsTest.cc |
diffstat | 4 files changed, 40 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Gpu/GpuScheduler.cc Mon Apr 23 05:48:02 2012 +0900 +++ b/TaskManager/Gpu/GpuScheduler.cc Mon Apr 23 18:53:35 2012 +0900 @@ -2,6 +2,7 @@ #include "GpuDmaManager.h" #include "GpuThreads.h" #include "stdio.h" +#include <fcntl.h> void GpuScheduler::init_impl(int useRefDma) @@ -22,7 +23,7 @@ TaskListPtr *tasklist = (TaskListPtr)connector->dma_load(tasklist, params_addr, sizeof(TaskList), DMA_READ_TASKLIST); GpuThreads gputhreads = GpuThreads::getInstance(); - cl_command_queue& command_queue = &gputhreads.cl_command_queue; + cl_command_queue& command_queue = gputhreads.cl_command_queue; for (int cur_index = 0; cur_index < tasklist->length; cur_index++) { TaskPtr task = tasklist.tasks[cur_index]; @@ -44,19 +45,29 @@ cl_context& context = &gputhreads.context; cl_device_id& device_id = &gputhreads.device_id; - FILE *fp; + int *fp; char *souce_str; size_t source_size; - - fp = fopen(filename, "r"); + + fp = open(filename, O_RDONLY); + if (!fp) { fprintf(stderr, "Failed to load kernel.\n"); exit(1); } + + struct stat stats; + fstat(fileno(fp),&stats); + off_t size = stas.st_size; + + if (!size) { + fprintf(stderr, "Failed to load kernel.\n"); + } + + source_str = (char*)malloc(size); - source_str = (char*)malloc(MAX_SOURCE_SIZE); - source_size = fread(source_str, 1, MAX_SOURCE_SIZE, fp); - fclose(fp); + source_size = read(source_str, size, fp); + close(fp); cl_program program = NULL; cl_int ret;
--- a/TaskManager/test/GpuThreadTest/GpuScheduler.cc Mon Apr 23 05:48:02 2012 +0900 +++ b/TaskManager/test/GpuThreadTest/GpuScheduler.cc Mon Apr 23 18:53:35 2012 +0900 @@ -2,6 +2,7 @@ #include "GpuDmaManager.h" #include "GpuThreads.h" #include "stdio.h" +#include <fcntl.h> void GpuScheduler::init_impl(int useRefDma) @@ -20,7 +21,7 @@ } TaskListPtr *tasklist = (TaskListPtr)connector->dma_load(tasklist, params_addr, - sizeof(TaskList), DMA_READ_TASKLIST); + sizeof(TaskList), DMA_READ_TASKLIST); GpuThreads gputhreads = GpuThreads::getInstance(); cl_command_queue& command_queue = gputhreads.cl_command_queue; @@ -44,19 +45,29 @@ cl_context& context = &gputhreads.context; cl_device_id& device_id = &gputhreads.device_id; - FILE *fp; + int *fp; char *souce_str; size_t source_size; - - fp = fopen(filename, "r"); + + fp = open(filename, O_RDONLY); + if (!fp) { fprintf(stderr, "Failed to load kernel.\n"); exit(1); } + + struct stat stats; + fstat(fileno(fp),&stats); + off_t size = stas.st_size; + + if (!size) { + fprintf(stderr, "Failed to load kernel.\n"); + } + + source_str = (char*)malloc(size); - source_str = (char*)malloc(MAX_SOURCE_SIZE); - source_size = fread(source_str, 1, MAX_SOURCE_SIZE, fp); - fclose(fp); + source_size = read(source_str, size, fp); + close(fp); cl_program program = NULL; cl_int ret;
--- a/TaskManager/test/GpuThreadTest/GpuScheduler.h Mon Apr 23 05:48:02 2012 +0900 +++ b/TaskManager/test/GpuThreadTest/GpuScheduler.h Mon Apr 23 18:53:35 2012 +0900 @@ -20,5 +20,5 @@ #endif -/*#define GpuSchedRegister(str, filename, functionname) \ - gpu_register_task(str, filename, functionname)*/ +#define GpuSchedRegister(str, filename, functionname) \ + gpu_register_task(str, filename, functionname)
--- a/TaskManager/test/GpuThreadTest/GpuThreadsTest.cc Mon Apr 23 05:48:02 2012 +0900 +++ b/TaskManager/test/GpuThreadTest/GpuThreadsTest.cc Mon Apr 23 18:53:35 2012 +0900 @@ -3,26 +3,15 @@ //#include "GpuScheduler.h" #include "CellTaskManagerImpl.h" -#define MAX_SOURCE_SIZE (0x100000) - void main(int argc, char* argv[]) { GpuThreads* c = GpuThreads::getInstance(); c->init(); - - FILE *fp; - char *kernel_src_str; - size_t kernel_code_size; - fp = fopen("twice.cl", "r"); - kernel_src_str = (char *)malloc(MAX_SOURCE_SIZE); - kernel_code_size = fread(kernel_src_str, 1, MAX_SOURCE_SIZE, fp); - fclose(fp); - - gpu_register_task(1, kernel_src_str,"Twice"); - delete c; + gpu_register_task(1, "twice.cl","Twice"); + delete c; } /* end */