Commit 2979d418 authored by BRAMAS Berenger's avatar BRAMAS Berenger

prepare for more starpu wrappers

parent 46188592
......@@ -68,13 +68,15 @@ protected:
typedef FStarPUCpuWrapper<CellContainerClass, CellClass, KernelClass, ParticleGroupClass, ParticleContainerClass> StarPUCpuWrapperClass;
StarPUCpuWrapperClass cpuWrapper;
StarPUCpuWrapperClass* wrapperptr;
FStarPUPtrInterface wrappers;
FStarPUPtrInterface* wrapperptr;
public:
FGroupTaskStarPUAlgorithm(OctreeClass*const inTree, KernelClass* inKernels, const int inMaxThreads = -1)
: MaxThreads(inMaxThreads), tree(inTree),
handles_up(nullptr), handles_down(nullptr),
cpuWrapper(tree->getHeight()), wrapperptr(&cpuWrapper){
cpuWrapper(tree->getHeight()), wrapperptr(&wrappers){
FAssertLF(tree, "tree cannot be null");
FAssertLF(inKernels, "kernels cannot be null");
FAssertLF(MaxThreads <= STARPU_MAXCPUS, "number of threads to high");
......@@ -91,6 +93,8 @@ public:
cpuWrapper.initKernel(starpu_worker_get_id(), inKernels);
starpu_pthread_mutex_unlock(&initMutex);
});
wrappers.set(FSTARPU_CPU_IDX, &cpuWrapper);
starpu_pthread_mutex_destroy(&initMutex);
starpu_pause();
......@@ -456,7 +460,7 @@ protected:
for(int idxGroup = 0 ; idxGroup < tree->getNbParticleGroup() ; ++idxGroup){
starpu_insert_task(&p2m_cl,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_RW, handles_up[tree->getHeight()-1][idxGroup],
STARPU_R, handles_up[tree->getHeight()][idxGroup],
0);
......@@ -508,7 +512,7 @@ protected:
char *arg_buffer;
size_t arg_buffer_size;
starpu_codelet_pack_args((void**)&arg_buffer, &arg_buffer_size,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_VALUE, &nbSubCellGroups, sizeof(nbSubCellGroups),
STARPU_VALUE, &idxLevel, sizeof(idxLevel),
0);
......@@ -531,7 +535,7 @@ protected:
FLOG( timerInBlock.tic() );
for(int idxGroup = 0 ; idxGroup < tree->getNbCellGroupAtLevel(idxLevel) ; ++idxGroup){
starpu_insert_task(&m2l_cl_in,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_VALUE, &idxLevel, sizeof(idxLevel),
(STARPU_RW|STARPU_COMMUTE), handles_down[idxLevel][idxGroup],
STARPU_R, handles_up[idxLevel][idxGroup],
......@@ -546,7 +550,7 @@ protected:
const std::vector<OutOfBlockInteraction>* outsideInteractions = &externalInteractionsAllLevel[idxLevel][idxGroup][idxInteraction].interactions;
starpu_insert_task(&m2l_cl_inout,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_VALUE, &idxLevel, sizeof(idxLevel),
STARPU_VALUE, &outsideInteractions, sizeof(outsideInteractions),
(STARPU_RW|STARPU_COMMUTE), handles_down[idxLevel][idxGroup],
......@@ -604,7 +608,7 @@ protected:
char *arg_buffer;
size_t arg_buffer_size;
starpu_codelet_pack_args((void**)&arg_buffer, &arg_buffer_size,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_VALUE, &nbSubCellGroups, sizeof(nbSubCellGroups),
STARPU_VALUE, &idxLevel, sizeof(idxLevel),
0);
......@@ -627,7 +631,7 @@ protected:
FLOG( timerInBlock.tic() );
for(int idxGroup = 0 ; idxGroup < tree->getNbParticleGroup() ; ++idxGroup){
starpu_insert_task(&p2p_cl_in,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
(STARPU_RW|STARPU_COMMUTE), handles_down[tree->getHeight()][idxGroup],
0);
}
......@@ -638,7 +642,7 @@ protected:
const int interactionid = externalInteractionsLeafLevel[idxGroup][idxInteraction].otherBlockId;
const std::vector<OutOfBlockInteraction>* outsideInteractions = &externalInteractionsLeafLevel[idxGroup][idxInteraction].interactions;
starpu_insert_task(&p2p_cl_inout,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_VALUE, &outsideInteractions, sizeof(outsideInteractions),
(STARPU_RW|STARPU_COMMUTE), handles_down[tree->getHeight()][idxGroup],
(STARPU_RW|STARPU_COMMUTE), handles_down[tree->getHeight()][interactionid],
......@@ -660,7 +664,7 @@ protected:
for(int idxGroup = 0 ; idxGroup < tree->getNbParticleGroup() ; ++idxGroup){
starpu_insert_task(&l2p_cl,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_R, handles_down[tree->getHeight()-1][idxGroup],
(STARPU_RW|STARPU_COMMUTE), handles_down[tree->getHeight()][idxGroup],
0);
......
......@@ -83,13 +83,15 @@ protected:
typedef FStarPUCpuWrapper<CellContainerClass, CellClass, KernelClass, ParticleGroupClass, ParticleContainerClass> StarPUCpuWrapperClass;
StarPUCpuWrapperClass cpuWrapper;
StarPUCpuWrapperClass* wrapperptr;
FStarPUPtrInterface wrappers;
FStarPUPtrInterface* wrapperptr;
public:
FGroupTaskStarPUMpiAlgorithm(const FMpi::FComm& inComm, OctreeClass*const inTree, KernelClass* inKernels, const int inMaxThreads = -1)
: comm(inComm), MaxThreads(inMaxThreads), tree(inTree),
handles_up(nullptr), handles_down(nullptr),
cpuWrapper(tree->getHeight()), wrapperptr(&cpuWrapper){
cpuWrapper(tree->getHeight()), wrapperptr(&wrappers){
FAssertLF(tree, "tree cannot be null");
FAssertLF(inKernels, "kernels cannot be null");
FAssertLF(MaxThreads <= STARPU_MAXCPUS, "number of threads to high");
......@@ -107,6 +109,8 @@ public:
cpuWrapper.initKernel(starpu_worker_get_id(), inKernels);
starpu_pthread_mutex_unlock(&initMutex);
});
wrappers.set(FSTARPU_CPU_IDX, &cpuWrapper);
starpu_pthread_mutex_destroy(&initMutex);
starpu_pause();
......@@ -971,7 +975,7 @@ protected:
for(int idxGroup = 0 ; idxGroup < tree->getNbParticleGroup() ; ++idxGroup){
starpu_insert_task(&p2m_cl,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_RW, handles_up[tree->getHeight()-1][idxGroup],
STARPU_R, handles_up[tree->getHeight()][idxGroup],
0);
......@@ -1021,7 +1025,7 @@ protected:
char *arg_buffer;
size_t arg_buffer_size;
starpu_codelet_pack_args((void**)&arg_buffer, &arg_buffer_size,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_VALUE, &nbSubCellGroups, sizeof(nbSubCellGroups),
STARPU_VALUE, &idxLevel, sizeof(idxLevel),
0);
......@@ -1086,7 +1090,7 @@ protected:
char *arg_buffer;
size_t arg_buffer_size;
starpu_codelet_pack_args((void**)&arg_buffer, &arg_buffer_size,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_VALUE, &nbSubCellGroups, sizeof(nbSubCellGroups),
STARPU_VALUE, &idxLevel, sizeof(idxLevel),
0);
......@@ -1143,7 +1147,7 @@ protected:
const std::vector<OutOfBlockInteraction>* outsideInteractions = &externalInteractionsAllLevelMpi[idxLevel][idxGroup][idxInteraction].interactions;
starpu_insert_task(&m2l_cl_inout_mpi,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_VALUE, &idxLevel, sizeof(idxLevel),
STARPU_VALUE, &outsideInteractions, sizeof(outsideInteractions),
(STARPU_RW|STARPU_COMMUTE), handles_down[idxLevel][idxGroup],
......@@ -1166,7 +1170,7 @@ protected:
FLOG( timerInBlock.tic() );
for(int idxGroup = 0 ; idxGroup < tree->getNbCellGroupAtLevel(idxLevel) ; ++idxGroup){
starpu_insert_task(&m2l_cl_in,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_VALUE, &idxLevel, sizeof(idxLevel),
(STARPU_RW|STARPU_COMMUTE), handles_down[idxLevel][idxGroup],
STARPU_R, handles_up[idxLevel][idxGroup],
......@@ -1181,7 +1185,7 @@ protected:
const std::vector<OutOfBlockInteraction>* outsideInteractions = &externalInteractionsAllLevel[idxLevel][idxGroup][idxInteraction].interactions;
starpu_insert_task(&m2l_cl_inout,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_VALUE, &idxLevel, sizeof(idxLevel),
STARPU_VALUE, &outsideInteractions, sizeof(outsideInteractions),
(STARPU_RW|STARPU_COMMUTE), handles_down[idxLevel][idxGroup],
......@@ -1304,7 +1308,7 @@ protected:
char *arg_buffer;
size_t arg_buffer_size;
starpu_codelet_pack_args((void**)&arg_buffer, &arg_buffer_size,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_VALUE, &nbSubCellGroups, sizeof(nbSubCellGroups),
STARPU_VALUE, &idxLevel, sizeof(idxLevel),
0);
......@@ -1353,7 +1357,7 @@ protected:
char *arg_buffer;
size_t arg_buffer_size;
starpu_codelet_pack_args((void**)&arg_buffer, &arg_buffer_size,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_VALUE, &nbSubCellGroups, sizeof(nbSubCellGroups),
STARPU_VALUE, &idxLevel, sizeof(idxLevel),
0);
......@@ -1376,7 +1380,7 @@ protected:
const int interactionid = externalInteractionsLeafLevelMpi[idxGroup][idxInteraction].otherBlockId;
const std::vector<OutOfBlockInteraction>* outsideInteractions = &externalInteractionsLeafLevelMpi[idxGroup][idxInteraction].interactions;
starpu_insert_task(&p2p_cl_inout_mpi,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_VALUE, &outsideInteractions, sizeof(outsideInteractions),
(STARPU_RW|STARPU_COMMUTE), handles_down[tree->getHeight()][idxGroup],
STARPU_R, remoteParticleGroupss[interactionid].handle,
......@@ -1398,7 +1402,7 @@ protected:
FLOG( timerInBlock.tic() );
for(int idxGroup = 0 ; idxGroup < tree->getNbParticleGroup() ; ++idxGroup){
starpu_insert_task(&p2p_cl_in,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
(STARPU_RW|STARPU_COMMUTE), handles_down[tree->getHeight()][idxGroup],
0);
}
......@@ -1409,7 +1413,7 @@ protected:
const int interactionid = externalInteractionsLeafLevel[idxGroup][idxInteraction].otherBlockId;
const std::vector<OutOfBlockInteraction>* outsideInteractions = &externalInteractionsLeafLevel[idxGroup][idxInteraction].interactions;
starpu_insert_task(&p2p_cl_inout,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_VALUE, &outsideInteractions, sizeof(outsideInteractions),
(STARPU_RW|STARPU_COMMUTE), handles_down[tree->getHeight()][idxGroup],
(STARPU_RW|STARPU_COMMUTE), handles_down[tree->getHeight()][interactionid],
......@@ -1432,7 +1436,7 @@ protected:
for(int idxGroup = 0 ; idxGroup < tree->getNbParticleGroup() ; ++idxGroup){
starpu_insert_task(&l2p_cl,
STARPU_VALUE, &wrapperptr, sizeof(StarPUCpuWrapperClass*),
STARPU_VALUE, &wrapperptr, sizeof(wrapperptr),
STARPU_R, handles_down[tree->getHeight()-1][idxGroup],
(STARPU_RW|STARPU_COMMUTE), handles_down[tree->getHeight()][idxGroup],
0);
......
......@@ -31,6 +31,7 @@ extern "C"{
}
#endif
#include "FStarPUUtils.hpp"
template <class CellContainerClass, class CellClass, class KernelClass,
class ParticleGroupClass, class ParticleContainerClass>
......@@ -80,9 +81,9 @@ public:
ParticleGroupClass containers((unsigned char*)STARPU_VARIABLE_GET_PTR(buffers[1]),
STARPU_VARIABLE_GET_ELEMSIZE(buffers[1]));
ThisClass* worker = nullptr;
FStarPUPtrInterface* worker = nullptr;
starpu_codelet_unpack_args(cl_arg, &worker);
worker->bottomPassPerform(&leafCells, &containers);
worker->get<ThisClass>(FSTARPU_CPU_IDX)->bottomPassPerform(&leafCells, &containers);
}
void bottomPassPerform(CellContainerClass* leafCells, ParticleGroupClass* containers){
......@@ -109,7 +110,7 @@ public:
CellContainerClass currentCells((unsigned char*)STARPU_VARIABLE_GET_PTR(buffers[0]),
STARPU_VARIABLE_GET_ELEMSIZE(buffers[0]));
ThisClass* worker = nullptr;
FStarPUPtrInterface* worker = nullptr;
int nbSubCellGroups = 0;
int idxLevel = 0;
starpu_codelet_unpack_args(cl_arg, &worker, &nbSubCellGroups, &idxLevel);
......@@ -121,7 +122,7 @@ public:
STARPU_VARIABLE_GET_ELEMSIZE(buffers[idxSubGroup+1]));
}
worker->upwardPassPerform(&currentCells, subCellGroups, nbSubCellGroups, idxLevel);
worker->get<ThisClass>(FSTARPU_CPU_IDX)->upwardPassPerform(&currentCells, subCellGroups, nbSubCellGroups, idxLevel);
for(int idxSubGroup = 0; idxSubGroup < nbSubCellGroups ; ++idxSubGroup){
delete subCellGroups[idxSubGroup];
......@@ -172,12 +173,12 @@ public:
CellContainerClass externalCells((unsigned char*)STARPU_VARIABLE_GET_PTR(buffers[1]),
STARPU_VARIABLE_GET_ELEMSIZE(buffers[1]));
ThisClass* worker = nullptr;
FStarPUPtrInterface* worker = nullptr;
int idxLevel = 0;
const std::vector<OutOfBlockInteraction>* outsideInteractions;
starpu_codelet_unpack_args(cl_arg, &worker, &idxLevel, &outsideInteractions);
worker->transferInoutPassPerformMpi(&currentCells, &externalCells, idxLevel, outsideInteractions);
worker->get<ThisClass>(FSTARPU_CPU_IDX)->transferInoutPassPerformMpi(&currentCells, &externalCells, idxLevel, outsideInteractions);
}
......@@ -213,11 +214,11 @@ public:
CellContainerClass currentCells((unsigned char*)STARPU_VARIABLE_GET_PTR(buffers[0]),
STARPU_VARIABLE_GET_ELEMSIZE(buffers[0]));
ThisClass* worker = nullptr;
FStarPUPtrInterface* worker = nullptr;
int idxLevel = 0;
starpu_codelet_unpack_args(cl_arg, &worker, &idxLevel);
worker->transferInPassPerform(&currentCells, idxLevel);
worker->get<ThisClass>(FSTARPU_CPU_IDX)->transferInPassPerform(&currentCells, idxLevel);
}
void transferInPassPerform(CellContainerClass*const currentCells, const int idxLevel){
......@@ -264,12 +265,12 @@ public:
CellContainerClass externalCells((unsigned char*)STARPU_VARIABLE_GET_PTR(buffers[1]),
STARPU_VARIABLE_GET_ELEMSIZE(buffers[1]));
ThisClass* worker = nullptr;
FStarPUPtrInterface* worker = nullptr;
int idxLevel = 0;
const std::vector<OutOfBlockInteraction>* outsideInteractions;
starpu_codelet_unpack_args(cl_arg, &worker, &idxLevel, &outsideInteractions);
worker->transferInoutPassPerform(&currentCells, &externalCells, idxLevel, outsideInteractions);
worker->get<ThisClass>(FSTARPU_CPU_IDX)->transferInoutPassPerform(&currentCells, &externalCells, idxLevel, outsideInteractions);
}
......@@ -307,7 +308,7 @@ public:
CellContainerClass currentCells((unsigned char*)STARPU_VARIABLE_GET_PTR(buffers[0]),
STARPU_VARIABLE_GET_ELEMSIZE(buffers[0]));
ThisClass* worker = nullptr;
FStarPUPtrInterface* worker = nullptr;
int nbSubCellGroups = 0;
int idxLevel = 0;
starpu_codelet_unpack_args(cl_arg, &worker, &nbSubCellGroups, &idxLevel);
......@@ -319,7 +320,7 @@ public:
STARPU_VARIABLE_GET_ELEMSIZE(buffers[idxSubGroup+1]));
}
worker->downardPassPerform(&currentCells, subCellGroups, nbSubCellGroups, idxLevel);
worker->get<ThisClass>(FSTARPU_CPU_IDX)->downardPassPerform(&currentCells, subCellGroups, nbSubCellGroups, idxLevel);
for(int idxSubGroup = 0; idxSubGroup < nbSubCellGroups ; ++idxSubGroup){
delete subCellGroups[idxSubGroup];
......@@ -370,11 +371,11 @@ public:
ParticleGroupClass externalContainers((unsigned char*)STARPU_VARIABLE_GET_PTR(buffers[1]),
STARPU_VARIABLE_GET_ELEMSIZE(buffers[1]));
ThisClass* worker = nullptr;
FStarPUPtrInterface* worker = nullptr;
const std::vector<OutOfBlockInteraction>* outsideInteractions = nullptr;
starpu_codelet_unpack_args(cl_arg, &worker, &outsideInteractions);
worker->directInoutPassPerform(&containers, &externalContainers, outsideInteractions);
worker->get<ThisClass>(FSTARPU_CPU_IDX)->directInoutPassPerform(&containers, &externalContainers, outsideInteractions);
}
void directInoutPassPerformMpi(ParticleGroupClass* containers, ParticleGroupClass* containersOther,
......@@ -402,10 +403,9 @@ public:
ParticleGroupClass containers((unsigned char*)STARPU_VARIABLE_GET_PTR(buffers[0]),
STARPU_VARIABLE_GET_ELEMSIZE(buffers[0]));
ThisClass* worker = nullptr;
FStarPUPtrInterface* worker = nullptr;
starpu_codelet_unpack_args(cl_arg, &worker);
worker->directInPassPerform(&containers);
worker->get<ThisClass>(FSTARPU_CPU_IDX)->directInPassPerform(&containers);
}
void directInPassPerform(ParticleGroupClass* containers){
......@@ -448,11 +448,11 @@ public:
ParticleGroupClass externalContainers((unsigned char*)STARPU_VARIABLE_GET_PTR(buffers[1]),
STARPU_VARIABLE_GET_ELEMSIZE(buffers[1]));
ThisClass* worker = nullptr;
FStarPUPtrInterface* worker = nullptr;
const std::vector<OutOfBlockInteraction>* outsideInteractions = nullptr;
starpu_codelet_unpack_args(cl_arg, &worker, &outsideInteractions);
worker->directInoutPassPerform(&containers, &externalContainers, outsideInteractions);
worker->get<ThisClass>(FSTARPU_CPU_IDX)->directInoutPassPerform(&containers, &externalContainers, outsideInteractions);
}
void directInoutPassPerform(ParticleGroupClass* containers, ParticleGroupClass* containersOther,
......@@ -486,9 +486,9 @@ public:
ParticleGroupClass containers((unsigned char*)STARPU_VARIABLE_GET_PTR(buffers[1]),
STARPU_VARIABLE_GET_ELEMSIZE(buffers[1]));
ThisClass* worker = nullptr;
FStarPUPtrInterface* worker = nullptr;
starpu_codelet_unpack_args(cl_arg, &worker);
worker->mergePassPerform(&leafCells, &containers);
worker->get<ThisClass>(FSTARPU_CPU_IDX)->mergePassPerform(&leafCells, &containers);
}
void mergePassPerform(CellContainerClass* leafCells, ParticleGroupClass* containers){
......
......@@ -16,6 +16,21 @@ extern "C"{
/////////////////////////////////////////////////////
enum FStarPUTypes{
#ifdef STARPU_USE_CPU
FSTARPU_CPU_IDX = 0,
#endif
#ifdef STARPU_USE_CUDA
FSTARPU_CUDA_IDX = 1,
#endif
#ifdef STARPU_USE_OPENCL
FSTARPU_OPENCL_IDX = 2,
#endif
FSTARPU_NB_TYPES = 3
};
/////////////////////////////////////////////////////
#include <functional>
class FStarPUUtils{
......@@ -37,5 +52,28 @@ public:
#define STARPU_COMMUTE STARPU_NONE
#endif
/////////////////////////////////////////////////////
class FStarPUPtrInterface {
void* ptrs[FSTARPU_NB_TYPES];
public:
FStarPUPtrInterface(){
memset(ptrs, 0, sizeof(void*)*FSTARPU_NB_TYPES);
}
void set(const FStarPUTypes idx, void* inPtr){
ptrs[idx] = inPtr;
}
template <class PtrClass>
PtrClass* get(const FStarPUTypes idx){
return reinterpret_cast<PtrClass*>(ptrs[idx]);
}
};
/////////////////////////////////////////////////////
#endif // FSTARPUUTILS_HPP
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment