Exemple #1
0
// paramv[0]: event to satisfy when kernel is done
// depv[0]: setupEdt completed (may carry a DB)
ocrGuid_t kernelEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) {
    // PRINTF("kernelEdt\n");
    ocrGuid_t kernelEdtDoneEvt;
    kernelEdtDoneEvt.guid = paramv[0];
    ocrGuid_t setupDb = depv[0].guid;
    domainSetup_t * setupDbPtr = depv[0].ptr;

    // The sub kernel done event
    ocrGuid_t subKernelDoneEvt;
    ocrEventCreate(&subKernelDoneEvt, OCR_EVENT_ONCE_T, true);

    // This EDT done event
    ocrGuid_t selfDoneEvt;
    ocrEventCreate(&selfDoneEvt, OCR_EVENT_ONCE_T, true);

    // Combine those in a combine EDT that satisfies kernelEdtDoneEvt
    //TODO same issue of allocating tpl every iteration
    ocrGuid_t curAffGuid;
    ocrAffinityGetCurrent(&curAffGuid);
    ocrGuid_t combEdtTplGuid;
    ocrEdtTemplateCreate(&combEdtTplGuid, combineKernelEdt, 1, 2);
    ocrGuid_t combineEdtGuid;
    combine(&combineEdtGuid, combEdtTplGuid, curAffGuid,
                  selfDoneEvt, subKernelDoneEvt, kernelEdtDoneEvt);
    ocrEdtTemplateDestroy(combEdtTplGuid);

    timestamp_t timer;
    domainKernel(subKernelDoneEvt, setupDbPtr, &timer);

    // Satisfy self event with the timer information
    ocrEventSatisfy(selfDoneEvt, setupDb);
    return NULL_GUID;
}
Exemple #2
0
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) {
    // Current thread is '0' and goes on with user code.
    ocrGuid_t ndepv[1];
    ocrGuid_t eventGuid;
    ocrEventCreate(&eventGuid, OCR_EVENT_STICKY_T, true);
    ndepv[0] = eventGuid;

    // Creates the EDT
    u32 nparamc = 1;
    u64 nparamv = 32;

    // 'ndepv' stores dependencies, so no need to call
    // ocrAddDependence later on to register events.
    ocrGuid_t edtGuid;
    ocrGuid_t taskForEdtTemplateGuid;
    ocrEdtTemplateCreate(&taskForEdtTemplateGuid, taskForEdt, nparamc, 1 /*depc*/);
    ocrEdtCreate(&edtGuid, taskForEdtTemplateGuid, EDT_PARAM_DEF, &nparamv, EDT_PARAM_DEF, /*depv=*/ndepv,
                 /*properties=*/0, NULL_HINT, /*outEvent=*/NULL);

    int *k;
    ocrGuid_t dbGuid;
    ocrDbCreate(&dbGuid,(void **) &k,
                sizeof(int), /*flags=*/DB_PROP_NONE,
                /*location=*/NULL_HINT,
                NO_ALLOC);
    *k = 42;

    ocrEventSatisfy(eventGuid, dbGuid);

    return NULL_GUID;
}
Exemple #3
0
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) {
    // Creates a data block
    int *k;
    ocrGuid_t dbGuid;
    ocrDbCreate(&dbGuid,(void **) &k,
            sizeof(int), /*flags=*/0,
            /*location=*/NULL_GUID,
            NO_ALLOC);
    *k = 42;

    ocrGuid_t eventGuid;
    ocrEventCreate(&eventGuid, OCR_EVENT_STICKY_T, true);

    // Creates the EDT
    ocrGuid_t edtGuid;
    ocrGuid_t taskForEdtTemplateGuid;
    ocrEdtTemplateCreate(&taskForEdtTemplateGuid, taskForEdt, 0 /*paramc*/, 1 /*depc*/);
    ocrEdtCreate(&edtGuid, taskForEdtTemplateGuid, EDT_PARAM_DEF, /*paramv=*/NULL, EDT_PARAM_DEF, /*depv=*/NULL,
                    /*properties=*/0, NULL_GUID, /*outEvent=*/NULL);

    ocrAddDependence(eventGuid, edtGuid, 0, DB_MODE_RO);

    // Register a dependence between a db and an event
    // (equivalent to directly satisfying the DB)
    ocrAddDependence(dbGuid, eventGuid, 0, DB_MODE_RO);

    // No need to satisfy as addDependence is equivalent to a satisfy
    // when the source is a datablock

    return NULL_GUID;
}
Exemple #4
0
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) {
    // Current thread is '0' and goes on with user code.
    ocrGuid_t e0;
    ocrEventCreate(&e0, OCR_EVENT_ONCE_T, EVT_PROP_TAKES_ARG);

    // Creates the EDTa
    ocrGuid_t edtGuid;
    ocrGuid_t taskForEdtTemplateGuid;
    ocrEdtTemplateCreate(&taskForEdtTemplateGuid, taskForEdt, 0 /*paramc*/, 2/*depc*/);
    ocrEdtCreate(&edtGuid, taskForEdtTemplateGuid, EDT_PARAM_DEF, /*paramv=*/NULL, EDT_PARAM_DEF, /*depv=*/NULL,
                 /*properties=*/0, NULL_HINT, /*outEvent=*/NULL);

    // Register a dependence between an event and an edt
    ocrAddDependence(e0, edtGuid, 0, DB_MODE_CONST);
    ocrAddDependence(e0, edtGuid, 1, DB_MODE_CONST);

    int *k;
    ocrGuid_t dbGuid;
    ocrDbCreate(&dbGuid,(void **) &k,
                sizeof(int), /*flags=*/DB_PROP_NONE,
                /*location=*/NULL_HINT,
                NO_ALLOC);
    *k = 42;

    // Satisfy event's chain head
    ocrEventSatisfy(e0, dbGuid);

    return NULL_GUID;
}
Exemple #5
0
// Create an event at the current affinity and writes
// the GUID into the domainSetup data-structure.
void domainSetup(ocrGuid_t userSetupDoneEvt, domainSetup_t * dsetup) {
    // This is for the domain kernel to callback and stop the timer
    ocrGuid_t stopTimerEvt;
    ocrEventCreate(&stopTimerEvt, OCR_EVENT_ONCE_T, true);

    // Create an EDT at a remote affinity to:
    // - Create a remote latch event and initialize it
    // - Hook that event to the local event declared above
    // - write back the guid of the remote latch event into the setup DB

    // - userSetupDoneEvt: to be satisfied when setup is done
    // - stopTimerEvt: to be satisfied when domain kernel is done
    dsetup->userSetupDoneEvt = userSetupDoneEvt;
    dsetup->stopTimerEvt = stopTimerEvt;

    u64 affinityCount;
    ocrAffinityCount(AFFINITY_PD, &affinityCount);
    ocrGuid_t remoteAffGuid;
    ocrAffinityGetAt(AFFINITY_PD, affinityCount-1, &remoteAffGuid);
    ocrHint_t edtHint;
    ocrHintInit(&edtHint, OCR_HINT_EDT_T);
    ocrSetHintValue(&edtHint, OCR_HINT_EDT_AFFINITY, ocrAffinityToHintValue(remoteAffGuid));
    ocrGuid_t edtTemplGuid;
    ocrEdtTemplateCreate(&edtTemplGuid, remoteSetupUserEdt, 0, 1);
    ocrGuid_t edtGuid;
    ocrEdtCreate(&edtGuid, edtTemplGuid,
                 0, NULL, 1, NULL, EDT_PROP_NONE, &edtHint, NULL);
    // EW addresses the race that the current caller owns the DB and we're
    // trying to start the remote setup EDT concurrently. Since we do not have
    // the caller event we can't setup a proper dependence and rely on EW instead.
    ocrAddDependence(dsetup->self, edtGuid, 0, DB_MODE_EW);
    ocrEdtTemplateDestroy(edtTemplGuid);
}
Exemple #6
0
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) {
    PRINTF("mainEdt\n");
    u32 maxIt = NB_ITERS;

    u64 affCount = 0;
    ocrAffinityCount(AFFINITY_PD, &affCount);
    ocrGuid_t affinities[affCount];
    ocrAffinityGet(AFFINITY_PD, &affCount, affinities);

    ocrGuid_t infoDbGuid;
    info_t * infoDbPtr;
    ocrDbCreate(&infoDbGuid, (void**) &infoDbPtr, sizeof(info_t), 0, NULL_HINT, NO_ALLOC);

    setupFramework(infoDbPtr, infoDbGuid, maxIt, (u32) affCount);
    ocrGuid_t iterTemplGuid = infoDbPtr->edtTemplGuids[ITER_IDX];
    ocrGuid_t endTemplGuid  = infoDbPtr->edtTemplGuids[END_IDX];
    ocrGuid_t affinity = affinities[infoDbPtr->edtAffinities[END_IDX]];
    ocrDbRelease(infoDbGuid);

    ocrGuid_t itDoneEvtGuid;
    ocrEventCreate(&itDoneEvtGuid, OCR_EVENT_STICKY_T, false);

    ocrGuid_t iterateEdtGuid;
    iterate(&iterateEdtGuid, iterTemplGuid,
            /*prev*/NULL_GUID, infoDbGuid, /*next*/itDoneEvtGuid);

    ocrGuid_t endEdtGuid;
    chain(&endEdtGuid, endTemplGuid, affinity, itDoneEvtGuid, NULL_GUID);

    return NULL_GUID;
}
Exemple #7
0
int main (int argc, char ** argv) {
    ocrEdt_t fctPtrArray [1];
    fctPtrArray[0] = &task_for_edt;
    ocrInit(&argc, argv, 1, fctPtrArray);

    // Current thread is '0' and goes on with user code.
    ocrGuid_t event_guid;
    ocrEventCreate(&event_guid, OCR_EVENT_STICKY_T, true);

    // Creates the EDT
    ocrGuid_t edt_guid;

    ocrEdtCreate(&edt_guid, task_for_edt, /*paramc=*/0, /*params=*/ NULL,
                 /*paramv=*/NULL, /*properties=*/0,
                 /*depc=*/1, /*depv=*/NULL);

    // Register a dependence between an event and an edt
    ocrAddDependence(event_guid, edt_guid, 0);
    // Schedule the EDT (will run when dependences satisfied)
    ocrEdtSchedule(edt_guid);

    int *k;
    ocrGuid_t db_guid;
    ocrDbCreate(&db_guid, (void **) &k, sizeof(int), /*flags=*/FLAGS,
                /*location=*/NULL, NO_ALLOC);
    *k = 42;

    ocrEventSatisfy(event_guid, db_guid);

    ocrCleanup();

    return 0;
}
void test () {
    // Current thread is '0' and goes on with user code.
    ocrGuid_t eventGuid;
    ocrEventCreate(&eventGuid, OCR_EVENT_STICKY_T, true);

    // Creates the EDT
    ocrGuid_t edtGuid;
    ocrGuid_t taskForEdtTemplateGuid;
    ocrEdtTemplateCreate(&taskForEdtTemplateGuid, taskForEdt, 0 /*paramc*/, 1 /*depc*/);

    ocrEdtCreate(&edtGuid, taskForEdtTemplateGuid, EDT_PARAM_DEF, /*paramv=*/NULL,
                 EDT_PARAM_DEF, /*depv=*/NULL, 0, NULL_GUID, NULL);

    // Register a dependence between an event and an edt
    ocrAddDependence(eventGuid, edtGuid, 0, DB_MODE_RO);

    int *k;
    ocrGuid_t db_guid;
    ocrDbCreate(&db_guid,(void **) &k,
            sizeof(int), /*flags=*/FLAGS,
            /*location=*/NULL_GUID,
            NO_ALLOC);
    *k = 42;

    ocrEventSatisfy(eventGuid, db_guid);
}
Exemple #9
0
// paramv[0]: continuation after iterations
// depv[0]: info
// depv[1]: done event for the work spawned by the iteration, carries the time DB
ocrGuid_t iterationEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) {
    ocrGuid_t iterationsDoneEvt;
    iterationsDoneEvt.guid = paramv[0];
    ocrGuid_t infoGuid = depv[0].guid;
    info_t * info = (info_t *) depv[0].ptr;
    ocrGuid_t timeDbGuid = depv[1].guid;
    long * timePrevIt = (long *) depv[1].ptr;

    // PRINTF("iteration %d\n", info->i);
    if (timePrevIt != NULL) {
        info->timer += (*timePrevIt);
        ocrDbRelease(timeDbGuid);
        ocrDbDestroy(timeDbGuid);
    }
    if (info->i < info->max) {
        //TODO do a pipeline EDT
        u64 affCount = 0;
        ocrAffinityCount(AFFINITY_PD, &affCount);
        ocrGuid_t affinities[affCount];
        ocrAffinityGet(AFFINITY_PD, &affCount, affinities);

        ocrGuid_t stageInit;
        ocrEventCreate(&stageInit, OCR_EVENT_ONCE_T, false);
        ocrGuid_t stagePrev = stageInit;
        u32 i = PIPE_START;
        while(i < (PIPE_START+PIPE_SZ)) {
            ocrGuid_t stageEdtDoneEvt;
            ocrEventCreate(&stageEdtDoneEvt, OCR_EVENT_ONCE_T, false);
            ocrGuid_t stageEdtGuid;
            //TODO I wonder if we shouldn't give the whole info to a functor and invoke that
            chain(&stageEdtGuid, info->edtTemplGuids[i], affinities[info->edtAffinities[i]], stagePrev, stageEdtDoneEvt);
            stagePrev = stageEdtDoneEvt;
            i++;
        }
        info->i+=1;
        ocrDbRelease(infoGuid);
        ocrGuid_t nextItEdtGuid;
        // 'iterationsDoneEvt' is passed on and on til the last iteration
        iterate(&nextItEdtGuid, info->edtTemplGuids[ITER_IDX],
                /*prev*/stagePrev, /*data*/infoGuid, /*next*/iterationsDoneEvt);
        // Start the pipeline
        ocrEventSatisfy(stageInit, NULL_GUID);
    } else {
       ocrEventSatisfy(iterationsDoneEvt, infoGuid);
    }
    return NULL_GUID;
}
Exemple #10
0
ocrGuid_t mainEdt ( u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) {
    u64 size = -1;
    u64 offset = -1;
    u32 i = 0;
    u64 argc;

    void *programArg = depv[0].ptr;
    argc = getArgc(programArg);
    if ( argc !=  4 ) {
        PRINTF("Usage: ./basicIO offset size fileName \n");
        ocrShutdown();
        return 1;
    }

    offset = atoi(getArgv(programArg, 1));
    size = atoi(getArgv(programArg, 2));
    u64 nparamv[2];
    nparamv[0] = offset;
    nparamv[1] = size;
    FILE *in;
    in = fopen(getArgv(programArg, 3), "r");
    if( !in ) {
        PRINTF("Cannot find file: %s\n", getArgv(programArg, 3));
        ocrShutdown();
        return NULL_GUID;
    }
    ocrGuid_t dataGuid;
    // Data can be passed as parameter also , there was no
    // necessary need of creating data block  in this example.
    // Its has been created for demo purpose
    //Create datablock to hold a block of 'size' elements
    u64 *inputarr;
    ocrDbCreate(&dataGuid, (void**)&inputarr, sizeof(u64)*size,0,NULL_GUID, NO_ALLOC);
#ifndef TG_ARCH
    while(fscanf(in,"%llu\n",&inputarr[i++])!=EOF);
#else
    fread(inputarr, sizeof(u64),size , in);

#endif
    fclose(in);

    ocrGuid_t addEdtTemplateGuid;
    ocrEdtTemplateCreate(&addEdtTemplateGuid, add_edt, 2 /*paramc*/, 1 /*depc*/);
    ocrGuid_t add_edt_guid;
    // Create the EDT not specifying the dependence vector at creation
    ocrEdtCreate(&add_edt_guid, addEdtTemplateGuid, EDT_PARAM_DEF, nparamv,1,NULL ,EDT_PROP_FINISH , NULL_GUID, NULL);

    ocrGuid_t triggerEventGuid;
    ocrEventCreate(&triggerEventGuid, OCR_EVENT_STICKY_T, true);

    ocrAddDependence(triggerEventGuid, add_edt_guid, 0, DB_MODE_EW);
    ocrEventSatisfy(triggerEventGuid, dataGuid);
    return NULL_GUID;
}
Exemple #11
0
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) {
    ocrGuid_t e0;
    ocrEventCreate(&e0, OCR_EVENT_STICKY_T, false);
    ocrGuid_t terminateEdtGuid;
    ocrGuid_t terminateEdtTemplateGuid;
    ocrEdtTemplateCreate(&terminateEdtTemplateGuid, terminateEdt, 0 /*paramc*/, EDT_PARAM_UNK /*depc*/);
    ocrEdtCreate(&terminateEdtGuid, terminateEdtTemplateGuid, EDT_PARAM_DEF, NULL, 1, NULL_GUID,
                    /*properties=*/EDT_PROP_FINISH, NULL_GUID, /*outEvent=*/ NULL);
    ocrAddDependence(e0, terminateEdtGuid, 0, DB_MODE_RO);
    ocrEventSatisfy(e0, NULL_GUID);
    return NULL_GUID;
}
Exemple #12
0
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) {
    u64 affinityCount;
    ocrAffinityCount(AFFINITY_PD, &affinityCount);
    ocrGuid_t dbAffGuid;
    ocrGuid_t * dbAffPtr;
    ocrDbCreate(&dbAffGuid, (void **)&dbAffPtr, sizeof(ocrGuid_t) * affinityCount, DB_PROP_SINGLE_ASSIGNMENT, NULL_HINT, NO_ALLOC);
    ocrAffinityGet(AFFINITY_PD, &affinityCount, dbAffPtr);
    ASSERT(affinityCount >= 1);

    // create local edt that depends on the remote edt, the db is automatically cloned
    ocrGuid_t remoteEdtTemplateGuid;
    ocrEdtTemplateCreate(&remoteEdtTemplateGuid, remoteEdt, 0, 1);

    ocrGuid_t eventsGuid[COUNT_EDT];
    ocrGuid_t dbsGuid[COUNT_EDT];
    u64 i = 0;
    while(i < COUNT_EDT) {
        ocrEventCreate(&eventsGuid[i],OCR_EVENT_ONCE_T, EVT_PROP_NONE);
        ocrGuid_t * dbPtr;
        ocrDbCreate(&dbsGuid[i], (void **)&dbPtr, sizeof(ocrGuid_t)*2, DB_PROP_SINGLE_ASSIGNMENT, NULL_HINT, NO_ALLOC);
        dbPtr[0] = eventsGuid[i];
        dbPtr[1] = dbAffPtr[i%affinityCount];
        ocrDbRelease(dbsGuid[i]);
        i++;
    }
    ocrDbRelease(dbAffGuid);

    // Setup shutdown EDT
    ocrGuid_t shutdownEdtTemplateGuid;
    ocrEdtTemplateCreate(&shutdownEdtTemplateGuid, shutdownEdt, 0, COUNT_EDT);
    ocrHint_t edtHint;
    ocrHintInit( &edtHint, OCR_HINT_EDT_T );

    ocrGuid_t shutdownEdtGuid;
    ocrEdtCreate(&shutdownEdtGuid, shutdownEdtTemplateGuid, 0, NULL, EDT_PARAM_DEF, eventsGuid,
                 EDT_PROP_NONE, NULL_HINT, NULL);

    // Spawn 'COUNT_EDT' EDTs, each satisfying its event
    i = 0;
    while(i < COUNT_EDT) {
        ocrSetHintValue( & edtHint, OCR_HINT_EDT_AFFINITY, ocrAffinityToHintValue( dbAffPtr[i%affinityCount]) );
        // Create EDTs
        ocrGuid_t edtGuid;
        ocrEdtCreate(&edtGuid, remoteEdtTemplateGuid, 0, NULL, EDT_PARAM_DEF, &dbsGuid[i],
            EDT_PROP_NONE, &edtHint, NULL);
        i++;
    }

    return NULL_GUID;
}
Exemple #13
0
// Input
// - Completion event to be satisfied when setup is done (paramv[0])
ocrGuid_t setupEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) {
    // Setup all done event
    ocrGuid_t setupEdtDoneEvt;
    setupEdtDoneEvt.guid = paramv[0];

    ocrGuid_t curAffGuid;
    ocrAffinityGetCurrent(&curAffGuid);

    ocrGuid_t setupDbGuid;
    domainSetup_t * setupDbPtr;
    ocrHint_t dbHint;
    ocrHintInit(&dbHint, OCR_HINT_DB_T);
    ocrSetHintValue(&dbHint, OCR_HINT_DB_AFFINITY, ocrAffinityToHintValue(curAffGuid));
    ocrDbCreate(&setupDbGuid, (void**) &setupDbPtr, sizeof(domainSetup_t), 0, &dbHint, NO_ALLOC);
    setupDbPtr->self = setupDbGuid;

    // This EDT done event
    ocrGuid_t selfDoneEvt;
    ocrEventCreate(&selfDoneEvt, OCR_EVENT_ONCE_T, true);

    // Create a done event for the user code
    ocrGuid_t subSetupDoneEvt;
    ocrEventCreate(&subSetupDoneEvt, OCR_EVENT_ONCE_T, true);
    ocrGuid_t combEdtTplGuid;
    ocrEdtTemplateCreate(&combEdtTplGuid, combineSetupEdt, 1, 2);
    ocrGuid_t combineEdtGuid;
    combine(&combineEdtGuid, combEdtTplGuid, curAffGuid,
                  selfDoneEvt, subSetupDoneEvt, setupEdtDoneEvt);
    ocrEdtTemplateDestroy(combEdtTplGuid);
    domainSetup(subSetupDoneEvt, setupDbPtr);

    ocrDbRelease(setupDbGuid);
    ocrEventSatisfy(selfDoneEvt, setupDbGuid);

    return NULL_GUID;
}
Exemple #14
0
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) {
    // Current thread is '0' and goes on with user code.
    ocrGuid_t latchGuid;
    ocrEventCreate(&latchGuid, OCR_EVENT_LATCH_T, false);

    // Creates the EDT
    ocrGuid_t edtGuid;
    ocrGuid_t taskForEdtTemplateGuid;
    ocrEdtTemplateCreate(&taskForEdtTemplateGuid, taskForEdt, 0 /*paramc*/, 1 /*depc*/);
    ocrEdtCreate(&edtGuid, taskForEdtTemplateGuid, EDT_PARAM_DEF, /*paramv=*/NULL, EDT_PARAM_DEF, /*depv=*/NULL,
                    /*properties=*/0, NULL_GUID, /*outEvent=*/NULL);

    // Register a dependence between an event and an edt
    ocrAddDependence(latchGuid, edtGuid, 0, DB_MODE_RO);

    // decr first and then incr (reaching zero from negative)
    ocrEventSatisfySlot(latchGuid, NULL_GUID, OCR_EVENT_LATCH_DECR_SLOT);
    ocrEventSatisfySlot(latchGuid, NULL_GUID, OCR_EVENT_LATCH_INCR_SLOT);

    return NULL_GUID;
}
Exemple #15
0
ocrGuid_t finishEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) {
    ocrGuid_t edtTemplateGuid;
    ocrEdtTemplateCreate(&edtTemplateGuid, remoteEdt, 0, 1);

    ocrGuid_t eventsGuid[COUNT_EDT];
    ocrGuid_t dbsGuid[COUNT_EDT];
    u64 i = 0;
    while(i < COUNT_EDT) {
        ocrEventCreate(&eventsGuid[i],OCR_EVENT_ONCE_T, EVT_PROP_NONE);
        ocrGuid_t * dbPtr;
        ocrDbCreate(&dbsGuid[i], (void **)&dbPtr, sizeof(ocrGuid_t), DB_PROP_SINGLE_ASSIGNMENT, NULL_HINT, NO_ALLOC);
        dbPtr[0] = eventsGuid[i];
        ocrDbRelease(dbsGuid[i]);
        i++;
    }

    // Setup shutdown EDT
    ocrGuid_t shutdownEdtTemplateGuid;
    ocrEdtTemplateCreate(&shutdownEdtTemplateGuid, shutdownEdt, 0, COUNT_EDT);

    ocrGuid_t shutdownEdtGuid;
    ocrEdtCreate(&shutdownEdtGuid, shutdownEdtTemplateGuid, 0, NULL, EDT_PARAM_DEF, eventsGuid,
                 EDT_PROP_NONE, NULL_HINT, NULL);
    ocrGuid_t currentAffinity;
    ocrAffinityGetCurrent(&currentAffinity);

    ocrHint_t edtHint;
    ocrHintInit( &edtHint, OCR_HINT_EDT_T );
    ocrSetHintValue( & edtHint, OCR_HINT_EDT_AFFINITY, ocrAffinityToHintValue( currentAffinity) );
    // Spawn 'COUNT_EDT' EDTs, each satisfying its event
    i = 0;
    while(i < COUNT_EDT) {
        // Create EDTs
        ocrGuid_t edtGuid;
        ocrEdtCreate(&edtGuid, edtTemplateGuid, 0, NULL, EDT_PARAM_DEF, &dbsGuid[i],
            EDT_PROP_NONE, &edtHint, NULL);
        i++;
    }
    return NULL_GUID;
}
Exemple #16
0
int main (int argc, char ** argv) {
    ocrEdt_t fctPtrArray [1];
    fctPtrArray[0] = &task_for_edt;
    ocrInit(&argc, argv, 1, fctPtrArray);

    // Current thread is '0' and goes on with user code.
    ocrGuid_t event_guid;
    ocrEventCreate(&event_guid, OCR_EVENT_STICKY_T, true);

    // Creates the EDT
    u32 paramc = 1;
    u64 params[1];
    params[0] = sizeof(int);
    int * paramv = (int *) malloc(sizeof(int));
    paramv[0] = 32;

    ocrGuid_t edt_guid;
    ocrEdtCreate(&edt_guid, task_for_edt, paramc, params, (void**) &paramv, 0, 1, NULL);

    // Register a dependence between an event and an edt
    ocrAddDependence(event_guid, edt_guid, 0);

    int *k;
    ocrGuid_t db_guid;
    ocrDbCreate(&db_guid,(void **) &k,
            sizeof(int), /*flags=*/FLAGS,
            /*location=*/NULL,
            NO_ALLOC);
    *k = 42;

    ocrEventSatisfy(event_guid, db_guid);

    ocrEdtSchedule(edt_guid);

    ocrCleanup();

    return 0;
}
Exemple #17
0
ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) {

    u64 arraySize = 100;
    //Create argument vector to hold array size
    u64 nparamv[1];
    nparamv[0] = arraySize;

    u64 * dataArray;
    ocrGuid_t dataGuid;
    //Create datablock to hold a block of 'array size' u64 elements
    ocrDbCreate(&dataGuid, (void **) &dataArray, sizeof(u64)*arraySize,
                /*flags=*/0, /*loc=*/NULL_GUID, NO_ALLOC);

    ocrGuid_t stepAEdtTemplateGuid;
    ocrEdtTemplateCreate(&stepAEdtTemplateGuid, stepA_edt, 1 /*paramc*/, 1 /*depc*/);

    // Create the EDT not specifying the dependence vector at creation
    ocrGuid_t stepAEdtGuid;
    ocrEdtCreate(&stepAEdtGuid, stepAEdtTemplateGuid, EDT_PARAM_DEF, nparamv, 1, NULL,
                /*prop=*/EDT_PROP_NONE, NULL_GUID, NULL);

    ocrGuid_t triggerEventGuid;
    //TODO Setup event used to trigger stepA
    ocrEventCreate(&triggerEventGuid, OCR_EVENT_STICKY_T, EVT_PROP_TAKES_ARG);
    //END-TODO

    //TODO Setup dependence between event and stepA's EDTs slot 0
    ocrAddDependence(triggerEventGuid, stepAEdtGuid, 0, DB_MODE_EW);
    //END-TODO

    //TODO Satisfy the event with the datablock
    ocrEventSatisfy(triggerEventGuid, dataGuid);
    //END-TODO

    return NULL_GUID;
}
Exemple #18
0
int main (int argc, char ** argv) {
    ocrEdt_t fctPtrArray[2] = {summer, autumn};
    ocrInit(&argc, argv, 2, fctPtrArray); /* No machine description */

    if(argc != 3) {
        printf("Usage %s <num1> <num2>\n", argv[0]);
        return -1;
    }

    /* Create 2 data-blocks */
    ocrGuid_t dbs[2];
    int *data[2];
    int i;
    for(i = 0; i < 2; ++i) {
        ocrDbCreate(&dbs[i], (void**)&data[i], sizeof(int), /*flags=*/0,
                    /*location=*/NULL, NO_ALLOC);
        *(data[i]) = atoi(argv[i+1]);
        printf("Created a data-block with value %d (GUID: 0x%lx)\n", i, (u64)dbs[i]);
    }

    ocrGuid_t summerEdt, autumnEdt;
    ocrGuid_t autumnEvt, summerEvt[3];
    ocrGuid_t summerEvtDbGuid;
    ocrGuid_t *summerEvtDb;

    /* Create final EDT (autumn) */
    ocrEdtCreate(&autumnEdt, autumn, /*paramc=*/0, /*params=*/NULL,
                 /*paramv=*/NULL, /*properties=*/0, /*depc=*/1, /*depv=*/NULL);

    /* Create event */
    ocrEventCreate(&autumnEvt, OCR_EVENT_STICKY_T, true);

    /* Create summer */
    ocrEdtCreate(&summerEdt, summer, /*paramc=*/0, /*params=*/NULL,
                 /*paramv=*/NULL, /*properties=*/0, /*depc=*/3, /*depv=*/NULL);

    /* Create events for summer */
    for(i = 0; i < 3; ++i) {
        ocrEventCreate(&summerEvt[i], OCR_EVENT_STICKY_T, true);
    }

    /* Create data-block containing event */
    ocrDbCreate(&summerEvtDbGuid, (void**)&summerEvtDb, sizeof(ocrGuid_t), /*flags=*/0,
                /*location=*/NULL, NO_ALLOC);
    *summerEvtDb = autumnEvt;

    /* Link up dependencees */
    for(i = 0; i < 3; ++i) {
        ocrAddDependence(summerEvt[i], summerEdt, i);
    }

    ocrAddDependence(autumnEvt, autumnEdt, 0);

    /* "Schedule" EDTs (order does not matter) */
    ocrEdtSchedule(autumnEdt);
    ocrEdtSchedule(summerEdt);

    printf("Done all scheduling, now going to satisfy\n");

    /* Satisfy dependences passing data */
    ocrEventSatisfy(summerEvt[0], dbs[0]);
    ocrEventSatisfy(summerEvt[1], dbs[1]);
    ocrEventSatisfy(summerEvt[2], summerEvtDbGuid);

    /* Finalize */
    ocrCleanup();
    return 0;
}
Exemple #19
0
//ocrGuid_t mainEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) {
int main(int argc, char **argv)
{
    int my_ID;
    int Num_procs;
    MPI_Init(&argc,&argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &my_ID);
    MPI_Comm_size(MPI_COMM_WORLD, &Num_procs);
    PRINTF("Starting main on rank %d\n", my_ID);

    u32 input;
    u32 myN;

    if (0 == my_ID)
        {
            if((argc != 2)) {
                PRINTF("Usage: fib <num>, defaulting to 10\n");
                input = 10;
            } else {
                input = atoi(argv[1]);
            }

            myN = input-1;
            u32 yourN = input-2;

            MPI_Send(&yourN, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
        }
    else
        if (1 == my_ID)
            {
                MPI_Recv(&myN, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);

            }
        else  // only need 2
            {
                MPI_Finalize();
                return 0;
            }


    u64 correctAns = fib(myN);


    ocrGuid_t fibC, totallyDoneEvent, absFinalEdt, templateGuid;

    /* create a db for the results */
    ocrGuid_t fibArg;
    u32* res;

    PRINTF("Before 1st DB create\n");
    ocrDbCreate(&fibArg, (void**)&res, sizeof(u32), DB_PROP_NONE, NULL_GUID, NO_ALLOC);
    PRINTF("Got DB created\n");

    /* DB is in/out */
    *res = myN;
    /* and an event for when the results are finished */
    ocrEventCreate(&totallyDoneEvent, OCR_EVENT_STICKY_T, EVT_PROP_TAKES_ARG);

    /* create the EDT with the done_event as the argument */
    {
        u64 paramv[] = {(u64)totallyDoneEvent, my_ID};
        ocrGuid_t depv = fibArg;

        ocrGuid_t templateGuid;
        ocrEdtTemplateCreate(&templateGuid, fibEdt, 2, 1);
        ocrEdtCreate(&fibC, templateGuid, 2, paramv, 1, &depv, EDT_PROP_NONE,
                     NULL_GUID, NULL);
        ocrEdtTemplateDestroy(templateGuid);
    }

    ocrGuid_t DB;
    void *myPtr;
    u64 dbSize;

    ocrLegacyBlockProgress(totallyDoneEvent, &DB, &myPtr, &dbSize, LEGACY_PROP_NONE);
    u32 myAns = *(u32*)myPtr;
    u32 ourAns;

    // get the results
    if (2 == Num_procs)
        {
            MPI_Reduce(&myAns, &ourAns, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
        }
    else
        {
            // extra ranks, need to ignore them else reduce would hang
            // because they have all returned
            if (0 == my_ID)
                {
                    MPI_Recv(&ourAns, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
                    ourAns += myAns;
                }
            else
                {
                    MPI_Send(&myAns, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
                }
        }

    if (0 == my_ID)
        {
            u64 correctAns = fib(input);

            if (correctAns == ourAns)
                {
                    PRINTF("\nFinal Answer Correct fib(%d) = %d\n", input, ourAns);
                }
            else
                {
                    PRINTF("\nFinal Answer **WRONG** fib(%d) = %d, should be %d\n", input, ourAns, correctAns);
                }
        }
    MPI_Finalize();

    return 0;
}
Exemple #20
0
int main ( int argc, char* argv[] ) {

    OCR_INIT(&argc, argv, smith_waterman_task );
    int i, j;

    int tile_width = (int) atoi (argv[3]);
    int tile_height = (int) atoi (argv[4]);

    int n_tiles_width;
    int n_tiles_height;

    if ( argc < 5 ) {
        fprintf(stderr, "Usage: %s fileName1 fileName2 tileWidth tileHeight\n", argv[0]);
        exit(1);
    }

    signed char* string_1;
    signed char* string_2;

    char* file_name_1 = argv[1];
    char* file_name_2 = argv[2];

    FILE* file_1 = fopen(file_name_1, "r");
    if (!file_1) { fprintf(stderr, "could not open file %s\n",file_name_1); exit(1); }
    size_t n_char_in_file_1 = 0;
    string_1 = read_file(file_1, &n_char_in_file_1);
    fprintf(stdout, "Size of input string 1 is %zu\n", n_char_in_file_1 );

    FILE* file_2 = fopen(file_name_2, "r");
    if (!file_2) { fprintf(stderr, "could not open file %s\n",file_name_2); exit(1); }
    size_t n_char_in_file_2 = 0;
    string_2 = read_file(file_2, &n_char_in_file_2);
    fprintf(stdout, "Size of input string 2 is %zu\n", n_char_in_file_2 );

    fprintf(stdout, "Tile width is %d\n", tile_width);
    fprintf(stdout, "Tile height is %d\n", tile_height);

    n_tiles_width = n_char_in_file_1/tile_width;
    n_tiles_height = n_char_in_file_2/tile_height;

    fprintf(stdout, "Imported %d x %d tiles.\n", n_tiles_width, n_tiles_height);

    fprintf(stdout, "Allocating tile matrix\n");

    /* Allocate a 2D matrix of 'Tile's where every Tile has 3 events that represents the readiness
     * of the bottom row, right column and bottom right element of that tile */
    Tile_t** tile_matrix = (Tile_t **) malloc(sizeof(Tile_t*)*(n_tiles_height+1));
    for ( i = 0; i < n_tiles_height+1; ++i ) {
        tile_matrix[i] = (Tile_t *) malloc(sizeof(Tile_t)*(n_tiles_width+1));
        for ( j = 0; j < n_tiles_width+1; ++j ) {
            /* Create readiness events for every tile */
            ocrEventCreate(&(tile_matrix[i][j].bottom_row_event_guid ), OCR_EVENT_STICKY_T, true);
            ocrEventCreate(&(tile_matrix[i][j].right_column_event_guid ), OCR_EVENT_STICKY_T, true);
            ocrEventCreate(&(tile_matrix[i][j].bottom_right_event_guid ), OCR_EVENT_STICKY_T, true);
        }
    }

    fprintf(stdout, "Allocated tile matrix\n");

    initialize_border_values(tile_matrix, n_tiles_width, n_tiles_height, tile_width, tile_height);

    struct timeval a;
    struct timeval b;
    gettimeofday(&a, 0);

    for ( i = 1; i < n_tiles_height+1; ++i ) {
        for ( j = 1; j < n_tiles_width+1; ++j ) {

            /* Box function parameters and put them on the heap for lifetime */
            intptr_t **p_paramv = (intptr_t **)malloc(sizeof(intptr_t*));
            intptr_t *paramv = (intptr_t *)malloc(9*sizeof(intptr_t));
            paramv[0]=(intptr_t) i;
            paramv[1]=(intptr_t) j;
            paramv[2]=(intptr_t) tile_width;
            paramv[3]=(intptr_t) tile_height;
            paramv[4]=(intptr_t) tile_matrix;
            paramv[5]=(intptr_t) string_1;
            paramv[6]=(intptr_t) string_2;
            paramv[7]=(intptr_t) n_tiles_height;
            paramv[8]=(intptr_t) n_tiles_width;
            *p_paramv = paramv;

            /* Create an event-driven tasks of smith_waterman tasks */
            ocrGuid_t task_guid;

            ocrEdtCreate(&task_guid, smith_waterman_task, 9, NULL, (void **) p_paramv, PROPERTIES, 3, NULL);

            /* add dependency to the EDT from the west tile's right column ready event */
            ocrAddDependence(tile_matrix[i][j-1].right_column_event_guid, task_guid, 0);

            /* add dependency to the EDT from the north tile's bottom row ready event */
            ocrAddDependence(tile_matrix[i-1][j].bottom_row_event_guid, task_guid, 1);

            /* add dependency to the EDT from the northwest tile's bottom right ready event */
            ocrAddDependence(tile_matrix[i-1][j-1].bottom_right_event_guid, task_guid, 2);

            /* schedule task*/
            ocrEdtSchedule(task_guid);
        }
    }

    ocrCleanup();
    gettimeofday(&b, 0);
    printf("The computation took %f seconds\r\n",((b.tv_sec - a.tv_sec)*1000000+(b.tv_usec - a.tv_usec))*1.0/1000000);
    return 0;
}
Exemple #21
0
ocrGuid_t fibEdt(u32 paramc, u64* paramv, u32 depc, ocrEdtDep_t depv[]) {
    void* ptr;
    ocrGuid_t inDep;
    ocrGuid_t fib0, fib1, comp;
    ocrGuid_t fibDone[2];
    ocrGuid_t fibArg[2];

    inDep = (ocrGuid_t)paramv[0];
    int my_ID = paramv[1];

    u32 n = *(u32*)(depv[0].ptr);
    PRINTF("r%d Starting fibEdt(%u)\n", my_ID, n);
    if (n < 2) {
        PRINTF("r%d In fibEdt(%d) -- done (sat %lx)\n", my_ID, n, inDep);
        ocrEventSatisfy(inDep, depv[0].guid);
        return NULL_GUID;
    }
    PRINTF("r%d In fibEdt(%d) -- spawning children\n", my_ID, n);

    /* create the completion EDT and pass it the in/out argument as a dependency */
    /* create the EDT with the done_event as the argument */
    {
        u64 paramv[] = {(u64)inDep, my_ID};

        ocrGuid_t templateGuid;
        ocrEdtTemplateCreate(&templateGuid, complete, 2, 3);
        ocrEdtCreate(&comp, templateGuid, 2, paramv, 3, NULL, EDT_PROP_NONE,
                     NULL_GUID, NULL);
        ocrEdtTemplateDestroy(templateGuid);
    }
    PRINTF("r%d In fibEdt(%u) -- spawned complete EDT GUID 0x%llx\n", my_ID, n, (u64)comp);
    ocrAddDependence(depv[0].guid, comp, 2, DB_DEFAULT_MODE);

    /* create the events that the completion EDT will "wait" on */
    ocrEventCreate(&fibDone[0], OCR_EVENT_ONCE_T, EVT_PROP_TAKES_ARG);
    ocrEventCreate(&fibDone[1], OCR_EVENT_ONCE_T, EVT_PROP_TAKES_ARG);
    ocrAddDependence(fibDone[0], comp, 0, DB_DEFAULT_MODE);
    ocrAddDependence(fibDone[1], comp, 1, DB_DEFAULT_MODE);
    /* allocate the argument to pass to fib(n-1) */

    ocrDbCreate(&fibArg[0], (void**)&ptr, sizeof(u32), DB_PROP_NONE, NULL_GUID, NO_ALLOC);
    PRINTF("r%d In fibEdt(%u) -- created arg DB GUID 0x%llx\n", my_ID, n, fibArg[0]);
    *((u32*)ptr) = n-1;
    /* sched the EDT, passing the fibDone event as it's argument */
    {
        u64 paramv[] = {(u64)fibDone[0], my_ID};
        ocrGuid_t depv = fibArg[0];

        ocrGuid_t templateGuid;
        ocrEdtTemplateCreate(&templateGuid, fibEdt, 2, 1);
        ocrEdtCreate(&fib0, templateGuid, 2, paramv, 1, &depv, EDT_PROP_NONE,
                     NULL_GUID, NULL);
        ocrEdtTemplateDestroy(templateGuid);
    }

    PRINTF("r%d In fibEdt(%u) -- spawned first sub-part EDT GUID 0x%llx\n", my_ID, n, fib0);
    /* then do the exact same thing for n-2 */
    ocrDbCreate(&fibArg[1], (void**)&ptr, sizeof(u32), DB_PROP_NONE, NULL_GUID, NO_ALLOC);
    PRINTF("r%d In fibEdt(%u) -- created arg DB GUID 0x%llx\n", my_ID, n, fibArg[1]);
    *((u32*)ptr) = n-2;
    {
        u64 paramv[] = {(u64)fibDone[1], my_ID};
        ocrGuid_t depv = fibArg[1];

        ocrGuid_t templateGuid;
        ocrEdtTemplateCreate(&templateGuid, fibEdt, 2, 1);
        ocrEdtCreate(&fib1, templateGuid, 2, paramv, 1, &depv, EDT_PROP_NONE,
                     NULL_GUID, NULL);
        ocrEdtTemplateDestroy(templateGuid);
    }
    PRINTF("r%d In fibEdt(%u) -- spawned first sub-part EDT GUID 0x%llx\n", my_ID, n, fib1);

    PRINTF("r%d Returning from fibEdt(%u)\n", my_ID, n);
    return NULL_GUID;

}