Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[FIX] Loop peeling

  • Loading branch information...
commit 426de036c51933f3719b9d8b448520b57bbd43c3 1 parent 5f6727c
@naoyam authored
View
2  translator/cuda_runtime_builder.cc
@@ -33,7 +33,7 @@ SgExpression *CUDARuntimeBuilder::BuildGridRefInRunKernel(
}
}
LOG_ERROR() << "No grid parameter found.\n";
- PSAbort(1);
+ PSAssert(0);
return NULL;
}
View
2  translator/optimizer/kernel_inlining.cc
@@ -92,7 +92,7 @@ void kernel_inlining(
PSAbort(1);
}
// Fix the grid attributes
- FixGridAttributes(proj, tx);
+ FixGridAttributes(proj);
}
}
View
25 translator/optimizer/loop_peeling.cc
@@ -7,6 +7,7 @@
// Author: Naoya Maruyama (naoya@matsulab.is.titech.ac.jp)
#include "translator/optimizer/optimization_passes.h"
+#include "translator/optimizer/optimization_common.h"
#include "translator/rose_util.h"
#include "translator/runtime_builder.h"
#include "translator/translation_util.h"
@@ -139,6 +140,7 @@ static void PeelFirstIterations(SgForStatement *loop,
LOG_DEBUG() << "Copying of original loop done.\n";
RenameLastStatementLabel(peeled_iterations);
LOG_DEBUG() << "Label renaming done\n";
+ FixGridAttributes(peeled_iterations);
// Modify the termination condition to i < peel_size
SgStatement *original_cond = peeled_iterations->get_test();
@@ -189,6 +191,13 @@ static void PeelFirstIterations(SgForStatement *loop,
return;
}
+static SgExpression *FindGridRefInLoop(SgInitializedName *grid) {
+ SgAssignInitializer *init = isSgAssignInitializer(grid->get_initptr());
+ PSAssert(init);
+ SgExpression *gr = init->get_operand();
+ LOG_DEBUG() << "Grid var init: " << gr->unparseToString() << "\n";
+ return gr;
+}
static void PeelLastIterations(SgForStatement *loop,
int peel_size,
@@ -203,24 +212,25 @@ static void PeelLastIterations(SgForStatement *loop,
PSAssert(loop_var);
SgForStatement *peeled_iterations =
isSgForStatement(si::copyStatement(loop));
- LOG_DEBUG() << "Copying of original loop done.\n";
+ LOG_DEBUG() << "Copying of original loop done.\n";
RunKernelLoopAttribute *peel_iter_attr =
rose_util::GetASTAttribute<RunKernelLoopAttribute>(
peeled_iterations);
- RenameLastStatementLabel(peeled_iterations);
+ RenameLastStatementLabel(peeled_iterations);
+
+ FixGridAttributes(peeled_iterations);
// Modify the termination condition of the original loop
SgStatement *original_cond = loop->get_test();
// loop_end is min(original_end, g->dim - peel_size)
SgExpression *original_loop_end = loop_attr->end();
+ SgExpression *grid_ref_in_loop =
+ si::copyExpression(FindGridRefInLoop(peel_grid));
SgExpression *grid_end_offset =
sb::buildSubtractOp(
- builder->BuildGridDim(
- builder->BuildGridRefInRunKernel(
- peel_grid,
- si::getEnclosingFunctionDeclaration(loop)),
- loop_attr->dim()),
+ builder->BuildGridDim(grid_ref_in_loop,
+ loop_attr->dim()),
sb::buildIntVal(peel_size));
SgExpression *loop_end = rose_util::BuildMin(
si::copyExpression(original_loop_end), grid_end_offset);
@@ -323,6 +333,7 @@ void loop_peeling(
PeelLoop(isSgFunctionDeclaration(*it), loop, builder);
}
+ post_process(proj, tx, __FUNCTION__);
}
View
5 translator/optimizer/optimization_common.cc
@@ -91,10 +91,9 @@ void FixGridGetAttribute(SgExpression *get_exp) {
}
void FixGridAttributes(
- SgProject *proj,
- physis::translator::TranslationContext *tx) {
+ SgNode *node) {
Rose_STL_Container<SgNode *> exps =
- NodeQuery::querySubTree(proj, V_SgExpression);
+ NodeQuery::querySubTree(node, V_SgExpression);
FOREACH(it, exps.begin(), exps.end()) {
SgExpression *exp = isSgExpression(*it);
PSAssert(exp);
View
4 translator/optimizer/optimization_common.h
@@ -22,8 +22,8 @@ extern void FixGridGetAttribute(SgExpression *get_exp);
//! Fix references to the offset expression.
extern void FixGridAttributes(
- SgProject *proj,
- physis::translator::TranslationContext *tx);
+ SgNode *node);
+
} // namespace optimizer
} // namespace translator
Please sign in to comment.
Something went wrong with that request. Please try again.