Skip to content
Snippets Groups Projects
Commit c16f8fe6 authored by kotsifa2's avatar kotsifa2
Browse files

dfrg2llvm_nvptx pass provides information about the kernel

name, local and global sizes.
parent ce28d8b3
No related branches found
No related tags found
No related merge requests found
......@@ -72,6 +72,12 @@ namespace {
Module &KernelM;
BuildDFG &DFG;
DFNode * KernelLaunchNode;
struct { Function * KF;
unsigned gridDim;
unsigned blockDim;
std::vector<Value*> localWGSize;
std::vector<Value*> globalWGSize;
} kernel;
// Map from Old function associated with DFNode to new cloned function with
// extra index and dimension arguments. This map also serves to find out if
......@@ -614,8 +620,10 @@ namespace {
insertRuntimeCalls(N, getKernelsModuleName(M), "matrixMul");
} else {
DEBUG(errs() << "Found intermediate node. Generating device code.\n");
//TODO
DEBUG(errs() << "Found intermediate node. Getting size parameters.\n");
//TODO : Check that the arguments order of root to intermediate matches
// the intermediate to leaf.
}
}
......@@ -633,10 +641,34 @@ namespace {
int pLevel = PNode->getLevel();
int pReplFactor = PNode->getNumOfDim();
if (!pLevel || !pReplFactor)
if (!pLevel || !pReplFactor) {
KernelLaunchNode = PNode;
else
// TODO: Find a better way of choosing parameters
kernel.gridDim = N->getNumOfDim();
kernel.blockDim = N->getNumOfDim();
kernel.globalWGSize = N->getDimLimits();
IntegerType* IntTy = Type::getInt32Ty(KernelM.getContext());
// TODO: How to choose the div factor;
ConstantInt* divFactor = ConstantInt::getSigned(IntTy, (int64_t) 16);
std::vector<Value*> tmp(kernel.gridDim, divFactor);
for (unsigned i = 0; i < kernel.gridDim; i++) {
BinaryOperator* SDivInst = BinaryOperator::CreateSDiv(kernel.globalWGSize[i],tmp[i]);
kernel.localWGSize.push_back(SDivInst);
}
}
else {
KernelLaunchNode = PNode->getParent();
kernel.gridDim = PNode->getNumOfDim();
kernel.blockDim = N->getNumOfDim();
// TODO: Handle different number of dimensions
assert((kernel.gridDim == kernel.blockDim) && "Dimension number must match");
std::vector<Value*> numOfBlocks = PNode->getDimLimits();
kernel.localWGSize = N->getDimLimits();
for (unsigned i = 0; i < kernel.gridDim; i++) {
BinaryOperator* MulInst = BinaryOperator::CreateMul(kernel.localWGSize[i],numOfBlocks[i]);
kernel.globalWGSize.push_back(MulInst);
}
}
std::vector<IntrinsicInst *> IItoRemove;
BuildDFG::HandleToDFNode Leaf_HandleToDFNodeMap;
......@@ -890,6 +922,7 @@ namespace {
(*ri)->eraseFromParent();
addCLMetadata(F_nvptx);
kernel.KF = F_nvptx;
DEBUG(errs() << KernelM);
return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment