Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanradanov committed Sep 6, 2023
1 parent 1fa4d42 commit 1da7e62
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 26 deletions.
8 changes: 3 additions & 5 deletions lib/polygeist/ExecutionEngine/PGORuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
// PGO functions which should know whether the code in the alternatives op is
// GPU code - we can add an attrib to the alternatives op for that

#include <cstdlib>
#include <ctime>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <map>
#include <vector>
#include <mutex>
#include <cstdlib>
#include <numeric>
#include <vector>

extern "C" int32_t mgpurtDeviceSynchronizeErr(void);

Expand All @@ -31,9 +31,7 @@ class PGOState {

struct Logger {
std::map<std::string, std::vector<double>> timings;
~Logger() {
PGOState::writeResults();
}
~Logger() { PGOState::writeResults(); }
};

inline static int alternative;
Expand Down
5 changes: 2 additions & 3 deletions lib/polygeist/Ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ LogicalResult
GetDeviceGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
// Verify that the result type is same as the type of the referenced
// memref.global op.
auto global =
symbolTable.lookupNearestSymbolFrom<memref::GlobalOp>(*this, getNameAttr());
auto global = symbolTable.lookupNearestSymbolFrom<memref::GlobalOp>(
*this, getNameAttr());
if (!global)
return emitOpError("'")
<< getName() << "' does not reference a valid global memref";
Expand All @@ -122,7 +122,6 @@ GetDeviceGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
return success();
}


//===----------------------------------------------------------------------===//
// GPUErrorOp
//===----------------------------------------------------------------------===//
Expand Down
26 changes: 15 additions & 11 deletions lib/polygeist/Passes/ConvertParallelToGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,8 @@ struct ConvertParallelToGPU1Pass
});
};

auto getBlockUnrollFactors = [&](uint64_t unrollFactor, unsigned gridDims) {
auto getBlockUnrollFactors = [&](uint64_t unrollFactor,
unsigned gridDims) {
std::vector<uint64_t> divisors;
for (unsigned i = 2; unrollFactor != 1; ++i) {
while (unrollFactor % i == 0) {
Expand All @@ -1745,7 +1746,8 @@ struct ConvertParallelToGPU1Pass
llvm::errs() << "\n";
return unrollFactors;
};
auto getThreadUnrollFactors = [&](unsigned unrollFactor, unsigned blockDims) {
auto getThreadUnrollFactors = [&](unsigned unrollFactor,
unsigned blockDims) {
unsigned powsOf2 = std::log2(unrollFactor);
unsigned initial = std::pow(2, powsOf2 / blockDims);
unsigned currentFactor = 1;
Expand Down Expand Up @@ -1802,9 +1804,11 @@ struct ConvertParallelToGPU1Pass
int gridDims = ubs.size();
assert(gridDims >= 1 && gridDims <= 3);

SmallVector<uint64_t, 3> blockUnrollFactors = convertToFactors(coarsenBlocks, gridDims, getBlockUnrollFactors);
SmallVector<uint64_t, 3> blockUnrollFactors =
convertToFactors(coarsenBlocks, gridDims, getBlockUnrollFactors);

if (blockUnrollFactors != noCoarsening && isValid(blockUnrollFactors)) {
if (blockUnrollFactors != noCoarsening &&
isValid(blockUnrollFactors)) {
if (polygeist::scfParallelUnrollByFactors(
gridPop, ArrayRef<uint64_t>(blockUnrollFactors),
/* generateEpilogueLoop */ true,
Expand All @@ -1819,9 +1823,11 @@ struct ConvertParallelToGPU1Pass
int blockDims = ubs.size();
assert(blockDims >= 1 && blockDims <= 3);

SmallVector<uint64_t, 3> threadUnrollFactors = convertToFactors(coarsenThreads, blockDims, getThreadUnrollFactors);
SmallVector<uint64_t, 3> threadUnrollFactors = convertToFactors(
coarsenThreads, blockDims, getThreadUnrollFactors);

if (threadUnrollFactors != noCoarsening && isValid(threadUnrollFactors)) {
if (threadUnrollFactors != noCoarsening &&
isValid(threadUnrollFactors)) {
// TODO We kind of assume that the upper bounds will be divisible by
// the factors and in that case this will succeed if the upper
// bounds are dynamic - we need to insert runtime checks and
Expand Down Expand Up @@ -2169,16 +2175,14 @@ struct ConvertParallelToGPU2Pass
void runOnOperation() override {

std::vector<polygeist::GetDeviceGlobalOp> gdgops;
getOperation()->walk([&](polygeist::GetDeviceGlobalOp gdgo) {
gdgops.push_back(gdgo);
});
getOperation()->walk(
[&](polygeist::GetDeviceGlobalOp gdgo) { gdgops.push_back(gdgo); });
for (auto gdgo : gdgops) {
auto builder = OpBuilder(gdgo);
auto ggo = builder.create<memref::GetGlobalOp>(
gdgo->getLoc(), gdgo.getType(), gdgo.getNameAttr());
gdgo->getLoc(), gdgo.getType(), gdgo.getNameAttr());
gdgo->replaceAllUsesWith(ggo);
gdgo->erase();

}

RewritePatternSet patterns(&getContext());
Expand Down
3 changes: 2 additions & 1 deletion lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,8 @@ struct LowerGPUAlternativesOp
return failure();

Location loc = gao->getLoc();
std::string locStr = gao->getAttrOfType<StringAttr>("polygeist.altop.id").data();
std::string locStr =
gao->getAttrOfType<StringAttr>("polygeist.altop.id").data();

auto descs = gao->getAttrOfType<ArrayAttr>("alternatives.descs");

Expand Down
5 changes: 3 additions & 2 deletions lib/polygeist/Passes/LowerAlternatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#include "mlir/Transforms/RegionUtils.h"
#include "polygeist/Passes/Passes.h"

#include <filesystem>
#include <fstream>
#include <limits>
#include <map>
#include <numeric>
#include <filesystem>

#include "polygeist/Ops.h"
#include "polygeist/Passes/Passes.h"
Expand Down Expand Up @@ -169,7 +169,8 @@ struct LowerAlternativesPass
for (char &c : locStr)
if (c == '/')
c = '+';
altOp->setAttr("polygeist.altop.id", StringAttr::get(&getContext(), locStr));
altOp->setAttr("polygeist.altop.id",
StringAttr::get(&getContext(), locStr));
});

if (PolygeistAlternativesMode == PAM_PGO_Opt) {
Expand Down
11 changes: 7 additions & 4 deletions lib/polygeist/Passes/ParallelLower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,16 +624,19 @@ void ParallelLower::runOnOperation() {

// If we are compiling for GPU
if (gpuKernelStructureMode != PGSM_Discard) {
// Tag device side get globals with an attribute so that CSE does not decide
// to reuse the host side get global for the device
// Tag device side get globals with an attribute so that CSE does not
// decide to reuse the host side get global for the device
std::vector<mlir::memref::GetGlobalOp> ggops;
container.walk([&](mlir::memref::GetGlobalOp getGlobalOp) {
ggops.push_back(getGlobalOp);
});
for (auto ggo : ggops) {
builder.setInsertionPoint(ggo);
builder.replaceOp(ggo, builder.create<polygeist::GetDeviceGlobalOp>(
ggo->getLoc(), ggo.getType(), ggo.getNameAttr())->getResults());
builder.replaceOp(
ggo, builder
.create<polygeist::GetDeviceGlobalOp>(
ggo->getLoc(), ggo.getType(), ggo.getNameAttr())
->getResults());
}
}

Expand Down

0 comments on commit 1da7e62

Please sign in to comment.