view TaskManager/kernel/ppe/HTask.h @ 1548:614a3f62c881 draft

add set work item size function
author Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
date Fri, 15 Feb 2013 07:37:04 +0900
parents a7895ab4d0e3
children ebaaaac6751a
line wrap: on
line source

#ifndef INCLUDED_HTASK
#define INCLUDED_HTASK

#include "base.h"
#include "types.h"
#include "Task.h"
#include "TaskList.h"
#include "TaskQueue.h"
#include "QueueInfo.h"
#include "TaskLog.h"
//#include <stdio.h>

class TaskManagerImpl;
class SchedTask;

typedef void (*PostFunction)(SchedTask *s, void *read, void *write);

extern QueueInfo<TaskQueue>* taskQueuePool;

/*!
  @class

  @brief

  Cerium の Task で、spawn() でキューに格納されて順次実行される。
  cpu の指定があれば並列に実行される。
  特定の Task を待ち合わせる事が可能。
  Task の入出力は dma などで copy される。
 */

#include "SimpleTask.h"

class HTask : public SimpleTask {
public:
    BASE_NEW_DELETE(HTask);

    QueueInfo<TaskQueue> *wait_me;  // List of task waiting for me
    QueueInfo<TaskQueue> *wait_i;   // List of task for which I am waiting
    PostFunction post_func;
    void *post_arg1;
    void *post_arg2;
    CPU_TYPE cpu_type;
    TaskManagerImpl *mimpl;
    TaskPtr last;

    int export_task_log;
    TaskLog *tasklog;

    HTask *waiter;
    HTask *next;
    HTask *prev;

    struct htask_flag {
        unsigned no_auto_free:1;        //      bit 0    auto free flag (0 .. auto, 1 manual)
        unsigned flip:1;                //      use read write buffers for all
        unsigned nd_range:1;            //      openCL nd_range
    } flag;

    void spawn();
    void wait_for(HTask *);
    void set_cpu(CPU_TYPE type);
    void set_post(PostFunction func, void *read, void *write);
    Task *create_task_array(int task_id, int num_task, int num_param, int num_inData, int num_outData);
    Task *next_task_array(int task_id, Task *t);
    Task *next_task_array(int id, Task *t, int param_count, int inData_count, int outData_count);
    void spawn_task_array(Task *t);

    HTask *init(int cmd, memaddr rbuf, int rs, memaddr wbuf, int ws) {
        init(cmd);
        set_input(rbuf, rs);
        set_output(wbuf, ws);
        return this;
    }

    void initOnce() {
       wait_me = new QueueInfo<TaskQueue>(taskQueuePool);
       wait_i = new QueueInfo<TaskQueue>(taskQueuePool);
    }

    void freeOnce() {
       delete wait_me;
       delete wait_i;
    }

    private:

// compatibility
    public: // functions
    void set_inData_t(int index, memaddr addr, int size) {
#ifdef EARLY_TOUCH
        if ((unsigned long)addr&0xf) {
          printf("inData is not aligned. command = %d, index = %d, addr = 0x%lx, size = %d\n",
                 command, index, (unsigned long)addr, size);
        }
        char *p = (char *)addr; char b = *p;
        p = (char *)(addr+size-1); b += *p;
#endif
        Task *t = ((TaskList*)rbuf)->tasks;
        t->set_inData_t(index, addr,size);
    }
    void set_outData_t(int index, memaddr addr, int size) {
#ifdef EARLY_TOUCH
        if ((unsigned long)addr&0xf) {
          printf("inData is not aligned. command = %d, index = %d, addr = 0x%lx, size = %d\n",
                 command, index, (unsigned long)addr, size);
        }
        char *p = (char *)addr; char b = *p;
        p = (char *)(addr+size-1); b += *p;
#endif
        Task *t = ((TaskList*)rbuf)->tasks;
        t->set_outData_t(index, addr,size);
    }
    void set_param_t(int index, memaddr param) {
        Task *t = ((TaskList*)rbuf)->tasks;
        t->set_param_t(index, param);
    }

    void no_auto_free() {
        flag.no_auto_free = 1;
    }
    void auto_free() {
        flag.no_auto_free = 0;
    }

    void flip() {
        flag.flip = 1;
    }
    void no_flip() {
        flag.flip = 0;
    }
    void NDrange() {
        flag.nd_range = 1;
    }
    void no_NDrange() {
        flag.nd_range = 0;
    }

    htask_flag get_flag(){
        return flag;
    }

    void init() {
        next = prev = NULL;
        waiter = NULL;
    }

    void init(int cmd) {
        command  = cmd;
        flag.no_auto_free = 0;
        flag.flip = 0;
        flag.nd_range = 0;
        self = (memaddr) this;

        post_func = NULL;
        mimpl     = NULL;
        cpu_type  = CPU_PPE;

        post_arg1 = NULL;
        post_arg2 = NULL;
    }
#define set_param(index,param) set_param_t(index, (memaddr) (param))

}  __attribute__ ((aligned (DEFAULT_ALIGNMENT)));

typedef HTask* HTaskPtr;

#endif