Skip to content

Commit

Permalink
fixes for mac (#1863)
Browse files Browse the repository at this point in the history
Template keyword for Mac clang compiler.

Signed-off-by: Alexandre Eichenberger <alexe@us.ibm.com>
  • Loading branch information
AlexandreEichenberger authored Nov 16, 2022
1 parent 14cb830 commit b1a99f2
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Conversion/ONNXToKrnl/ONNXToKrnlCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct OnnxToKrnlBuilder : public OnnxBuilder {
OnnxToKrnlBuilder(mlir::OpBuilder &b, mlir::Location loc)
: OnnxBuilder(b, loc) {}
OnnxToKrnlBuilder(DialectBuilder &db) : OnnxBuilder(db) {}
~OnnxToKrnlBuilder() {}
virtual ~OnnxToKrnlBuilder() {}

// Generate an 'onnx.reshape' operation on the 'input' tensor, the new shape
// is provided by 'shapeDims'.
Expand Down
8 changes: 6 additions & 2 deletions src/Dialect/Krnl/DialectBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ Value KrnlBuilder::vectorTypeCast(Value sourceMemref, int64_t vectorLen) const {
}

ValueRange KrnlBuilder::defineLoops(int64_t originalLoopNum) const {
return b().create<KrnlDefineLoopsOp>(loc(), originalLoopNum).getResults();
return b()
.template create<KrnlDefineLoopsOp>(loc(), originalLoopNum)
.getResults();
}

ValueRange KrnlBuilder::block(Value loop, int64_t blockSize) const {
Expand All @@ -119,7 +121,9 @@ void KrnlBuilder::permute(ValueRange loops, ArrayRef<int64_t> map) const {
}

ValueRange KrnlBuilder::getInductionVarValue(ValueRange loops) const {
return b().create<KrnlGetInductionVariableValueOp>(loc(), loops).getResults();
return b()
.template create<KrnlGetInductionVariableValueOp>(loc(), loops)
.getResults();
}

void KrnlBuilder::iterate(ValueRange originalLoops, ValueRange optimizedLoops,
Expand Down
4 changes: 2 additions & 2 deletions src/Dialect/Krnl/DialectBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct KrnlBuilder : public DialectBuilder {
KrnlBuilder(mlir::OpBuilder &b, mlir::Location loc)
: DialectBuilder(b, loc) {}
KrnlBuilder(const DialectBuilder &db) : DialectBuilder(db) {}
~KrnlBuilder() {}
virtual ~KrnlBuilder() {}

mlir::Value load(mlir::Value memref, mlir::ValueRange indices = {}) const;
// When ranks of offsets<indices, add offsets to the least significant dims.
Expand Down Expand Up @@ -176,7 +176,7 @@ struct IndexExprBuilderForKrnl : IndexExprBuilder {
IndexExprBuilderForKrnl(mlir::OpBuilder &b, mlir::Location loc)
: IndexExprBuilder(b, loc) {}
IndexExprBuilderForKrnl(const DialectBuilder &db) : IndexExprBuilder(db) {}
~IndexExprBuilderForKrnl() {}
virtual ~IndexExprBuilderForKrnl() {}

protected:
mlir::DenseElementsAttr getConst(mlir::Value value) final;
Expand Down
14 changes: 7 additions & 7 deletions src/Dialect/Mlir/DialectBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct DialectBuilder {
: builder(&b), location(loc) {}
DialectBuilder(const DialectBuilder &db)
: builder(db.builder), location(db.location) {}
~DialectBuilder() {}
virtual ~DialectBuilder() {}
DialectBuilder(DialectBuilder &&) = delete;
DialectBuilder &operator=(const DialectBuilder &) = delete;
DialectBuilder &&operator=(const DialectBuilder &&) = delete;
Expand Down Expand Up @@ -77,7 +77,7 @@ struct MathBuilder final : DialectBuilder {
MathBuilder(mlir::OpBuilder &b, mlir::Location loc)
: DialectBuilder(b, loc) {}
MathBuilder(const DialectBuilder &db) : DialectBuilder(db) {}
~MathBuilder() {}
virtual ~MathBuilder() {}

mlir::Value abs(mlir::Value val) const;

Expand Down Expand Up @@ -150,7 +150,7 @@ struct MemRefBuilder final : DialectBuilder {
MemRefBuilder(mlir::OpBuilder &b, mlir::Location loc)
: DialectBuilder(b, loc) {}
MemRefBuilder(const DialectBuilder &db) : DialectBuilder(db) {}
~MemRefBuilder() {}
virtual ~MemRefBuilder() {}

mlir::memref::AllocOp alloc(mlir::MemRefType type) const;
mlir::memref::AllocOp alloc(
Expand Down Expand Up @@ -191,7 +191,7 @@ struct SCFBuilder final : DialectBuilder {
SCFBuilder(mlir::Location loc) : DialectBuilder(loc) {}
SCFBuilder(mlir::OpBuilder &b, mlir::Location loc) : DialectBuilder(b, loc) {}
SCFBuilder(const DialectBuilder &db) : DialectBuilder(db) {}
~SCFBuilder() {}
virtual ~SCFBuilder() {}

/// Create an if then with optional else. Construct does not generate a result
/// (unlike some scf::if) and introduces the yields automatically.
Expand All @@ -215,7 +215,7 @@ struct VectorBuilder final : DialectBuilder {
VectorBuilder(mlir::OpBuilder &b, mlir::Location loc)
: DialectBuilder(b, loc) {}
VectorBuilder(const DialectBuilder &db) : DialectBuilder(db) {}
~VectorBuilder() {}
virtual ~VectorBuilder() {}

// Get the machine SIMD vector length for the given elementary type.
// This can help guide certain optimizations.
Expand Down Expand Up @@ -264,7 +264,7 @@ struct GenericAffineBuilder final : DialectBuilder {
GenericAffineBuilder(mlir::OpBuilder &b, mlir::Location loc)
: DialectBuilder(b, loc) {}
GenericAffineBuilder(const DialectBuilder &db) : DialectBuilder(db) {}
~GenericAffineBuilder() {}
virtual ~GenericAffineBuilder() {}

mlir::Value load(mlir::Value memref, mlir::ValueRange indices = {}) const;
// When ranks of offsets<indices, add offsets to the least significant dims.
Expand Down Expand Up @@ -332,7 +332,7 @@ struct LLVMBuilder final : DialectBuilder {
LLVMBuilder(mlir::OpBuilder &b, mlir::Location loc)
: DialectBuilder(b, loc) {}
LLVMBuilder(const DialectBuilder &db) : DialectBuilder(db) {}
~LLVMBuilder() {}
virtual ~LLVMBuilder() {}

// AddressOfOp
mlir::Value addressOf(mlir::LLVM::GlobalOp op) const;
Expand Down
21 changes: 13 additions & 8 deletions src/Dialect/Mlir/DialectBuilder.hpp.inc
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
//===---- DialectBuilder.hpp.inc - Helper functions for MLIR dialects -----===//
//
// Copyright 2019-2021 The IBM Research Authors.
// Copyright 2019-2022 The IBM Research Authors.
//
// =============================================================================
//
// This file contains helper functions for building MLIR operations.
//
// Note on usage of template keyword. Since the GenericAffineBuilder is
// templated, and we use templated functions (such as create<OP>), we must add
// the "template" keyword before the "create" function to indicate what is being
// templated.
//
//===----------------------------------------------------------------------===//

// Implementation of GenericAffineBuilder
template <class LOAD_OP, class STORE_OP>
mlir::Value GenericAffineBuilder<LOAD_OP, STORE_OP>::load(
mlir::Value memref, mlir::ValueRange indices) const {
return b().create<LOAD_OP>(loc(), memref, indices);
return b().template create<LOAD_OP>(loc(), memref, indices);
}

template <class LOAD_OP, class STORE_OP>
Expand All @@ -36,7 +41,7 @@ mlir::Value GenericAffineBuilder<LOAD_OP, STORE_OP>::loadIE(mlir::Value memref,
template <class LOAD_OP, class STORE_OP>
inline void GenericAffineBuilder<LOAD_OP, STORE_OP>::store(
mlir::Value val, mlir::Value memref, mlir::ValueRange indices) const {
b().create<STORE_OP>(loc(), val, memref, indices);
b().template create<STORE_OP>(loc(), val, memref, indices);
}

template <class LOAD_OP, class STORE_OP>
Expand Down Expand Up @@ -70,8 +75,8 @@ inline void GenericAffineBuilder<LOAD_OP, STORE_OP>::forIE(IndexExpr lb,
lb.getAffineMapAndOperands(lbMap, lbOperands);
ub.getAffineMapAndOperands(ubMap, ubOperands);
// Create affine for.
b().create<mlir::AffineForOp>(loc(), lbOperands, lbMap, ubOperands, ubMap,
step, mlir::ValueRange{},
b().template create<mlir::AffineForOp>(loc(), lbOperands, lbMap, ubOperands,
ubMap, step, mlir::ValueRange{},
[&](mlir::OpBuilder &b, mlir::Location loc, mlir::Value index,
mlir::ValueRange args) {
GenericAffineBuilder createAffine(b, loc);
Expand Down Expand Up @@ -120,8 +125,8 @@ inline void GenericAffineBuilder<LOAD_OP, STORE_OP>::ifThenElse(
scope.getNumDims(), scope.getNumSymbols(), affineCond, isEq);
llvm::SmallVector<mlir::Value, 8> dimAndSymbolList;
scope.getDimAndSymbolList(dimAndSymbolList);
auto ifOp =
b().create<mlir::AffineIfOp>(loc(), inset, dimAndSymbolList, true);
auto ifOp = b().template create<mlir::AffineIfOp>(
loc(), inset, dimAndSymbolList, true);
mlir::Block *thenBlock = ifOp.getThenBlock();
mlir::Block *elseBlock = ifOp.getElseBlock();
if (!allFalse) {
Expand All @@ -140,7 +145,7 @@ inline void GenericAffineBuilder<LOAD_OP, STORE_OP>::ifThenElse(

template <class LOAD_OP, class STORE_OP>
inline void GenericAffineBuilder<LOAD_OP, STORE_OP>::yield() const {
b().create<mlir::AffineYieldOp>(loc());
b().template create<mlir::AffineYieldOp>(loc());
}

// Support for multiple forIE loops.
Expand Down
2 changes: 1 addition & 1 deletion src/Dialect/Mlir/IndexExprBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct IndexExprBuilder : DialectBuilder {
IndexExprBuilder(mlir::OpBuilder &b, mlir::Location loc)
: DialectBuilder(b, loc) {}
IndexExprBuilder(const DialectBuilder &db) : DialectBuilder(db) {}
~IndexExprBuilder() {}
virtual ~IndexExprBuilder() {}

using IndexExprList = llvm::SmallVectorImpl<IndexExpr>;

Expand Down
4 changes: 2 additions & 2 deletions src/Dialect/ONNX/DialectBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct OnnxBuilder : onnx_mlir::DialectBuilder {
OnnxBuilder(mlir::OpBuilder &b, mlir::Location loc)
: DialectBuilder(b, loc) {}
OnnxBuilder(const DialectBuilder &db) : DialectBuilder(db) {}
~OnnxBuilder(){};
virtual ~OnnxBuilder(){};
// ONNXAddOp
mlir::Value add(mlir::Value A, mlir::Value B) const;

Expand Down Expand Up @@ -145,7 +145,7 @@ struct IndexExprBuilderForAnalysis : IndexExprBuilder {
: IndexExprBuilder(b, loc) {}
IndexExprBuilderForAnalysis(const DialectBuilder &db)
: IndexExprBuilder(db) {}
~IndexExprBuilderForAnalysis() {}
virtual ~IndexExprBuilderForAnalysis() {}

protected:
mlir::DenseElementsAttr getConst(mlir::Value value) final;
Expand Down
6 changes: 3 additions & 3 deletions test/modellib/ModelLib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class LSTMLibBuilder : public RNNModelLibBuilder {
const bool isDynamicB, const bool isNoneH = false,
const bool isNoneC = false, const bool isNoneP = false,
const int layout = 0);
~LSTMLibBuilder();
virtual ~LSTMLibBuilder();
bool build() final;
bool prepareInputs() final;
bool prepareInputs(float dataRangeLB, float dataRangeUB);
Expand All @@ -415,7 +415,7 @@ class GRULibBuilder : public RNNModelLibBuilder {
GRULibBuilder(const std::string &modelName, const int direction, const int S,
const int B, const int I, const int H, const int linearBeforeReset,
const bool isDynamicS, const bool isDynamicB, const int layout = 0);
~GRULibBuilder();
virtual ~GRULibBuilder();
bool build() final;
bool prepareInputs() final;
bool prepareInputs(float dataRangeLB, float dataRangeUB);
Expand All @@ -436,7 +436,7 @@ class RNNLibBuilder : public RNNModelLibBuilder {
RNNLibBuilder(const std::string &modelName, const int direction, const int S,
const int B, const int I, const int H, const bool isDynamicS,
const bool isDynamicB, const int layout = 0);
~RNNLibBuilder();
virtual ~RNNLibBuilder();
bool build() final;
bool prepareInputs() final;
bool prepareInputs(float dataRangeLB, float dataRangeUB);
Expand Down

0 comments on commit b1a99f2

Please sign in to comment.