view example/multiply/main.cc @ 1561:e8c9a7099bcc draft

add set NDRange param
author Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
date Tue, 12 Mar 2013 16:52:49 +0900
parents f71632373220
children 4e1899c693f0
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "TaskManager.h"
#include "Func.h"
/*
typedef struct nd_range {
    int dimension;
    size_t gws[3];
    size_t lws[3];
} ND_RANGE_T, *ND_RANGE_T_PTR;
*/
extern void task_init(void);
static int task = 1;
static int length = DATA_NUM;
const char *usr_help_str = "Usage: ./multiply \n";
void TMend(TaskManager *);

float *A,*B,*C;

static void
print_result()
{
    printf("---\n");
    for (int i =0;i<length;i++) {
        printf("%f * %f = %f \n",A[i],B[i],C[i]);
    }
    printf("---\n");
}

void
multi_init(TaskManager *manager)
{
    HTask *multiply;
    
    A = new float[length];
    B = new float[length];
    C = new float[length];
    for(int i=0; i<length; i++) {
        A[i]=(float)(i+1000);
        B[i]=(float)i/10.f;
    }
    /**
     * Create Task
     *   create_task(Task ID);
     */

    ND_RANGE_T_PTR ndr = new ND_RANGE_T;
    ndr->dimension = 1;
    ndr->gws[0] = 100; ndr->gws[1] = 1; ndr->gws[2] = 1;
    ndr->lws[0] = 1;   ndr->lws[1] = 1; ndr->lws[2] = 1;
    manager->set_NDRange(ndr);

    multiply = manager->create_task(MULTIPLY_TASK);
    multiply->set_param(0,(memaddr)&ndr);
    multiply->nd_range();
    multiply->set_cpu(SPE_ANY);

    /**
     * Set of Input Data
     *   add_inData(address of input data, size of input data);
     */
    multiply->set_inData(0,(memaddr)A, sizeof(float)*length);
    multiply->set_inData(1,(memaddr)B, sizeof(float)*length);

    /**
     * Set of OutPut area
     *   add_outData(address of output area, size of output area);
     */
    multiply->set_outData(0,(memaddr)C, sizeof(float)*length);

    /**
     * Set 32bits parameter
     *   add_param(32bit parameter);
     */
    multiply->set_param(1,(memaddr)length);
    
    // add Active Queue
    multiply->spawn();
}


int
TMmain(TaskManager *manager,int argc, char *argv[])
{
    // Task Register
    //   ppe/task_init.cc
    task_init();

    for (int i = 0; i < task; ++i) {
        multi_init(manager);
    }

    manager->set_TMend(TMend);

    return 0;
}

void
TMend(TaskManager *manager)
{
    print_result();
}