From bf99a82832f84ccc1d526e8d50423ae85b699524 Mon Sep 17 00:00:00 2001 From: Sean Silva Date: Wed, 7 Oct 2020 17:12:52 -0700 Subject: [PATCH] [RefBackend] Rename Npcomprt dialect to Refbackrt. --- include/npcomp/Dialect/CMakeLists.txt | 2 +- .../npcomp/Dialect/Npcomprt/IR/CMakeLists.txt | 1 - .../{Npcomprt => Refbackrt}/CMakeLists.txt | 0 .../Dialect/Refbackrt/IR/CMakeLists.txt | 1 + .../IR/RefbackrtBase.td} | 28 +++---- .../IR/RefbackrtDialect.h} | 12 +-- .../IR/RefbackrtOps.h} | 8 +- .../IR/RefbackrtOps.td} | 44 +++++----- .../npcomp/RefBackend/JITHelpers/JITModule.h | 8 +- include/npcomp/RefBackend/Passes.td | 8 +- include/npcomp/RefBackend/RefBackend.h | 2 +- include/npcomp/RefBackend/Runtime/README.md | 2 +- include/npcomp/RefBackend/Runtime/Support.h | 4 +- include/npcomp/RefBackend/Runtime/UserAPI.h | 4 +- lib/Backend/RefJIT/PythonModule.cpp | 12 +-- lib/CMakeLists.txt | 2 +- lib/Dialect/CMakeLists.txt | 2 +- lib/Dialect/Npcomprt/IR/CMakeLists.txt | 17 ---- .../{Npcomprt => Refbackrt}/CMakeLists.txt | 0 lib/Dialect/Refbackrt/IR/CMakeLists.txt | 17 ++++ .../IR/RefbackrtDialect.cpp} | 20 ++--- .../IR/RefbackrtOps.cpp} | 14 ++-- lib/InitAll.cpp | 4 +- lib/RefBackend/CMakeLists.txt | 2 +- lib/RefBackend/JITHelpers/JITModule.cpp | 35 ++++---- lib/RefBackend/LowerToLLVM.cpp | 80 +++++++++---------- ...pcomprtABI.cpp => LowerToRefbackrtABI.cpp} | 61 +++++++------- lib/RefBackend/RefBackend.cpp | 6 +- lib/RefBackend/Runtime/CMakeLists.txt | 2 +- .../Runtime/CompilerDataStructures.h | 6 +- lib/RefBackend/Runtime/CompilerRuntime.cpp | 2 +- lib/RefBackend/Runtime/Runtime.cpp | 18 ++--- test/Dialect/Npcomprt/invalid.mlir | 43 ---------- test/Dialect/Npcomprt/ops.mlir | 20 ----- test/Dialect/Refbackrt/invalid.mlir | 43 ++++++++++ test/Dialect/Refbackrt/ops.mlir | 20 +++++ test/RefBackend/lower-to-llvm-global.mlir | 18 ++--- test/RefBackend/lower-to-llvm.mlir | 54 ++++++------- ...t-abi.mlir => lower-to-refbackrt-abi.mlir} | 38 ++++----- tools/mnist-playground/mnist-playground.cpp | 18 ++--- tools/npcomp-run-mlir/npcomp-run-mlir.cpp | 26 +++--- 41 files changed, 352 insertions(+), 352 deletions(-) delete mode 100644 include/npcomp/Dialect/Npcomprt/IR/CMakeLists.txt rename include/npcomp/Dialect/{Npcomprt => Refbackrt}/CMakeLists.txt (100%) create mode 100644 include/npcomp/Dialect/Refbackrt/IR/CMakeLists.txt rename include/npcomp/Dialect/{Npcomprt/IR/NpcomprtBase.td => Refbackrt/IR/RefbackrtBase.td} (50%) rename include/npcomp/Dialect/{Npcomprt/IR/NpcomprtDialect.h => Refbackrt/IR/RefbackrtDialect.h} (70%) rename include/npcomp/Dialect/{Npcomprt/IR/NpcomprtOps.h => Refbackrt/IR/RefbackrtOps.h} (71%) rename include/npcomp/Dialect/{Npcomprt/IR/NpcomprtOps.td => Refbackrt/IR/RefbackrtOps.td} (78%) delete mode 100644 lib/Dialect/Npcomprt/IR/CMakeLists.txt rename lib/Dialect/{Npcomprt => Refbackrt}/CMakeLists.txt (100%) create mode 100644 lib/Dialect/Refbackrt/IR/CMakeLists.txt rename lib/Dialect/{Npcomprt/IR/NpcomprtDialect.cpp => Refbackrt/IR/RefbackrtDialect.cpp} (55%) rename lib/Dialect/{Npcomprt/IR/NpcomprtOps.cpp => Refbackrt/IR/RefbackrtOps.cpp} (91%) rename lib/RefBackend/{LowerToNpcomprtABI.cpp => LowerToRefbackrtABI.cpp} (82%) delete mode 100644 test/Dialect/Npcomprt/invalid.mlir delete mode 100644 test/Dialect/Npcomprt/ops.mlir create mode 100644 test/Dialect/Refbackrt/invalid.mlir create mode 100644 test/Dialect/Refbackrt/ops.mlir rename test/RefBackend/{lower-to-npcomprt-abi.mlir => lower-to-refbackrt-abi.mlir} (62%) diff --git a/include/npcomp/Dialect/CMakeLists.txt b/include/npcomp/Dialect/CMakeLists.txt index a7f68cc01..c5e3ccf27 100644 --- a/include/npcomp/Dialect/CMakeLists.txt +++ b/include/npcomp/Dialect/CMakeLists.txt @@ -1,8 +1,8 @@ add_subdirectory(ATen) add_subdirectory(Basicpy) -add_subdirectory(Npcomprt) add_subdirectory(Numpy) add_subdirectory(RefBackend) +add_subdirectory(Refbackrt) add_subdirectory(TCF) add_subdirectory(TCP) add_subdirectory(Torch) diff --git a/include/npcomp/Dialect/Npcomprt/IR/CMakeLists.txt b/include/npcomp/Dialect/Npcomprt/IR/CMakeLists.txt deleted file mode 100644 index 1a47e0d84..000000000 --- a/include/npcomp/Dialect/Npcomprt/IR/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_mlir_dialect(NpcomprtOps npcomprt) diff --git a/include/npcomp/Dialect/Npcomprt/CMakeLists.txt b/include/npcomp/Dialect/Refbackrt/CMakeLists.txt similarity index 100% rename from include/npcomp/Dialect/Npcomprt/CMakeLists.txt rename to include/npcomp/Dialect/Refbackrt/CMakeLists.txt diff --git a/include/npcomp/Dialect/Refbackrt/IR/CMakeLists.txt b/include/npcomp/Dialect/Refbackrt/IR/CMakeLists.txt new file mode 100644 index 000000000..a3b14f551 --- /dev/null +++ b/include/npcomp/Dialect/Refbackrt/IR/CMakeLists.txt @@ -0,0 +1 @@ +add_mlir_dialect(RefbackrtOps refbackrt) diff --git a/include/npcomp/Dialect/Npcomprt/IR/NpcomprtBase.td b/include/npcomp/Dialect/Refbackrt/IR/RefbackrtBase.td similarity index 50% rename from include/npcomp/Dialect/Npcomprt/IR/NpcomprtBase.td rename to include/npcomp/Dialect/Refbackrt/IR/RefbackrtBase.td index 514483a2f..8633a6ed9 100644 --- a/include/npcomp/Dialect/Npcomprt/IR/NpcomprtBase.td +++ b/include/npcomp/Dialect/Refbackrt/IR/RefbackrtBase.td @@ -6,31 +6,31 @@ // //===----------------------------------------------------------------------===// -#ifndef NPCOMPRT_BASE -#define NPCOMPRT_BASE +#ifndef REFBACKRT_BASE +#define REFBACKRT_BASE include "mlir/IR/OpBase.td" -def Npcomprt_Dialect : Dialect { - let name = "npcomprt"; - let cppNamespace = "::mlir::NPCOMP::npcomprt"; +def Refbackrt_Dialect : Dialect { + let name = "refbackrt"; + let cppNamespace = "::mlir::NPCOMP::refbackrt"; let description = [{ -The `npcomprt` dialect is the IR manifestation for interaction with the -npcomp runtime. It primarily serves as a layer that enapsulates the data -structures and functions available in the runtime, and faciliates +The `refbackrt` dialect is the IR manifestation for interaction with the +reference backend runtime. It primarily serves as a layer that enapsulates the +data structures and functions available in the runtime, and faciliates conversion to those conventions, such as by providing utilities for being lowered to the llvm dialect. }]; } -def Npcomprt_Tensor +def Refbackrt_Tensor : DialectType< - Npcomprt_Dialect, - CPred<"$_self.isa<::mlir::NPCOMP::npcomprt::TensorType>()">, - "npcomprt.tensor">, + Refbackrt_Dialect, + CPred<"$_self.isa<::mlir::NPCOMP::refbackrt::TensorType>()">, + "refbackrt.tensor">, BuildableType< - "$_builder.getType<::mlir::NPCOMP::npcomprt::TensorType>()"> { + "$_builder.getType<::mlir::NPCOMP::refbackrt::TensorType>()"> { let typeDescription = [{The runtime type that represents a buffer.}]; } -#endif // #ifndef NPCOMPRT_BASE +#endif // #ifndef REFBACKRT_BASE diff --git a/include/npcomp/Dialect/Npcomprt/IR/NpcomprtDialect.h b/include/npcomp/Dialect/Refbackrt/IR/RefbackrtDialect.h similarity index 70% rename from include/npcomp/Dialect/Npcomprt/IR/NpcomprtDialect.h rename to include/npcomp/Dialect/Refbackrt/IR/RefbackrtDialect.h index 90338f9ae..73f6924fd 100644 --- a/include/npcomp/Dialect/Npcomprt/IR/NpcomprtDialect.h +++ b/include/npcomp/Dialect/Refbackrt/IR/RefbackrtDialect.h @@ -6,14 +6,14 @@ // //===----------------------------------------------------------------------===// -#ifndef NPCOMP_DIALECT_NPCOMPRT_IR_NPCOMPRTDIALECT_H -#define NPCOMP_DIALECT_NPCOMPRT_IR_NPCOMPRTDIALECT_H +#ifndef NPCOMP_DIALECT_REFBACKRT_IR_REFBACKRTDIALECT_H +#define NPCOMP_DIALECT_REFBACKRT_IR_REFBACKRTDIALECT_H #include "mlir/IR/Dialect.h" namespace mlir { namespace NPCOMP { -namespace npcomprt { +namespace refbackrt { class TensorType : public Type::TypeBase { public: @@ -22,10 +22,10 @@ public: static TensorType get(MLIRContext *context) { return Base::get(context); } }; -} // namespace npcomprt +} // namespace refbackrt } // namespace NPCOMP } // namespace mlir -#include "npcomp/Dialect/Npcomprt/IR/NpcomprtOpsDialect.h.inc" +#include "npcomp/Dialect/Refbackrt/IR/RefbackrtOpsDialect.h.inc" -#endif // NPCOMP_DIALECT_NPCOMPRT_IR_NPCOMPRTDIALECT_H +#endif // NPCOMP_DIALECT_REFBACKRT_IR_REFBACKRTDIALECT_H diff --git a/include/npcomp/Dialect/Npcomprt/IR/NpcomprtOps.h b/include/npcomp/Dialect/Refbackrt/IR/RefbackrtOps.h similarity index 71% rename from include/npcomp/Dialect/Npcomprt/IR/NpcomprtOps.h rename to include/npcomp/Dialect/Refbackrt/IR/RefbackrtOps.h index 8444ab343..39b805df6 100644 --- a/include/npcomp/Dialect/Npcomprt/IR/NpcomprtOps.h +++ b/include/npcomp/Dialect/Refbackrt/IR/RefbackrtOps.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef NPCOMP_DIALECT_NPCOMPRT_IR_NPCOMPRTOPS_H -#define NPCOMP_DIALECT_NPCOMPRT_IR_NPCOMPRTOPS_H +#ifndef NPCOMP_DIALECT_REFBACKRT_IR_REFBACKRTOPS_H +#define NPCOMP_DIALECT_REFBACKRT_IR_REFBACKRTOPS_H #include "mlir/IR/OpDefinition.h" #include "mlir/IR/OpImplementation.h" @@ -15,6 +15,6 @@ #include "mlir/IR/SymbolTable.h" #define GET_OP_CLASSES -#include "npcomp/Dialect/Npcomprt/IR/NpcomprtOps.h.inc" +#include "npcomp/Dialect/Refbackrt/IR/RefbackrtOps.h.inc" -#endif // NPCOMP_DIALECT_NPCOMPRT_IR_NPCOMPRTOPS_H +#endif // NPCOMP_DIALECT_REFBACKRT_IR_REFBACKRTOPS_H diff --git a/include/npcomp/Dialect/Npcomprt/IR/NpcomprtOps.td b/include/npcomp/Dialect/Refbackrt/IR/RefbackrtOps.td similarity index 78% rename from include/npcomp/Dialect/Npcomprt/IR/NpcomprtOps.td rename to include/npcomp/Dialect/Refbackrt/IR/RefbackrtOps.td index bfd273913..f504d24f3 100644 --- a/include/npcomp/Dialect/Npcomprt/IR/NpcomprtOps.td +++ b/include/npcomp/Dialect/Refbackrt/IR/RefbackrtOps.td @@ -6,37 +6,37 @@ // //===----------------------------------------------------------------------===// -#ifndef NPCOMPRT_OPS -#define NPCOMPRT_OPS +#ifndef REFBACKRT_OPS +#define REFBACKRT_OPS -include "npcomp/Dialect/Npcomprt/IR/NpcomprtBase.td" +include "npcomp/Dialect/Refbackrt/IR/RefbackrtBase.td" include "mlir/IR/SymbolInterfaces.td" -class Npcomprt_Op traits = []> - : Op { +class Refbackrt_Op traits = []> + : Op { } -def Npcomprt_ToMemrefOp : Npcomprt_Op<"to_memref"> { +def Refbackrt_ToMemrefOp : Refbackrt_Op<"to_memref"> { let summary = "Gets a memref descriptor from a tensor"; let description = [{ Gets a memref descriptor from a tensor. }]; - let arguments = (ins Npcomprt_Tensor:$tensor); + let arguments = (ins Refbackrt_Tensor:$tensor); let results = (outs AnyUnrankedMemRef:$memref); let assemblyFormat = "$tensor attr-dict `:` type($memref)"; } -def Npcomprt_FromMemrefOp : Npcomprt_Op<"from_memref"> { +def Refbackrt_FromMemrefOp : Refbackrt_Op<"from_memref"> { let summary = "Converts a memref descriptor to a tensor"; let description = [{ Copies the data from a memref into a new tensor. }]; let arguments = (ins AnyUnrankedMemRef:$memref); - let results = (outs Npcomprt_Tensor:$tensor); + let results = (outs Refbackrt_Tensor:$tensor); let assemblyFormat = "$memref attr-dict `:` type($memref)"; } -def Npcomprt_AbortIfOp : Npcomprt_Op<"abort_if"> { +def Refbackrt_AbortIfOp : Refbackrt_Op<"abort_if"> { let summary = "Aborts if the predicate is true"; let description = [{ Aborts if the predicate is true. @@ -46,7 +46,7 @@ def Npcomprt_AbortIfOp : Npcomprt_Op<"abort_if"> { let assemblyFormat = "$pred `,` $msg attr-dict"; } -def Npcomprt_GlobalOp : Npcomprt_Op<"global", [Symbol]> { +def Refbackrt_GlobalOp : Refbackrt_Op<"global", [Symbol]> { let summary = "Represents a global variable"; let description = [{ Represents a global variable. @@ -61,19 +61,19 @@ def Npcomprt_GlobalOp : Npcomprt_Op<"global", [Symbol]> { let parser = [{ return ::parse$cppClass(parser, result); }]; } -def Npcomprt_GetGlobalOp : Npcomprt_Op<"get_global"> { +def Refbackrt_GetGlobalOp : Refbackrt_Op<"get_global"> { let summary = "Obtain a rank-erased memref pointing at the given global"; let description = [{ Obtain a rank-erased memref pointing at the given global. TODO: As we define the runtime layer better, we should have fewer entry points that return memrefs, or at least have a clearer separation - between the "memref world" and the "npcomprt world". + between the "memref world" and the "refbackrt world". Something like forming IREE dispatch regions seems to be the missing thing: - Everything inside the dispatch regions gets things marshaled from the - runtime (flow/hal/npcomprt) layer to/from memrefs in a clear way. + runtime (flow/hal/refbackrt) layer to/from memrefs in a clear way. - Everything outside the dispatch regions purely uses the runtime - (flow/hal/npcomprt) data structures. + (flow/hal/refbackrt) data structures. Globals should be one of the things that are purely runtime data structures, rather than using memrefs. For now, using memrefs is simpler though. }]; @@ -83,12 +83,12 @@ def Npcomprt_GetGlobalOp : Npcomprt_Op<"get_global"> { let verifier = "return ::verify$cppClass(*this);"; } -def Npcomprt_ModuleMetadataOp : Npcomprt_Op<"module_metadata", [ +def Refbackrt_ModuleMetadataOp : Refbackrt_Op<"module_metadata", [ SingleBlockImplicitTerminator<"ModuleMetadataTerminatorOp"> ]> { let summary = "Global metadata for the module"; let description = [{ - This op contains a region containing npcomprt.func_metadata ops, + This op contains a region containing refbackrt.func_metadata ops, which give information about the functions in the module. This allows the module to be introspected when it is loaded, such as looking up functions. @@ -110,8 +110,8 @@ def Npcomprt_ModuleMetadataOp : Npcomprt_Op<"module_metadata", [ let parser = [{ return ::parse$cppClass(parser, result); }]; } -def Npcomprt_ModuleMetadataTerminatorOp - : Npcomprt_Op<"module_metadata_terminator", +def Refbackrt_ModuleMetadataTerminatorOp + : Refbackrt_Op<"module_metadata_terminator", [Terminator, HasParent<"ModuleMetadataOp">]> { let summary = "Implicit terminator for ModuleMetadataOp's region"; let arguments = (ins); @@ -119,8 +119,8 @@ def Npcomprt_ModuleMetadataTerminatorOp let assemblyFormat = "attr-dict"; } -def Npcomprt_FuncMetadataOp - : Npcomprt_Op<"func_metadata", [HasParent<"ModuleMetadataOp">]> { +def Refbackrt_FuncMetadataOp + : Refbackrt_Op<"func_metadata", [HasParent<"ModuleMetadataOp">]> { let summary = "Runtime metadata for a single func"; let description = [{ Runtime metadata for a single func. @@ -138,4 +138,4 @@ def Npcomprt_FuncMetadataOp let verifier = [{ return ::verify(*this); }]; } -#endif // #ifndef NPCOMPRT_OPS +#endif // #ifndef REFBACKRT_OPS diff --git a/include/npcomp/RefBackend/JITHelpers/JITModule.h b/include/npcomp/RefBackend/JITHelpers/JITModule.h index 1895a8164..60bd0cfbb 100644 --- a/include/npcomp/RefBackend/JITHelpers/JITModule.h +++ b/include/npcomp/RefBackend/JITHelpers/JITModule.h @@ -24,7 +24,7 @@ class PassManager; } // namespace mlir namespace npcomp { -// Wrapper around npcomprt data structures and a JITted module, facilitating +// Wrapper around refbackrt data structures and a JITted module, facilitating // interaction. class JITModule { public: @@ -40,14 +40,14 @@ public: fromCompiledModule(mlir::ModuleOp module, llvm::ArrayRef sharedLibs); - llvm::Expected, 6>> + llvm::Expected, 6>> invoke(llvm::StringRef functionName, - llvm::ArrayRef> inputs); + llvm::ArrayRef> inputs); private: JITModule(); std::unique_ptr engine; - npcomprt::ModuleDescriptor *descriptor; + refbackrt::ModuleDescriptor *descriptor; }; } // namespace npcomp diff --git a/include/npcomp/RefBackend/Passes.td b/include/npcomp/RefBackend/Passes.td index b4b4fa195..cabe8f426 100644 --- a/include/npcomp/RefBackend/Passes.td +++ b/include/npcomp/RefBackend/Passes.td @@ -52,10 +52,10 @@ def LowerStructuralToMemref : let constructor = "mlir::NPCOMP::createLowerStructuralToMemrefPass()"; } -def LowerToNpcomprtABI : Pass<"lower-to-npcomprt-abi", "ModuleOp"> { - let summary = "Lower constructs requiring runtime support to `npcomprt`"; +def LowerToRefbackrtABI : Pass<"lower-to-refbackrt-abi", "ModuleOp"> { + let summary = "Lower constructs requiring runtime support to `refbackrt`"; let description = [{ - We have a specialized dialect `npcomprt` which models our runtime's data + We have a specialized dialect `refbackrt` which models our runtime's data structures, and function signatures (and presumably eventually, other ABI boundaries like external calls if we ever support it) will be converted. @@ -65,7 +65,7 @@ def LowerToNpcomprtABI : Pass<"lower-to-npcomprt-abi", "ModuleOp"> { - globals - error handling }]; - let constructor = "mlir::NPCOMP::createLowerToNpcomprtABIPass()"; + let constructor = "mlir::NPCOMP::createLowerToRefbackrtABIPass()"; } def LowerAllocMemRefOps : Pass<"lower-alloc-memref-ops", "FuncOp"> { diff --git a/include/npcomp/RefBackend/RefBackend.h b/include/npcomp/RefBackend/RefBackend.h index 03b1a2bc7..40edb5668 100644 --- a/include/npcomp/RefBackend/RefBackend.h +++ b/include/npcomp/RefBackend/RefBackend.h @@ -34,7 +34,7 @@ createLowerConstantTensorsToMemrefPass(); std::unique_ptr> createLowerStructuralToMemrefPass(); -std::unique_ptr> createLowerToNpcomprtABIPass(); +std::unique_ptr> createLowerToRefbackrtABIPass(); std::unique_ptr> createLowerAllocMemRefOpsPass(); diff --git a/include/npcomp/RefBackend/Runtime/README.md b/include/npcomp/RefBackend/Runtime/README.md index d22e6f34a..d909611d7 100644 --- a/include/npcomp/RefBackend/Runtime/README.md +++ b/include/npcomp/RefBackend/Runtime/README.md @@ -1,4 +1,4 @@ -RefBackendRt (namespace `refbackrt`) is the runtime support library for the +Refbackrt (namespace `refbackrt`) is the runtime support library for the RefBackend backend. It is best practice to keep compiler and runtime code totally firewalled. diff --git a/include/npcomp/RefBackend/Runtime/Support.h b/include/npcomp/RefBackend/Runtime/Support.h index e9b3b59f2..4dd4b40a9 100644 --- a/include/npcomp/RefBackend/Runtime/Support.h +++ b/include/npcomp/RefBackend/Runtime/Support.h @@ -19,7 +19,7 @@ #include #include -namespace npcomprt { +namespace refbackrt { class StringRef { public: StringRef(const char *ptr, std::size_t length) : ptr(ptr), length(length){}; @@ -94,6 +94,6 @@ inline bool failed(LogicalResult result) { return result.value == LogicalResult::Failure; } -} // namespace npcomprt +} // namespace refbackrt #endif // NPCOMP_RUNTIME_SUPPORT_H diff --git a/include/npcomp/RefBackend/Runtime/UserAPI.h b/include/npcomp/RefBackend/Runtime/UserAPI.h index 5b66a25c0..f5b9c24a9 100644 --- a/include/npcomp/RefBackend/Runtime/UserAPI.h +++ b/include/npcomp/RefBackend/Runtime/UserAPI.h @@ -25,7 +25,7 @@ #include #include -namespace npcomprt { +namespace refbackrt { // Reference-counted handle to a type with a `refCount` member. template class Ref { @@ -178,6 +178,6 @@ LogicalResult getMetadata(ModuleDescriptor *moduleDescriptor, StringRef functionName, FunctionMetadata &outMetadata); -} // namespace npcomprt +} // namespace refbackrt #endif // NPCOMP_RUNTIME_USERAPI_H diff --git a/lib/Backend/RefJIT/PythonModule.cpp b/lib/Backend/RefJIT/PythonModule.cpp index 3f7084f2d..33cee4fc9 100644 --- a/lib/Backend/RefJIT/PythonModule.cpp +++ b/lib/Backend/RefJIT/PythonModule.cpp @@ -22,8 +22,8 @@ using llvm::Twine; using mlir::PyModuleOp; using mlir::PyPassManager; using npcomp::JITModule; -using npcomprt::Ref; -using npcomprt::Tensor; +using refbackrt::Ref; +using refbackrt::Tensor; template static T checkError(llvm::Expected &&expected, Twine banner = {}) { @@ -37,10 +37,10 @@ static T checkError(llvm::Expected &&expected, Twine banner = {}) { throw py::raisePyError(PyExc_RuntimeError, errorMessage.c_str()); } -static npcomprt::ElementType +static refbackrt::ElementType mapBufferFormatToElementType(const std::string &format, py::ssize_t itemSize) { if (format == "f") - return npcomprt::ElementType::F32; + return refbackrt::ElementType::F32; std::string message("unsupported buffer format: "); message.append(format); @@ -61,7 +61,7 @@ static Ref copyBufferToTensor(py::buffer buffer) { // TODO: Switch Tensor extents to ssize_t for efficiency. SmallVector extents(info.shape.begin(), info.shape.end()); return Tensor::create( - npcomprt::ArrayRef(extents.data(), extents.size()), + refbackrt::ArrayRef(extents.data(), extents.size()), elementType, info.ptr); } @@ -73,7 +73,7 @@ py::array wrapTensorAsArray(Ref tensor) { const char *format; switch (tensor->getElementType()) { - case npcomprt::ElementType::F32: + case refbackrt::ElementType::F32: format = "f"; break; default: diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 47f9b547c..324fcb1a4 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -43,7 +43,7 @@ add_mlir_library(NPCOMPInitAll NPCOMPTCPDialect NPCOMPTCFDialect NPCOMPTorchDialect - NPCOMPNpcomprtDialect + NPCOMPRefbackrtDialect NPCOMPATenDialect NPCOMPBasicpyDialect NPCOMPBasicpyPasses diff --git a/lib/Dialect/CMakeLists.txt b/lib/Dialect/CMakeLists.txt index a7f68cc01..c5e3ccf27 100644 --- a/lib/Dialect/CMakeLists.txt +++ b/lib/Dialect/CMakeLists.txt @@ -1,8 +1,8 @@ add_subdirectory(ATen) add_subdirectory(Basicpy) -add_subdirectory(Npcomprt) add_subdirectory(Numpy) add_subdirectory(RefBackend) +add_subdirectory(Refbackrt) add_subdirectory(TCF) add_subdirectory(TCP) add_subdirectory(Torch) diff --git a/lib/Dialect/Npcomprt/IR/CMakeLists.txt b/lib/Dialect/Npcomprt/IR/CMakeLists.txt deleted file mode 100644 index f70fa79d7..000000000 --- a/lib/Dialect/Npcomprt/IR/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -add_mlir_dialect_library(NPCOMPNpcomprtDialect - NpcomprtDialect.cpp - NpcomprtOps.cpp - - ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/npcomp/Dialect/Npcomprt - - DEPENDS - MLIRNpcomprtOpsIncGen - - LINK_COMPONENTS - Core - - LINK_LIBS PUBLIC - MLIRIR - MLIRSupport -) diff --git a/lib/Dialect/Npcomprt/CMakeLists.txt b/lib/Dialect/Refbackrt/CMakeLists.txt similarity index 100% rename from lib/Dialect/Npcomprt/CMakeLists.txt rename to lib/Dialect/Refbackrt/CMakeLists.txt diff --git a/lib/Dialect/Refbackrt/IR/CMakeLists.txt b/lib/Dialect/Refbackrt/IR/CMakeLists.txt new file mode 100644 index 000000000..c1d15f444 --- /dev/null +++ b/lib/Dialect/Refbackrt/IR/CMakeLists.txt @@ -0,0 +1,17 @@ +add_mlir_dialect_library(NPCOMPRefbackrtDialect + RefbackrtDialect.cpp + RefbackrtOps.cpp + + ADDITIONAL_HEADER_DIRS + ${PROJECT_SOURCE_DIR}/include/npcomp/Dialect/Refbackrt + + DEPENDS + MLIRRefbackrtOpsIncGen + + LINK_COMPONENTS + Core + + LINK_LIBS PUBLIC + MLIRIR + MLIRSupport +) diff --git a/lib/Dialect/Npcomprt/IR/NpcomprtDialect.cpp b/lib/Dialect/Refbackrt/IR/RefbackrtDialect.cpp similarity index 55% rename from lib/Dialect/Npcomprt/IR/NpcomprtDialect.cpp rename to lib/Dialect/Refbackrt/IR/RefbackrtDialect.cpp index a5bbb5f1b..12c4d4063 100644 --- a/lib/Dialect/Npcomprt/IR/NpcomprtDialect.cpp +++ b/lib/Dialect/Refbackrt/IR/RefbackrtDialect.cpp @@ -6,23 +6,23 @@ // //===----------------------------------------------------------------------===// -#include "npcomp/Dialect/Npcomprt/IR/NpcomprtDialect.h" +#include "npcomp/Dialect/Refbackrt/IR/RefbackrtDialect.h" #include "mlir/IR/DialectImplementation.h" -#include "npcomp/Dialect/Npcomprt/IR/NpcomprtOps.h" +#include "npcomp/Dialect/Refbackrt/IR/RefbackrtOps.h" #include "llvm/ADT/TypeSwitch.h" using namespace mlir; -using namespace mlir::NPCOMP::npcomprt; +using namespace mlir::NPCOMP::refbackrt; -void NpcomprtDialect::initialize() { +void RefbackrtDialect::initialize() { addOperations< #define GET_OP_LIST -#include "npcomp/Dialect/Npcomprt/IR/NpcomprtOps.cpp.inc" +#include "npcomp/Dialect/Refbackrt/IR/RefbackrtOps.cpp.inc" >(); addTypes(); } -Type NpcomprtDialect::parseType(DialectAsmParser &parser) const { +Type RefbackrtDialect::parseType(DialectAsmParser &parser) const { StringRef keyword; if (parser.parseKeyword(&keyword)) return Type(); @@ -30,14 +30,14 @@ Type NpcomprtDialect::parseType(DialectAsmParser &parser) const { if (keyword == "tensor") return TensorType::get(getContext()); - parser.emitError(parser.getNameLoc(), "unknown type in 'npcomprt' dialect: ") + parser.emitError(parser.getNameLoc(), "unknown type in 'refbackrt' dialect: ") << keyword; return Type(); } -void NpcomprtDialect::printType(Type type, DialectAsmPrinter &os) const { +void RefbackrtDialect::printType(Type type, DialectAsmPrinter &os) const { TypeSwitch(type) - .Case([&](Type) { os << "tensor"; }) + .Case([&](Type) { os << "tensor"; }) .Default( - [&](Type) { llvm_unreachable("unexpected 'npcomprt' type kind"); }); + [&](Type) { llvm_unreachable("unexpected 'refbackrt' type kind"); }); } diff --git a/lib/Dialect/Npcomprt/IR/NpcomprtOps.cpp b/lib/Dialect/Refbackrt/IR/RefbackrtOps.cpp similarity index 91% rename from lib/Dialect/Npcomprt/IR/NpcomprtOps.cpp rename to lib/Dialect/Refbackrt/IR/RefbackrtOps.cpp index 908828ee0..bccede993 100644 --- a/lib/Dialect/Npcomprt/IR/NpcomprtOps.cpp +++ b/lib/Dialect/Refbackrt/IR/RefbackrtOps.cpp @@ -6,22 +6,22 @@ // //===----------------------------------------------------------------------===// -#include "npcomp/Dialect/Npcomprt/IR/NpcomprtOps.h" +#include "npcomp/Dialect/Refbackrt/IR/RefbackrtOps.h" #include "mlir/IR/Builders.h" #include "mlir/IR/Function.h" #include "mlir/IR/SymbolTable.h" #include "mlir/IR/TypeUtilities.h" -#include "npcomp/Dialect/Npcomprt/IR/NpcomprtDialect.h" +#include "npcomp/Dialect/Refbackrt/IR/RefbackrtDialect.h" using namespace mlir; -using namespace mlir::NPCOMP::npcomprt; +using namespace mlir::NPCOMP::refbackrt; //===----------------------------------------------------------------------===// // GlobalOp //===----------------------------------------------------------------------===// static void printGlobalOp(OpAsmPrinter &p, GlobalOp &op) { - p << "npcomprt.global "; + p << "refbackrt.global "; p.printSymbolName(op.sym_name()); p << ' '; p.printOptionalAttrDictWithKeyword(op.getAttrs(), @@ -49,7 +49,7 @@ static ParseResult parseGlobalOp(OpAsmParser &parser, OperationState &result) { static LogicalResult verifyGetGlobalOp(GetGlobalOp op) { auto global = SymbolTable::lookupNearestSymbolFrom(op, op.global()); if (!global) - return op.emitError() << "must reference a valid npcomprt.global"; + return op.emitError() << "must reference a valid refbackrt.global"; auto globalType = global.value().getType(); auto resultType = op.getType().cast(); if (globalType.getElementType() != resultType.getElementType()) @@ -62,7 +62,7 @@ static LogicalResult verifyGetGlobalOp(GetGlobalOp op) { //===----------------------------------------------------------------------===// static void printModuleMetadataOp(OpAsmPrinter &p, ModuleMetadataOp &op) { - p << "npcomprt.module_metadata"; + p << "refbackrt.module_metadata"; p.printOptionalAttrDictWithKeyword(op.getAttrs()); p.printRegion(op.metadatas(), /*printEntryBlockArgs=*/false, /*printBlockTerminators=*/false); @@ -99,4 +99,4 @@ static LogicalResult verify(FuncMetadataOp op) { } #define GET_OP_CLASSES -#include "npcomp/Dialect/Npcomprt/IR/NpcomprtOps.cpp.inc" +#include "npcomp/Dialect/Refbackrt/IR/RefbackrtOps.cpp.inc" diff --git a/lib/InitAll.cpp b/lib/InitAll.cpp index aaecabd18..f5a68f3aa 100644 --- a/lib/InitAll.cpp +++ b/lib/InitAll.cpp @@ -12,7 +12,7 @@ #include "npcomp/Dialect/ATen/ATenPasses.h" #include "npcomp/Dialect/Basicpy/IR/BasicpyDialect.h" #include "npcomp/Dialect/Basicpy/Transforms/Passes.h" -#include "npcomp/Dialect/Npcomprt/IR/NpcomprtDialect.h" +#include "npcomp/Dialect/Refbackrt/IR/RefbackrtDialect.h" #include "npcomp/Dialect/Numpy/IR/NumpyDialect.h" #include "npcomp/Dialect/Numpy/Transforms/Passes.h" #include "npcomp/Dialect/RefBackend/IR/RefBackendDialect.h" @@ -73,7 +73,7 @@ void mlir::NPCOMP::registerAllDialects(mlir::DialectRegistry ®istry) { registry.insertdescriptor = - reinterpret_cast(*expectedAddress); + reinterpret_cast(*expectedAddress); return std::move(ret); } -// Converter for bridging to npcomprt llvm-lookalike data structures. -static npcomprt::StringRef toNpcomprt(llvm::StringRef s) { - return npcomprt::StringRef(s.data(), s.size()); +// Converter for bridging to refbackrt llvm-lookalike data structures. +static refbackrt::StringRef toRefbackrt(llvm::StringRef s) { + return refbackrt::StringRef(s.data(), s.size()); } template -static npcomprt::ArrayRef toNpcomprt(llvm::ArrayRef a) { - return npcomprt::ArrayRef(a.data(), a.size()); +static refbackrt::ArrayRef toRefbackrt(llvm::ArrayRef a) { + return refbackrt::ArrayRef(a.data(), a.size()); } template -static npcomprt::MutableArrayRef toNpcomprt(llvm::MutableArrayRef a) { - return npcomprt::MutableArrayRef(a.data(), a.size()); +static refbackrt::MutableArrayRef toRefbackrt(llvm::MutableArrayRef a) { + return refbackrt::MutableArrayRef(a.data(), a.size()); } -llvm::Expected, 6>> +llvm::Expected, 6>> JITModule::invoke(llvm::StringRef functionName, - llvm::ArrayRef> inputs) { - npcomprt::FunctionMetadata metadata; - if (npcomprt::failed(npcomprt::getMetadata( - descriptor, toNpcomprt(functionName), metadata))) + llvm::ArrayRef> inputs) { + refbackrt::FunctionMetadata metadata; + if (refbackrt::failed(refbackrt::getMetadata( + descriptor, toRefbackrt(functionName), metadata))) return make_string_error("unknown function: " + Twine(functionName)); - SmallVector, 6> outputs(metadata.numOutputs); + SmallVector, 6> outputs( + metadata.numOutputs); if (metadata.numInputs != static_cast(inputs.size())) return make_string_error("invoking '" + Twine(functionName) + "': expected " + Twine(metadata.numInputs) + " inputs"); - npcomprt::invoke( - descriptor, toNpcomprt(functionName), toNpcomprt(inputs), - toNpcomprt(llvm::makeMutableArrayRef(outputs.data(), outputs.size()))); + refbackrt::invoke( + descriptor, toRefbackrt(functionName), toRefbackrt(inputs), + toRefbackrt(llvm::makeMutableArrayRef(outputs.data(), outputs.size()))); return outputs; } diff --git a/lib/RefBackend/LowerToLLVM.cpp b/lib/RefBackend/LowerToLLVM.cpp index cd7906e42..e33600d7d 100644 --- a/lib/RefBackend/LowerToLLVM.cpp +++ b/lib/RefBackend/LowerToLLVM.cpp @@ -15,8 +15,8 @@ #include "mlir/Dialect/StandardOps/Transforms/Passes.h" #include "mlir/Transforms/DialectConversion.h" -#include "npcomp/Dialect/Npcomprt/IR/NpcomprtDialect.h" -#include "npcomp/Dialect/Npcomprt/IR/NpcomprtOps.h" +#include "npcomp/Dialect/Refbackrt/IR/RefbackrtDialect.h" +#include "npcomp/Dialect/Refbackrt/IR/RefbackrtOps.h" using namespace mlir; using namespace mlir::NPCOMP; @@ -29,7 +29,7 @@ using mlir::LLVM::LLVMType; // These correspond to the types in CompilerDataStructures.h //===----------------------------------------------------------------------===// -// Get the LLVMType for npcomprt::FuncDescriptor. +// Get the LLVMType for refbackrt::FuncDescriptor. static LLVMType getFuncDescriptorTy(MLIRContext *context) { return LLVMType::getStructTy(context, { // Name length. @@ -45,7 +45,7 @@ static LLVMType getFuncDescriptorTy(MLIRContext *context) { }); } -// Get the LLVMType for npcomprt::ModuleDescriptor. +// Get the LLVMType for refbackrt::ModuleDescriptor. static LLVMType getModuleDescriptorTy(MLIRContext *context) { return LLVMType::getStructTy(context, { @@ -56,7 +56,7 @@ static LLVMType getModuleDescriptorTy(MLIRContext *context) { }); } -// Get the LLVMType for npcomprt::GlobalDescriptor. +// Get the LLVMType for refbackrt::GlobalDescriptor. static LLVMType getGlobalDescriptorTy(MLIRContext *context) { return LLVMType::getStructTy( // std::int32_t numExtents; @@ -97,13 +97,13 @@ namespace { // FromMemrefOp requires special handling so that the unranked memref descriptor // gets passed as two separate arguments instead of as a struct. class FromMemrefOpCompilerRuntimeLowering - : public OpConversionPattern { + : public OpConversionPattern { public: FromMemrefOpCompilerRuntimeLowering(LLVM::LLVMFuncOp backingFunc) - : OpConversionPattern(backingFunc.getContext()), + : OpConversionPattern(backingFunc.getContext()), backingFunc(backingFunc) {} LogicalResult - matchAndRewrite(npcomprt::FromMemrefOp op, ArrayRef operands, + matchAndRewrite(refbackrt::FromMemrefOp op, ArrayRef operands, ConversionPatternRewriter &rewriter) const override { auto structVal = operands[0]; Value rank = rewriter.create( @@ -124,17 +124,17 @@ public: namespace { class GetGlobalOpCompilerRuntimeLowering - : public OpConversionPattern { + : public OpConversionPattern { public: GetGlobalOpCompilerRuntimeLowering(LLVM::LLVMFuncOp backingFunc) - : OpConversionPattern(backingFunc.getContext()), + : OpConversionPattern(backingFunc.getContext()), backingFunc(backingFunc) {} LogicalResult - matchAndRewrite(npcomprt::GetGlobalOp op, ArrayRef operands, + matchAndRewrite(refbackrt::GetGlobalOp op, ArrayRef operands, ConversionPatternRewriter &rewriter) const override { // It would be nice if we could use the constructor here that takes just the // global, but keeping track of the converted llvm.mlir.global op that gets - // created from the npcomprt.global while conversion is going on is a + // created from the refbackrt.global while conversion is going on is a // headache. // // Instead, we rely on the symbol name being the same and the result type @@ -178,15 +178,15 @@ static LLVM::GlobalOp createGlobalString(ModuleOp module, StringAttr msg, namespace { class AbortIfOpCompilerRuntimeLowering - : public OpConversionPattern { + : public OpConversionPattern { public: AbortIfOpCompilerRuntimeLowering(LLVM::LLVMFuncOp backingFunc) - : OpConversionPattern(backingFunc.getContext()), + : OpConversionPattern(backingFunc.getContext()), backingFunc(backingFunc) {} LogicalResult - matchAndRewrite(npcomprt::AbortIfOp op, ArrayRef operands, + matchAndRewrite(refbackrt::AbortIfOp op, ArrayRef operands, ConversionPatternRewriter &rewriter) const override { - npcomprt::AbortIfOp::Adaptor adaptor(operands); + refbackrt::AbortIfOp::Adaptor adaptor(operands); auto *context = op.getContext(); // Create the global string, take its address, and gep to get an `i8*`. @@ -207,7 +207,7 @@ public: }; } // namespace -// Create the LLVM runtime function backing the npcomprt op with name `name` +// Create the LLVM runtime function backing the refbackrt op with name `name` // and requiring `type`. static LLVMFuncOp createCompilerRuntimeFuncDecl(StringRef name, LLVMType type, OpBuilder &builder, @@ -242,12 +242,12 @@ static void populateCompilerRuntimePatterns(ModuleOp module, { auto mlirFunctionType = builder.getFunctionType( - {builder.getType()}, + {builder.getType()}, {UnrankedMemRefType::get(builder.getF32Type(), /*memorySpace=*/0)}); LLVMType funcTy = convertFunctionType(mlirFunctionType); LLVMFuncOp toMemrefFunc = createCompilerRuntimeFuncDecl( "to_memref", funcTy, builder, module.getLoc()); - patterns.insert>( + patterns.insert>( toMemrefFunc); } @@ -256,7 +256,7 @@ static void populateCompilerRuntimePatterns(ModuleOp module, // doesn't know its own dtype. auto mlirFunctionType = builder.getFunctionType( {UnrankedMemRefType::get(builder.getF32Type(), /*memorySpace=*/0)}, - {builder.getType()}); + {builder.getType()}); LLVMType funcTy = convertFunctionType(mlirFunctionType); LLVMFuncOp fromMemrefFunc = createCompilerRuntimeFuncDecl( "from_memref", funcTy, builder, module.getLoc()); @@ -277,24 +277,24 @@ static void populateCompilerRuntimePatterns(ModuleOp module, } //===----------------------------------------------------------------------===// -// Lowering for npcomprt.global +// Lowering for refbackrt.global //===----------------------------------------------------------------------===// namespace { -class LowerNpcomprtGlobalOp : public OpConversionPattern { +class LowerRefbackrtGlobalOp : public OpConversionPattern { public: - explicit LowerNpcomprtGlobalOp(LLVMTypeConverter &typeConverter) - : OpConversionPattern(&typeConverter.getContext()), + explicit LowerRefbackrtGlobalOp(LLVMTypeConverter &typeConverter) + : OpConversionPattern(&typeConverter.getContext()), typeConverter(typeConverter) {} LogicalResult - matchAndRewrite(npcomprt::GlobalOp op, ArrayRef operands, + matchAndRewrite(refbackrt::GlobalOp op, ArrayRef operands, ConversionPatternRewriter &rewriter) const override { auto *context = rewriter.getContext(); auto globalDescriptorTy = getGlobalDescriptorTy(context); // Create the data buffer. auto dataBuffer = createGlobalForDenseElementsAttr( - (Twine("__npcomprt_global_data_buffer_") + op.sym_name()).str(), + (Twine("__refbackrt_global_data_buffer_") + op.sym_name()).str(), op.value().cast(), op, rewriter); // Create the extents buffer. @@ -302,8 +302,8 @@ public: llvm::map_range(op.value().getType().cast().getShape(), [](int64_t i) -> int32_t { return i; }))); auto extentsBuffer = createGlobalForDenseElementsAttr( - (Twine("__npcomprt_global_extents_") + op.sym_name()).str(), extentsI32, - op, rewriter); + (Twine("__refbackrt_global_extents_") + op.sym_name()).str(), + extentsI32, op, rewriter); // Create the GlobalDescriptor. auto globalDescriptorGlobal = rewriter.create( @@ -352,7 +352,7 @@ public: private: // TODO: It feels like MLIR core should have better utilities for this. LLVM::GlobalOp createGlobalForDenseElementsAttr( - StringRef symbolName, DenseElementsAttr elements, npcomprt::GlobalOp op, + StringRef symbolName, DenseElementsAttr elements, refbackrt::GlobalOp op, ConversionPatternRewriter &rewriter) const { auto type = elements.getType().cast(); @@ -384,7 +384,7 @@ private: /*isConstant=*/true, LLVM::Linkage::Internal, symbolName, elements); } - LLVMType getLLVMTypeForShapedType(ShapedType type, npcomprt::GlobalOp op, + LLVMType getLLVMTypeForShapedType(ShapedType type, refbackrt::GlobalOp op, ConversionPatternRewriter &rewriter) const { auto llvmType = typeConverter.convertType(type.getElementType()).cast(); @@ -425,7 +425,7 @@ private: //===----------------------------------------------------------------------===// static LLVM::GlobalOp -createFuncDescriptorArray(ArrayRef funcMetadatas, +createFuncDescriptorArray(ArrayRef funcMetadatas, OpBuilder &builder, Location loc) { auto llvmI32Ty = LLVMType::getIntNTy(builder.getContext(), 32); @@ -556,14 +556,14 @@ LLVM::GlobalOp createModuleDescriptor(LLVM::GlobalOp funcDescriptorArray, namespace { class LowerModuleMetadata - : public OpConversionPattern { + : public OpConversionPattern { public: using OpConversionPattern::OpConversionPattern; LogicalResult - matchAndRewrite(npcomprt::ModuleMetadataOp op, ArrayRef operands, + matchAndRewrite(refbackrt::ModuleMetadataOp op, ArrayRef operands, ConversionPatternRewriter &rewriter) const override { auto funcMetadatas = - llvm::to_vector<6>(op.metadatas().getOps()); + llvm::to_vector<6>(op.metadatas().getOps()); auto funcDescriptorArray = createFuncDescriptorArray(funcMetadatas, rewriter, op.getLoc()); auto moduleDescriptor = @@ -646,7 +646,7 @@ static void storeWrapperResults(LLVM::CallOp callToWrapped, Value resultsPtrPtr, // Construct a wrapper function. // For an externally visible function f(T1, T2) -> T3, T4, we create a // wrapper -// __npcomprt_wrapper_f(void **inputs, void ** outputs) { +// __refbackrt_wrapper_f(void **inputs, void ** outputs) { // T3 t3; // T4 t4; // (t3, t4) = f(*cast(inputs[0]), *cast(inputs[1])); @@ -664,8 +664,8 @@ static LLVMFuncOp createWrapperFunc(LLVMFuncOp func) { auto wrapperTy = LLVMType::getFunctionTy(LLVMType::getVoidTy(context), {voidStarStarTy, voidStarStarTy}, /*isVarArg=*/false); - constexpr char kNpcomprtWrapperPrefix[] = "__npcomprt_wrapper_"; - auto wrapperName = (Twine(kNpcomprtWrapperPrefix) + func.getName()).str(); + constexpr char kRefbackrtWrapperPrefix[] = "__refbackrt_wrapper_"; + auto wrapperName = (Twine(kRefbackrtWrapperPrefix) + func.getName()).str(); OpBuilder moduleBuilder(func.getParentRegion()); LLVMFuncOp wrapper = moduleBuilder.create( func.getLoc(), wrapperName, wrapperTy, LLVM::Linkage::External); @@ -693,8 +693,8 @@ class LowerToLLVM : public LowerToLLVMBase { LLVMTypeConverter converter(context); - // npcomprt::TensorType is passed as a `void*` in the ABI. - converter.addConversion([&](npcomprt::TensorType type) { + // refbackrt::TensorType is passed as a `void*` in the ABI. + converter.addConversion([&](refbackrt::TensorType type) { return LLVMType::getInt8PtrTy(context); }); @@ -706,7 +706,7 @@ class LowerToLLVM : public LowerToLLVMBase { target.addLegalOp(); populateStdToLLVMConversionPatterns(converter, patterns); patterns.insert(context); - patterns.insert(converter); + patterns.insert(converter); // TODO: Move these "std to std" legalizations to their own pass if we grow // lots of these patterns. diff --git a/lib/RefBackend/LowerToNpcomprtABI.cpp b/lib/RefBackend/LowerToRefbackrtABI.cpp similarity index 82% rename from lib/RefBackend/LowerToNpcomprtABI.cpp rename to lib/RefBackend/LowerToRefbackrtABI.cpp index 1f3a66497..f0056d330 100644 --- a/lib/RefBackend/LowerToNpcomprtABI.cpp +++ b/lib/RefBackend/LowerToRefbackrtABI.cpp @@ -14,8 +14,8 @@ #include "mlir/IR/Verifier.h" #include "mlir/Transforms/DialectConversion.h" -#include "npcomp/Dialect/Npcomprt/IR/NpcomprtDialect.h" -#include "npcomp/Dialect/Npcomprt/IR/NpcomprtOps.h" +#include "npcomp/Dialect/Refbackrt/IR/RefbackrtDialect.h" +#include "npcomp/Dialect/Refbackrt/IR/RefbackrtOps.h" #include "npcomp/Dialect/RefBackend/IR/RefBackendOps.h" using namespace mlir; @@ -32,10 +32,10 @@ static Type getABIMemrefType(Type type) { // Creating module metadata. //===----------------------------------------------------------------------===// -// Returns true if the function signature can be expressed with the npcomprt +// Returns true if the function signature can be expressed with the refbackrt // ABI. -static bool expressibleWithNpcomprtABI(FunctionType type) { - // Currently, only memref types can be exposed at npcomprt ABI boundaries. +static bool expressibleWithRefbackrtABI(FunctionType type) { + // Currently, only memref types can be exposed at refbackrt ABI boundaries. return llvm::all_of( llvm::concat(type.getInputs(), type.getResults()), [](Type t) { return t.isa(); }); @@ -44,11 +44,11 @@ static bool expressibleWithNpcomprtABI(FunctionType type) { static LogicalResult createModuleMetadata(ModuleOp module) { auto moduleMetadata = OpBuilder::atBlockBegin(module.getBody()) - .create(module.getLoc()); + .create(module.getLoc()); moduleMetadata.metadatas().push_back(new Block); Block &metadatas = moduleMetadata.metadatas().front(); OpBuilder::atBlockEnd(&metadatas) - .create(module.getLoc()); + .create(module.getLoc()); SymbolTable symbolTable(module); auto builder = OpBuilder::atBlockBegin(&metadatas); @@ -59,13 +59,13 @@ static LogicalResult createModuleMetadata(ModuleOp module) { } // TODO: Add richer information here such as expected shapes and element // types. - builder.create( + builder.create( func.getLoc(), builder.getSymbolRefAttr(func.getName()), builder.getI32IntegerAttr(func.getNumArguments()), builder.getI32IntegerAttr(func.getNumResults())); - if (!expressibleWithNpcomprtABI(func.getType())) - return func.emitError() << "func not expressible with npcomprt ABI"; + if (!expressibleWithRefbackrtABI(func.getType())) + return func.emitError() << "func not expressible with refbackrt ABI"; } return success(); } @@ -81,8 +81,8 @@ public: LogicalResult matchAndRewrite(refback::GlobalOp op, ArrayRef operands, ConversionPatternRewriter &rewriter) const override { - rewriter.replaceOpWithNewOp(op, op.sym_name(), - op.value()); + rewriter.replaceOpWithNewOp(op, op.sym_name(), + op.value()); return success(); } }; @@ -96,7 +96,7 @@ public: LogicalResult matchAndRewrite(refback::GetGlobalMemrefOp op, ArrayRef operands, ConversionPatternRewriter &rewriter) const override { - auto abiMemref = rewriter.create( + auto abiMemref = rewriter.create( op.getLoc(), getABIMemrefType(op.getType()), op.global()); // Cast back to the original type. rewriter.replaceOpWithNewOp(op, abiMemref, op.getType()); @@ -113,22 +113,22 @@ public: matchAndRewrite(AssertOp op, ArrayRef operands, ConversionPatternRewriter &rewriter) const override { AssertOp::Adaptor adaptor(operands); - // The npcomprt runtime function aborts if the argument is true, rather than - // when it is false as an `assert` does. So negate the predicate (by xor'ing - // with 1). + // The refbackrt runtime function aborts if the argument is true, rather + // than when it is false as an `assert` does. So negate the predicate (by + // xor'ing with 1). auto c1 = rewriter.create( op.getLoc(), rewriter.getIntegerAttr(rewriter.getI1Type(), APInt(/*numBits=*/1, /*val=*/1))); Value assertFailed = rewriter.create(op.getLoc(), adaptor.arg(), c1); - rewriter.replaceOpWithNewOp(op, assertFailed, - op.msgAttr()); + rewriter.replaceOpWithNewOp(op, assertFailed, + op.msgAttr()); return success(); } }; } // namespace namespace { -// At ABI bondaries, use !npcomprt.tensor instead of memref. +// At ABI bondaries, use !refbackrt.tensor instead of memref. class FuncOpSignatureConversion : public OpConversionPattern { public: using OpConversionPattern::OpConversionPattern; @@ -159,7 +159,7 @@ public: for (auto newAndOldArg : llvm::zip(newEntry.getArguments(), oldEntry.getArguments())) { std::tie(newArg, oldArg) = newAndOldArg; - auto abiMemref = rewriter.create( + auto abiMemref = rewriter.create( op.getLoc(), getABIMemrefType(oldArg.getType()), newArg); auto memref = rewriter.create(op.getLoc(), abiMemref, oldArg.getType()); @@ -172,7 +172,7 @@ public: } // namespace namespace { -// At the return ABI boundaries, convert to !npcomprt.tensor type. +// At the return ABI boundaries, convert to !refbackrt.tensor type. // This pattern is needed to trigger the type conversion mechanics to do a // target materialization. class RewriteReturnOp : public OpConversionPattern { @@ -193,20 +193,20 @@ static LogicalResult doDialectConversion(ModuleOp module) { TypeConverter typeConverter; typeConverter.addConversion([](Type type) { return type; }); typeConverter.addConversion([](MemRefType type) { - return npcomprt::TensorType::get(type.getContext()); + return refbackrt::TensorType::get(type.getContext()); }); typeConverter.addTargetMaterialization( - [](OpBuilder &builder, npcomprt::TensorType type, ValueRange inputs, + [](OpBuilder &builder, refbackrt::TensorType type, ValueRange inputs, Location loc) -> Value { assert(inputs.size() == 1); auto abiMemref = builder.create( loc, inputs[0], getABIMemrefType(inputs[0].getType())); - return builder.create(loc, type, abiMemref); + return builder.create(loc, type, abiMemref); }); OwningRewritePatternList patterns; ConversionTarget target(*context); - target.addLegalDialect(); + target.addLegalDialect(); target.addLegalDialect(); patterns.insert(typeConverter, context); @@ -230,10 +230,11 @@ static LogicalResult doDialectConversion(ModuleOp module) { namespace { // This pass lowers the public ABI of the module to the primitives exposed by -// the npcomprt dialect. -class LowerToNpcomprtABI : public LowerToNpcomprtABIBase { +// the refbackrt dialect. +class LowerToRefbackrtABI + : public LowerToRefbackrtABIBase { void getDependentDialects(DialectRegistry ®istry) const override { - registry.insert(); + registry.insert(); } void runOnOperation() override { @@ -254,6 +255,6 @@ class LowerToNpcomprtABI : public LowerToNpcomprtABIBase { } // namespace std::unique_ptr> -mlir::NPCOMP::createLowerToNpcomprtABIPass() { - return std::make_unique(); +mlir::NPCOMP::createLowerToRefbackrtABIPass() { + return std::make_unique(); } diff --git a/lib/RefBackend/RefBackend.cpp b/lib/RefBackend/RefBackend.cpp index 35eac8761..de6551f0a 100644 --- a/lib/RefBackend/RefBackend.cpp +++ b/lib/RefBackend/RefBackend.cpp @@ -292,12 +292,12 @@ void mlir::NPCOMP::createRefBackendLoweringPipeline( pm.addPass(createLowerToCFGPass()); // Convert functions signatures and other constructs that interface with the - // runtime to the `npcomprt` dialect. - pm.addPass(createLowerToNpcomprtABIPass()); + // runtime to the `refbackrt` dialect. + pm.addPass(createLowerToRefbackrtABIPass()); // Finally, convert to LLVM dialect using our custom LowerToLLVM pass // which reuses the upstream patterns and gives us a place to add our own - // patterns for our own custom ops like the npcomprt ops. + // patterns for our own custom ops like the refbackrt ops. pm.addPass(createLowerToLLVMPass()); // Although LLVM will clean everything up eventually, for the sake of IR diff --git a/lib/RefBackend/Runtime/CMakeLists.txt b/lib/RefBackend/Runtime/CMakeLists.txt index f07ffd19a..5658f75cb 100644 --- a/lib/RefBackend/Runtime/CMakeLists.txt +++ b/lib/RefBackend/Runtime/CMakeLists.txt @@ -7,7 +7,7 @@ set(LLVM_OPTIONAL_SOURCES ) # The library that users link against, defining basic interactions with an -# npcomprt module and the relevant data structures. +# refbackrt module and the relevant data structures. add_mlir_library(NPCOMPRuntime Runtime.cpp diff --git a/lib/RefBackend/Runtime/CompilerDataStructures.h b/lib/RefBackend/Runtime/CompilerDataStructures.h index 5eb5a9a98..ae669f6bf 100644 --- a/lib/RefBackend/Runtime/CompilerDataStructures.h +++ b/lib/RefBackend/Runtime/CompilerDataStructures.h @@ -17,7 +17,7 @@ #include -namespace npcomprt { +namespace refbackrt { // All arguments are packed into this type-erased form for being invoked. See // LowerToLLVM.cpp for more details. @@ -55,6 +55,6 @@ struct GlobalDescriptor { void *data; }; -} // namespace npcomprt +} // namespace refbackrt -#endif // NPCOMP_LIB_RUNTIME_COMPILERDATASTRUCTURES_H \ No newline at end of file +#endif // NPCOMP_LIB_RUNTIME_COMPILERDATASTRUCTURES_H diff --git a/lib/RefBackend/Runtime/CompilerRuntime.cpp b/lib/RefBackend/Runtime/CompilerRuntime.cpp index 3d9d2554b..1b15fa30c 100644 --- a/lib/RefBackend/Runtime/CompilerRuntime.cpp +++ b/lib/RefBackend/Runtime/CompilerRuntime.cpp @@ -18,7 +18,7 @@ #include "CompilerDataStructures.h" #include "npcomp/RefBackend/Runtime/UserAPI.h" -using namespace npcomprt; +using namespace refbackrt; extern "C" void __npcomp_compiler_rt_abort_if(bool b, const char *msg) { if (b) { diff --git a/lib/RefBackend/Runtime/Runtime.cpp b/lib/RefBackend/Runtime/Runtime.cpp index 783502445..ee5b607e3 100644 --- a/lib/RefBackend/Runtime/Runtime.cpp +++ b/lib/RefBackend/Runtime/Runtime.cpp @@ -15,7 +15,7 @@ #include "CompilerDataStructures.h" -using namespace npcomprt; +using namespace refbackrt; //===----------------------------------------------------------------------===// // Tensor @@ -29,7 +29,7 @@ static std::int32_t totalElements(ArrayRef extents) { return ret; } -std::int32_t npcomprt::getElementTypeByteSize(ElementType type) { +std::int32_t refbackrt::getElementTypeByteSize(ElementType type) { switch (type) { case ElementType::F32: return 4; @@ -85,9 +85,9 @@ static FuncDescriptor *getFuncDescriptor(ModuleDescriptor *moduleDescriptor, return nullptr; } -void npcomprt::invoke(ModuleDescriptor *moduleDescriptor, - StringRef functionName, ArrayRef> inputs, - MutableArrayRef> outputs) { +void refbackrt::invoke(ModuleDescriptor *moduleDescriptor, + StringRef functionName, ArrayRef> inputs, + MutableArrayRef> outputs) { auto *descriptor = getFuncDescriptor(moduleDescriptor, functionName); assert(descriptor && "unknown function name"); assert(inputs.size() < kMaxArity && "number of inputs exceeds kMaxArity"); @@ -104,7 +104,7 @@ void npcomprt::invoke(ModuleDescriptor *moduleDescriptor, for (int i = 0, e = outputs.size(); i < e; i++) outputTensorPtrs[i] = static_cast(packedOutputs[i]); // TODO: Actually manage refcounts inside the compiler. - // Right now, we only pass around npcomprt.tensor's in trivial ways on ABI + // Right now, we only pass around refbackrt.tensor's in trivial ways on ABI // boundaries, so the following contract of the compiler-generated code works: // - input tensors are never retained or released // - output tensors always have refcount 0. Hence the next line here is @@ -113,9 +113,9 @@ void npcomprt::invoke(ModuleDescriptor *moduleDescriptor, outputs[i] = Ref(outputTensorPtrs[i]); } -LogicalResult npcomprt::getMetadata(ModuleDescriptor *moduleDescriptor, - StringRef functionName, - FunctionMetadata &outMetadata) { +LogicalResult refbackrt::getMetadata(ModuleDescriptor *moduleDescriptor, + StringRef functionName, + FunctionMetadata &outMetadata) { auto *descriptor = getFuncDescriptor(moduleDescriptor, functionName); if (!descriptor) return failure(); diff --git a/test/Dialect/Npcomprt/invalid.mlir b/test/Dialect/Npcomprt/invalid.mlir deleted file mode 100644 index c62716545..000000000 --- a/test/Dialect/Npcomprt/invalid.mlir +++ /dev/null @@ -1,43 +0,0 @@ -// RUN: npcomp-opt <%s -split-input-file -verify-diagnostics - -npcomprt.module_metadata { - // expected-error @+1 {{must reference a valid func}} - npcomprt.func_metadata {funcName = @g, numInputs = 1 : i32, numOutputs = 0 : i32} -} - - -// ----- - -npcomprt.module_metadata { - // expected-error @+1 {{must agree on number of inputs}} - npcomprt.func_metadata {funcName = @f, numInputs = 1 : i32, numOutputs = 0 : i32} -} -func @f() { return } - -// ----- - -npcomprt.module_metadata { - // expected-error @+1 {{must agree on number of outputs}} - npcomprt.func_metadata {funcName = @f, numInputs = 0 : i32, numOutputs = 1 : i32} -} -func @f() { return } - -// ----- - -npcomprt.global @g dense<0.0> : tensor<2xf32> - -func @f() { - // expected-error @+1 {{must reference a valid npcomprt.global}} - npcomprt.get_global @nonexistent_symbol : memref<*xf32> - return -} - -// ----- - -npcomprt.global @g dense<0.0> : tensor<2xf32> - -func @f() { - // expected-error @+1 {{inconsistent with element type of global}} - npcomprt.get_global @g : memref<*xi8> - return -} diff --git a/test/Dialect/Npcomprt/ops.mlir b/test/Dialect/Npcomprt/ops.mlir deleted file mode 100644 index 569bfc72e..000000000 --- a/test/Dialect/Npcomprt/ops.mlir +++ /dev/null @@ -1,20 +0,0 @@ -// RUN: npcomp-opt <%s | npcomp-opt | FileCheck %s --dump-input=fail - -// CHECK: npcomprt.module_metadata -npcomprt.module_metadata { - // CHECK: npcomprt.func_metadata - npcomprt.func_metadata {funcName = @f, numInputs = 1 : i32, numOutputs = 0 : i32} -} - -// CHECK-LABEL: func @f -// CHECK-SAME: !npcomprt.tensor -func @f(%arg0: !npcomprt.tensor) { - return -} - -// CHECK-LABEL: npcomprt.global @g dense<0.0{{.*}}> : tensor<10xf32> -npcomprt.global @g dense<0.0> : tensor<10xf32> -func @uses_global() { - npcomprt.get_global @g : memref<*xf32> - return -} \ No newline at end of file diff --git a/test/Dialect/Refbackrt/invalid.mlir b/test/Dialect/Refbackrt/invalid.mlir new file mode 100644 index 000000000..d33207df7 --- /dev/null +++ b/test/Dialect/Refbackrt/invalid.mlir @@ -0,0 +1,43 @@ +// RUN: npcomp-opt <%s -split-input-file -verify-diagnostics + +refbackrt.module_metadata { + // expected-error @+1 {{must reference a valid func}} + refbackrt.func_metadata {funcName = @g, numInputs = 1 : i32, numOutputs = 0 : i32} +} + + +// ----- + +refbackrt.module_metadata { + // expected-error @+1 {{must agree on number of inputs}} + refbackrt.func_metadata {funcName = @f, numInputs = 1 : i32, numOutputs = 0 : i32} +} +func @f() { return } + +// ----- + +refbackrt.module_metadata { + // expected-error @+1 {{must agree on number of outputs}} + refbackrt.func_metadata {funcName = @f, numInputs = 0 : i32, numOutputs = 1 : i32} +} +func @f() { return } + +// ----- + +refbackrt.global @g dense<0.0> : tensor<2xf32> + +func @f() { + // expected-error @+1 {{must reference a valid refbackrt.global}} + refbackrt.get_global @nonexistent_symbol : memref<*xf32> + return +} + +// ----- + +refbackrt.global @g dense<0.0> : tensor<2xf32> + +func @f() { + // expected-error @+1 {{inconsistent with element type of global}} + refbackrt.get_global @g : memref<*xi8> + return +} diff --git a/test/Dialect/Refbackrt/ops.mlir b/test/Dialect/Refbackrt/ops.mlir new file mode 100644 index 000000000..02ccbc20f --- /dev/null +++ b/test/Dialect/Refbackrt/ops.mlir @@ -0,0 +1,20 @@ +// RUN: npcomp-opt <%s | npcomp-opt | FileCheck %s --dump-input=fail + +// CHECK: refbackrt.module_metadata +refbackrt.module_metadata { + // CHECK: refbackrt.func_metadata + refbackrt.func_metadata {funcName = @f, numInputs = 1 : i32, numOutputs = 0 : i32} +} + +// CHECK-LABEL: func @f +// CHECK-SAME: !refbackrt.tensor +func @f(%arg0: !refbackrt.tensor) { + return +} + +// CHECK-LABEL: refbackrt.global @g dense<0.0{{.*}}> : tensor<10xf32> +refbackrt.global @g dense<0.0> : tensor<10xf32> +func @uses_global() { + refbackrt.get_global @g : memref<*xf32> + return +} diff --git a/test/RefBackend/lower-to-llvm-global.mlir b/test/RefBackend/lower-to-llvm-global.mlir index b21bb4580..a8619c373 100644 --- a/test/RefBackend/lower-to-llvm-global.mlir +++ b/test/RefBackend/lower-to-llvm-global.mlir @@ -5,17 +5,17 @@ // CHECK: llvm.func @__npcomp_compiler_rt_to_memref(!llvm.ptr) -> !llvm.struct<(i64, ptr)> // CHECK: llvm.func @__npcomp_compiler_rt_from_memref(!llvm.i64, !llvm.ptr) -> !llvm.ptr // CHECK: llvm.func @__npcomp_compiler_rt_get_global(!llvm.ptr, ptr)>>) -> !llvm.struct<(i64, ptr)> -// CHECK: llvm.mlir.global internal constant @__npcomprt_global_data_buffer_g(dense<7.000000e+00> : tensor<3xf32>) : !llvm.array<3 x float> -// CHECK: llvm.mlir.global internal constant @__npcomprt_global_extents_g(dense<3> : tensor<1xi32>) : !llvm.array<1 x i32> +// CHECK: llvm.mlir.global internal constant @__refbackrt_global_data_buffer_g(dense<7.000000e+00> : tensor<3xf32>) : !llvm.array<3 x float> +// CHECK: llvm.mlir.global internal constant @__refbackrt_global_extents_g(dense<3> : tensor<1xi32>) : !llvm.array<1 x i32> // CHECK-LABEL: llvm.mlir.global internal constant @g() : !llvm.struct<(i32, ptr, ptr)> { // CHECK: %[[VAL_0:.*]] = llvm.mlir.undef : !llvm.struct<(i32, ptr, ptr)> // CHECK: %[[VAL_1:.*]] = llvm.mlir.constant(1 : i32) : !llvm.i32 // CHECK: %[[VAL_2:.*]] = llvm.insertvalue %[[VAL_1]], %[[VAL_0]][0 : i32] : !llvm.struct<(i32, ptr, ptr)> -// CHECK: %[[VAL_3:.*]] = llvm.mlir.addressof @__npcomprt_global_extents_g : !llvm.ptr> +// CHECK: %[[VAL_3:.*]] = llvm.mlir.addressof @__refbackrt_global_extents_g : !llvm.ptr> // CHECK: %[[VAL_4:.*]] = llvm.bitcast %[[VAL_3]] : !llvm.ptr> to !llvm.ptr // CHECK: %[[VAL_5:.*]] = llvm.insertvalue %[[VAL_4]], %[[VAL_2]][1 : i32] : !llvm.struct<(i32, ptr, ptr)> -// CHECK: %[[VAL_6:.*]] = llvm.mlir.addressof @__npcomprt_global_data_buffer_g : !llvm.ptr> +// CHECK: %[[VAL_6:.*]] = llvm.mlir.addressof @__refbackrt_global_data_buffer_g : !llvm.ptr> // CHECK: %[[VAL_7:.*]] = llvm.bitcast %[[VAL_6]] : !llvm.ptr> to !llvm.ptr // CHECK: %[[VAL_8:.*]] = llvm.insertvalue %[[VAL_7]], %[[VAL_5]][2 : i32] : !llvm.struct<(i32, ptr, ptr)> // CHECK: llvm.return %[[VAL_8]] : !llvm.struct<(i32, ptr, ptr)> @@ -44,15 +44,15 @@ // CHECK: %[[VAL_18:.*]] = llvm.insertvalue %[[VAL_13]], %[[VAL_17]][1] : !llvm.struct<(i64, ptr)> // CHECK: llvm.return %[[VAL_18]] : !llvm.struct<(i64, ptr)> // CHECK: } -npcomprt.global @g dense<7.000000e+00> : tensor<3xf32> +refbackrt.global @g dense<7.000000e+00> : tensor<3xf32> func @calls_get_global() -> memref<*xf32> { - %0 = npcomprt.get_global @g : memref<*xf32> + %0 = refbackrt.get_global @g : memref<*xf32> return %0 : memref<*xf32> } // ----- // For scalars, we have to fake-up a size-1 data buffer array to make LLVM translation happy. -// CHECK: llvm.mlir.global internal constant @__npcomprt_global_data_buffer_g(dense<7.000000e+00> : tensor) : !llvm.array<1 x float> -// CHECK: llvm.mlir.global internal constant @__npcomprt_global_extents_g(dense<0> : tensor<1xi32>) : !llvm.array<1 x i32> -npcomprt.global @g dense<7.0> : tensor +// CHECK: llvm.mlir.global internal constant @__refbackrt_global_data_buffer_g(dense<7.000000e+00> : tensor) : !llvm.array<1 x float> +// CHECK: llvm.mlir.global internal constant @__refbackrt_global_extents_g(dense<0> : tensor<1xi32>) : !llvm.array<1 x i32> +refbackrt.global @g dense<7.0> : tensor diff --git a/test/RefBackend/lower-to-llvm.mlir b/test/RefBackend/lower-to-llvm.mlir index b5bfcd81d..8c7cfca2a 100644 --- a/test/RefBackend/lower-to-llvm.mlir +++ b/test/RefBackend/lower-to-llvm.mlir @@ -1,6 +1,6 @@ // RUN: npcomp-opt -refback-lower-to-llvm -split-input-file <%s | FileCheck %s --dump-input=fail -// CHECK-LABEL: llvm.func @__npcomprt_wrapper_identity( +// CHECK-LABEL: llvm.func @__refbackrt_wrapper_identity( // CHECK-SAME: %[[VAL_0:.*]]: !llvm.ptr>, // CHECK-SAME: %[[VAL_1:.*]]: !llvm.ptr>) { // CHECK: %[[VAL_2:.*]] = llvm.mlir.constant(0 : i32) : !llvm.i32 @@ -28,7 +28,7 @@ // CHECK: %[[VAL_4:.*]] = llvm.mlir.addressof @__npcomp_internal_constant_identity : !llvm.ptr> // CHECK: %[[VAL_5:.*]] = llvm.getelementptr %[[VAL_4]]{{\[}}%[[VAL_1]], %[[VAL_1]]] : (!llvm.ptr>, !llvm.i32, !llvm.i32) -> !llvm.ptr // CHECK: %[[VAL_6:.*]] = llvm.insertvalue %[[VAL_5]], %[[VAL_3]][0 : i32, 1 : i32] : !llvm.array<1 x struct<(i32, ptr, ptr, i32, i32)>> -// CHECK: %[[VAL_7:.*]] = llvm.mlir.addressof @__npcomprt_wrapper_identity : !llvm.ptr>, ptr>)>> +// CHECK: %[[VAL_7:.*]] = llvm.mlir.addressof @__refbackrt_wrapper_identity : !llvm.ptr>, ptr>)>> // CHECK: %[[VAL_8:.*]] = llvm.bitcast %[[VAL_7]] : !llvm.ptr>, ptr>)>> to !llvm.ptr // CHECK: %[[VAL_9:.*]] = llvm.insertvalue %[[VAL_8]], %[[VAL_6]][0 : i32, 2 : i32] : !llvm.array<1 x struct<(i32, ptr, ptr, i32, i32)>> // CHECK: %[[VAL_10:.*]] = llvm.mlir.constant(1 : i32) : !llvm.i32 @@ -48,8 +48,8 @@ // CHECK: llvm.return %[[VAL_5]] : !llvm.struct<(i32, ptr, ptr, i32, i32)>>)> // CHECK: } -npcomprt.module_metadata { - npcomprt.func_metadata {funcName = @identity, numInputs = 1 : i32, numOutputs = 1 : i32} +refbackrt.module_metadata { + refbackrt.func_metadata {funcName = @identity, numInputs = 1 : i32, numOutputs = 1 : i32} } @@ -57,15 +57,15 @@ npcomprt.module_metadata { // CHECK-SAME: %[[VAL_0:.*]]: !llvm.ptr) -> !llvm.ptr { // CHECK: llvm.return %[[VAL_0]] : !llvm.ptr // CHECK: } -func @identity(%arg0: !npcomprt.tensor) -> !npcomprt.tensor { - return %arg0 : !npcomprt.tensor +func @identity(%arg0: !refbackrt.tensor) -> !refbackrt.tensor { + return %arg0 : !refbackrt.tensor } // ----- // Test input/output arg marshaling. -// CHECK-LABEL: llvm.func @__npcomprt_wrapper_inputs1results2( +// CHECK-LABEL: llvm.func @__refbackrt_wrapper_inputs1results2( // CHECK-SAME: %[[VAL_0:.*]]: !llvm.ptr>, // CHECK-SAME: %[[VAL_1:.*]]: !llvm.ptr>) { // CHECK: %[[VAL_2:.*]] = llvm.mlir.constant(0 : i32) : !llvm.i32 @@ -86,7 +86,7 @@ func @identity(%arg0: !npcomprt.tensor) -> !npcomprt.tensor { // CHECK: llvm.return // CHECK: } -// CHECK-LABEL: llvm.func @__npcomprt_wrapper_inputs1results1( +// CHECK-LABEL: llvm.func @__refbackrt_wrapper_inputs1results1( // CHECK-SAME: %[[VAL_0:.*]]: !llvm.ptr>, // CHECK-SAME: %[[VAL_1:.*]]: !llvm.ptr>) { // CHECK: %[[VAL_2:.*]] = llvm.mlir.constant(0 : i32) : !llvm.i32 @@ -101,7 +101,7 @@ func @identity(%arg0: !npcomprt.tensor) -> !npcomprt.tensor { // CHECK: llvm.return // CHECK: } -// CHECK-LABEL: llvm.func @__npcomprt_wrapper_inputs1results0( +// CHECK-LABEL: llvm.func @__refbackrt_wrapper_inputs1results0( // CHECK-SAME: %[[VAL_0:.*]]: !llvm.ptr>, // CHECK-SAME: %[[VAL_1:.*]]: !llvm.ptr>) { // CHECK: %[[VAL_2:.*]] = llvm.mlir.constant(0 : i32) : !llvm.i32 @@ -127,7 +127,7 @@ func @identity(%arg0: !npcomprt.tensor) -> !npcomprt.tensor { // CHECK: %[[VAL_4:.*]] = llvm.mlir.addressof @__npcomp_internal_constant_inputs1results0 : !llvm.ptr> // CHECK: %[[VAL_5:.*]] = llvm.getelementptr %[[VAL_4]]{{\[}}%[[VAL_1]], %[[VAL_1]]] : (!llvm.ptr>, !llvm.i32, !llvm.i32) -> !llvm.ptr // CHECK: %[[VAL_6:.*]] = llvm.insertvalue %[[VAL_5]], %[[VAL_3]][0 : i32, 1 : i32] : !llvm.array<3 x struct<(i32, ptr, ptr, i32, i32)>> -// CHECK: %[[VAL_7:.*]] = llvm.mlir.addressof @__npcomprt_wrapper_inputs1results0 : !llvm.ptr>, ptr>)>> +// CHECK: %[[VAL_7:.*]] = llvm.mlir.addressof @__refbackrt_wrapper_inputs1results0 : !llvm.ptr>, ptr>)>> // CHECK: %[[VAL_8:.*]] = llvm.bitcast %[[VAL_7]] : !llvm.ptr>, ptr>)>> to !llvm.ptr // CHECK: %[[VAL_9:.*]] = llvm.insertvalue %[[VAL_8]], %[[VAL_6]][0 : i32, 2 : i32] : !llvm.array<3 x struct<(i32, ptr, ptr, i32, i32)>> // CHECK: %[[VAL_10:.*]] = llvm.mlir.constant(1 : i32) : !llvm.i32 @@ -139,7 +139,7 @@ func @identity(%arg0: !npcomprt.tensor) -> !npcomprt.tensor { // CHECK: %[[VAL_16:.*]] = llvm.mlir.addressof @__npcomp_internal_constant_inputs1results1 : !llvm.ptr> // CHECK: %[[VAL_17:.*]] = llvm.getelementptr %[[VAL_16]]{{\[}}%[[VAL_1]], %[[VAL_1]]] : (!llvm.ptr>, !llvm.i32, !llvm.i32) -> !llvm.ptr // CHECK: %[[VAL_18:.*]] = llvm.insertvalue %[[VAL_17]], %[[VAL_15]][1 : i32, 1 : i32] : !llvm.array<3 x struct<(i32, ptr, ptr, i32, i32)>> -// CHECK: %[[VAL_19:.*]] = llvm.mlir.addressof @__npcomprt_wrapper_inputs1results1 : !llvm.ptr>, ptr>)>> +// CHECK: %[[VAL_19:.*]] = llvm.mlir.addressof @__refbackrt_wrapper_inputs1results1 : !llvm.ptr>, ptr>)>> // CHECK: %[[VAL_20:.*]] = llvm.bitcast %[[VAL_19]] : !llvm.ptr>, ptr>)>> to !llvm.ptr // CHECK: %[[VAL_21:.*]] = llvm.insertvalue %[[VAL_20]], %[[VAL_18]][1 : i32, 2 : i32] : !llvm.array<3 x struct<(i32, ptr, ptr, i32, i32)>> // CHECK: %[[VAL_22:.*]] = llvm.mlir.constant(1 : i32) : !llvm.i32 @@ -151,7 +151,7 @@ func @identity(%arg0: !npcomprt.tensor) -> !npcomprt.tensor { // CHECK: %[[VAL_28:.*]] = llvm.mlir.addressof @__npcomp_internal_constant_inputs1results2 : !llvm.ptr> // CHECK: %[[VAL_29:.*]] = llvm.getelementptr %[[VAL_28]]{{\[}}%[[VAL_1]], %[[VAL_1]]] : (!llvm.ptr>, !llvm.i32, !llvm.i32) -> !llvm.ptr // CHECK: %[[VAL_30:.*]] = llvm.insertvalue %[[VAL_29]], %[[VAL_27]][2 : i32, 1 : i32] : !llvm.array<3 x struct<(i32, ptr, ptr, i32, i32)>> -// CHECK: %[[VAL_31:.*]] = llvm.mlir.addressof @__npcomprt_wrapper_inputs1results2 : !llvm.ptr>, ptr>)>> +// CHECK: %[[VAL_31:.*]] = llvm.mlir.addressof @__refbackrt_wrapper_inputs1results2 : !llvm.ptr>, ptr>)>> // CHECK: %[[VAL_32:.*]] = llvm.bitcast %[[VAL_31]] : !llvm.ptr>, ptr>)>> to !llvm.ptr // CHECK: %[[VAL_33:.*]] = llvm.insertvalue %[[VAL_32]], %[[VAL_30]][2 : i32, 2 : i32] : !llvm.array<3 x struct<(i32, ptr, ptr, i32, i32)>> // CHECK: %[[VAL_34:.*]] = llvm.mlir.constant(1 : i32) : !llvm.i32 @@ -171,10 +171,10 @@ func @identity(%arg0: !npcomprt.tensor) -> !npcomprt.tensor { // CHECK: llvm.return %[[VAL_5]] : !llvm.struct<(i32, ptr, ptr, i32, i32)>>)> // CHECK: } -npcomprt.module_metadata { - npcomprt.func_metadata {funcName = @inputs1results0, numInputs = 1 : i32, numOutputs = 0 : i32} - npcomprt.func_metadata {funcName = @inputs1results1, numInputs = 1 : i32, numOutputs = 1 : i32} - npcomprt.func_metadata {funcName = @inputs1results2, numInputs = 1 : i32, numOutputs = 2 : i32} +refbackrt.module_metadata { + refbackrt.func_metadata {funcName = @inputs1results0, numInputs = 1 : i32, numOutputs = 0 : i32} + refbackrt.func_metadata {funcName = @inputs1results1, numInputs = 1 : i32, numOutputs = 1 : i32} + refbackrt.func_metadata {funcName = @inputs1results2, numInputs = 1 : i32, numOutputs = 2 : i32} } @@ -183,7 +183,7 @@ npcomprt.module_metadata { // CHECK-SAME: %[[VAL_0:.*]]: !llvm.ptr) { // CHECK: llvm.return // CHECK: } -func @inputs1results0(%arg0: !npcomprt.tensor) { +func @inputs1results0(%arg0: !refbackrt.tensor) { return } @@ -191,8 +191,8 @@ func @inputs1results0(%arg0: !npcomprt.tensor) { // CHECK-SAME: %[[VAL_0:.*]]: !llvm.ptr) -> !llvm.ptr { // CHECK: llvm.return %[[VAL_0]] : !llvm.ptr // CHECK: } -func @inputs1results1(%arg0: !npcomprt.tensor) -> !npcomprt.tensor { - return %arg0 : !npcomprt.tensor +func @inputs1results1(%arg0: !refbackrt.tensor) -> !refbackrt.tensor { + return %arg0 : !refbackrt.tensor } // CHECK-LABEL: llvm.func @inputs1results2( @@ -202,8 +202,8 @@ func @inputs1results1(%arg0: !npcomprt.tensor) -> !npcomprt.tensor { // CHECK: %[[VAL_3:.*]] = llvm.insertvalue %[[VAL_0]], %[[VAL_2]][1] : !llvm.struct<(ptr, ptr)> // CHECK: llvm.return %[[VAL_3]] : !llvm.struct<(ptr, ptr)> // CHECK: } -func @inputs1results2(%arg0: !npcomprt.tensor) -> (!npcomprt.tensor, !npcomprt.tensor) { - return %arg0, %arg0 : !npcomprt.tensor, !npcomprt.tensor +func @inputs1results2(%arg0: !refbackrt.tensor) -> (!refbackrt.tensor, !refbackrt.tensor) { + return %arg0, %arg0 : !refbackrt.tensor, !refbackrt.tensor } @@ -226,7 +226,7 @@ func @inputs1results2(%arg0: !npcomprt.tensor) -> (!npcomprt.tensor, !npcomprt.t // CHECK: llvm.return func @calls_abort_if(%arg0: i1) { - npcomprt.abort_if %arg0, "msg" + refbackrt.abort_if %arg0, "msg" return } @@ -235,8 +235,8 @@ func @calls_abort_if(%arg0: i1) { // CHECK: %[[VAL_1:.*]] = llvm.call @__npcomp_compiler_rt_to_memref(%[[VAL_0]]) : (!llvm.ptr) -> !llvm.struct<(i64, ptr)> // CHECK: llvm.return // CHECK: } -func @calls_to_memref(%arg0: !npcomprt.tensor) { - %0 = npcomprt.to_memref %arg0 : memref<*xf32> +func @calls_to_memref(%arg0: !refbackrt.tensor) { + %0 = refbackrt.to_memref %arg0 : memref<*xf32> return } @@ -251,7 +251,7 @@ func @calls_to_memref(%arg0: !npcomprt.tensor) { // CHECK: %[[VAL_7:.*]] = llvm.call @__npcomp_compiler_rt_from_memref(%[[VAL_5]], %[[VAL_6]]) : (!llvm.i64, !llvm.ptr) -> !llvm.ptr // CHECK: llvm.return %[[VAL_7]] : !llvm.ptr // CHECK: } -func @calls_from_memref(%arg0: memref<*xf32>) -> !npcomprt.tensor { - %0 = npcomprt.from_memref %arg0 : memref<*xf32> - return %0 : !npcomprt.tensor +func @calls_from_memref(%arg0: memref<*xf32>) -> !refbackrt.tensor { + %0 = refbackrt.from_memref %arg0 : memref<*xf32> + return %0 : !refbackrt.tensor } diff --git a/test/RefBackend/lower-to-npcomprt-abi.mlir b/test/RefBackend/lower-to-refbackrt-abi.mlir similarity index 62% rename from test/RefBackend/lower-to-npcomprt-abi.mlir rename to test/RefBackend/lower-to-refbackrt-abi.mlir index 874629f01..13956968b 100644 --- a/test/RefBackend/lower-to-npcomprt-abi.mlir +++ b/test/RefBackend/lower-to-refbackrt-abi.mlir @@ -1,10 +1,10 @@ -// RUN: npcomp-opt -lower-to-npcomprt-abi -split-input-file -verify-diagnostics <%s | FileCheck %s --dump-input=fail +// RUN: npcomp-opt -lower-to-refbackrt-abi -split-input-file -verify-diagnostics <%s | FileCheck %s --dump-input=fail // Test module metadata. -// CHECK: npcomprt.module_metadata -// CHECK-NEXT: npcomprt.func_metadata {funcName = @f_2inputs_0outputs, numInputs = 2 : i32, numOutputs = 0 : i32} -// CHECK-NEXT: npcomprt.func_metadata {funcName = @f_1input_2outputs, numInputs = 1 : i32, numOutputs = 2 : i32} +// CHECK: refbackrt.module_metadata +// CHECK-NEXT: refbackrt.func_metadata {funcName = @f_2inputs_0outputs, numInputs = 2 : i32, numOutputs = 0 : i32} +// CHECK-NEXT: refbackrt.func_metadata {funcName = @f_1input_2outputs, numInputs = 1 : i32, numOutputs = 2 : i32} // This function only exists to test its metadata above. func @f_2inputs_0outputs(%arg0: memref, %arg1: memref) { @@ -20,12 +20,12 @@ func @f_1input_2outputs(%arg0: memref) -> (memref, memref) // Test ABI conversions. -// CHECK-LABEL: func @identity(%arg0: !npcomprt.tensor) -> !npcomprt.tensor +// CHECK-LABEL: func @identity(%arg0: !refbackrt.tensor) -> !refbackrt.tensor func @identity(%arg0: memref) -> memref { // The argument materialization. // In this test case, these go unused since, as described below, the new // argument value is seen immediately by the return op for some reason. - // CHECK-NEXT: %[[INABIMEMREF:.*]] = npcomprt.to_memref %arg0 : memref<*xf32> + // CHECK-NEXT: %[[INABIMEMREF:.*]] = refbackrt.to_memref %arg0 : memref<*xf32> // CHECK-NEXT: %[[MEMREF:.*]] = memref_cast %[[INABIMEMREF]] : memref<*xf32> to memref // TODO: Why do these target materializations not happen in this particular @@ -34,7 +34,7 @@ func @identity(%arg0: memref) -> memref { // rather than the result of replaceUsesOfBlockArgument from // FuncOpSignatureConversion // Cxxxx-NEXT: %[[OUTABIMEMREF:.*]] = memref_cast %[[MEMREF]] : memref to memref<*xf32> - // Cxxxx-NEXT: %[[RET:.*]] = npcomprt.from_memref %[[OUTABIMEMREF]] : memref<*xf32> + // Cxxxx-NEXT: %[[RET:.*]] = refbackrt.from_memref %[[OUTABIMEMREF]] : memref<*xf32> // Cxxxx-NEXT: return %[[RET]] // CHECK-NEXT: return %arg0 @@ -44,9 +44,9 @@ func @identity(%arg0: memref) -> memref { // ----- -// CHECK-LABEL: func @use_of_arg(%arg0: !npcomprt.tensor) +// CHECK-LABEL: func @use_of_arg(%arg0: !refbackrt.tensor) func @use_of_arg(%arg0: memref) { - // CHECK-NEXT: %[[INABIMEMREF:.*]] = npcomprt.to_memref %arg0 : memref<*xf32> + // CHECK-NEXT: %[[INABIMEMREF:.*]] = refbackrt.to_memref %arg0 : memref<*xf32> // CHECK-NEXT: %[[MEMREF:.*]] = memref_cast %[[INABIMEMREF]] : memref<*xf32> to memref %c0 = constant 0 : index %0 = dim %arg0, %c0 : memref @@ -57,32 +57,32 @@ func @use_of_arg(%arg0: memref) { // ----- -// CHECK-LABEL: func @multiple_blocks(%arg0: !npcomprt.tensor) -> !npcomprt.tensor +// CHECK-LABEL: func @multiple_blocks(%arg0: !refbackrt.tensor) -> !refbackrt.tensor func @multiple_blocks(%arg0: memref) -> memref { - // CHECK-NEXT: %[[INABIMEMREF:.*]] = npcomprt.to_memref %arg0 : memref<*xf32> + // CHECK-NEXT: %[[INABIMEMREF:.*]] = refbackrt.to_memref %arg0 : memref<*xf32> // CHECK-NEXT: %[[INMEMREF:.*]] = memref_cast %[[INABIMEMREF]] : memref<*xf32> to memref // CHECK-NEXT: br ^bb1(%[[INMEMREF]] : memref) br ^bb1(%arg0: memref) // CHECK-NEXT: ^bb1(%[[BBARG:.*]]: memref): ^bb1(%bbarg: memref): // CHECK-NEXT: %[[OUTMEMREF:.*]] = memref_cast %[[BBARG]] : memref to memref<*xf32> - // CHECK-NEXT: %[[OUTABIMEMREF:.*]] = npcomprt.from_memref %[[OUTMEMREF]] : memref<*xf32> - // CHECK-NEXT: return %[[OUTABIMEMREF]] : !npcomprt.tensor + // CHECK-NEXT: %[[OUTABIMEMREF:.*]] = refbackrt.from_memref %[[OUTMEMREF]] : memref<*xf32> + // CHECK-NEXT: return %[[OUTABIMEMREF]] : !refbackrt.tensor return %bbarg : memref } // ----- -// CHECK: npcomprt.global @g dense<7.000000e+00> : tensor<10xf32> +// CHECK: refbackrt.global @g dense<7.000000e+00> : tensor<10xf32> refback.global @g dense<7.0> : tensor<10xf32> -// CHECK-LABEL: func @gets_global() -> !npcomprt.tensor +// CHECK-LABEL: func @gets_global() -> !refbackrt.tensor func @gets_global() -> memref<10xf32> { -// CHECK: %[[GMEMREF:.*]] = npcomprt.get_global @g : memref<*xf32> +// CHECK: %[[GMEMREF:.*]] = refbackrt.get_global @g : memref<*xf32> // CHECK: %[[ORIGMEMREF:.*]] = memref_cast %[[GMEMREF]] : memref<*xf32> to memref<10xf32> // CHECK: %[[OUTABIMEMREF:.*]] = memref_cast %[[ORIGMEMREF:.*]] : memref<10xf32> to memref<*xf32> -// CHECK: %[[RET:.*]] = npcomprt.from_memref %[[OUTABIMEMREF]] : memref<*xf32> -// CHECK: return %[[RET]] : !npcomprt.tensor +// CHECK: %[[RET:.*]] = refbackrt.from_memref %[[OUTABIMEMREF]] : memref<*xf32> +// CHECK: return %[[RET]] : !refbackrt.tensor %0 = refback.get_global_memref @g : memref<10xf32> return %0 : memref<10xf32> } @@ -91,7 +91,7 @@ func @gets_global() -> memref<10xf32> { // Test diagnostics. -// expected-error @+1 {{func not expressible with npcomprt ABI}} +// expected-error @+1 {{func not expressible with refbackrt ABI}} func @unhandled_abi_type_on_public_func(%arg0: i32) { return } diff --git a/tools/mnist-playground/mnist-playground.cpp b/tools/mnist-playground/mnist-playground.cpp index b61f71071..192dac680 100644 --- a/tools/mnist-playground/mnist-playground.cpp +++ b/tools/mnist-playground/mnist-playground.cpp @@ -73,32 +73,30 @@ invokeJITModuleWithATenTensors(npcomp::JITModule &jitModule, std::vector tensorArgs; for (auto arg : llvm::enumerate(args)) tensorArgs.push_back(at::TensorArg(arg.value(), "arg", arg.index())); - at::CheckedFrom c = "converting to npcomprt::Tensor"; + at::CheckedFrom c = "converting to refbackrt::Tensor"; for (auto &tensorArg : tensorArgs) at::checkScalarType(c, tensorArg, at::ScalarType::Float); at::checkAllContiguous(c, tensorArgs); - SmallVector, 6> npcomprtInputs; + SmallVector, 6> refbackInputs; for (at::Tensor arg : args) { SmallVector extents(arg.sizes().begin(), arg.sizes().end()); float *data = arg.storage().data(); // This does a deep copy of the data. Let's see if it shows up on the // profile. - npcomprtInputs.push_back(npcomprt::Tensor::create( - npcomprt::ArrayRef(extents.data(), extents.size()), - npcomprt::ElementType::F32, data)); + refbackInputs.push_back(refbackrt::Tensor::create( + refbackrt::ArrayRef(extents.data(), extents.size()), + refbackrt::ElementType::F32, data)); } // Invoke the RefBackend function. - // TODO: The mishmash of terminology "npcomprt", "refback", "npcomp" in this - // file is getting out of hand. - auto expectedOutputs = jitModule.invoke(invokeFunction, npcomprtInputs); + auto expectedOutputs = jitModule.invoke(invokeFunction, refbackInputs); if (!expectedOutputs) return expectedOutputs.takeError(); - auto npcomprtOutputs = std::move(*expectedOutputs); + auto refbackrtOutputs = std::move(*expectedOutputs); std::vector results; - for (auto output : npcomprtOutputs) { + for (auto output : refbackrtOutputs) { std::vector sizes(output->getExtents().data(), output->getExtents().data() + output->getExtents().size()); diff --git a/tools/npcomp-run-mlir/npcomp-run-mlir.cpp b/tools/npcomp-run-mlir/npcomp-run-mlir.cpp index ef95daf58..290051037 100644 --- a/tools/npcomp-run-mlir/npcomp-run-mlir.cpp +++ b/tools/npcomp-run-mlir/npcomp-run-mlir.cpp @@ -35,7 +35,7 @@ static Error make_string_error(const Twine &message) { llvm::inconvertibleErrorCode()); } -static Expected> +static Expected> convertAttrToTensor(Attribute attr) { auto type = attr.getType().dyn_cast(); if (!type) @@ -47,18 +47,18 @@ convertAttrToTensor(Attribute attr) { if (elementType.isF32()) { auto values = llvm::to_vector<100>(llvm::map_range( denseFp, [](APFloat f) { return f.convertToFloat(); })); - return npcomprt::Tensor::create( - npcomprt::ArrayRef(extents.data(), extents.size()), - npcomprt::ElementType::F32, static_cast(values.data())); + return refbackrt::Tensor::create( + refbackrt::ArrayRef(extents.data(), extents.size()), + refbackrt::ElementType::F32, static_cast(values.data())); } } return make_string_error("unhandled argument"); } -static Expected, 6>> +static Expected, 6>> createInputs(ArrayRef argValues) { MLIRContext context; - SmallVector, 6> ret; + SmallVector, 6> ret; for (auto argValue : argValues) { auto attr = parseAttribute(argValue, &context); if (!attr) @@ -71,14 +71,14 @@ createInputs(ArrayRef argValues) { return ret; } -static Type convertToMLIRType(npcomprt::ElementType type, Builder &builder) { +static Type convertToMLIRType(refbackrt::ElementType type, Builder &builder) { switch (type) { - case npcomprt::ElementType::F32: + case refbackrt::ElementType::F32: return builder.getF32Type(); } } -static RankedTensorType getCorrespondingMLIRTensorType(npcomprt::Tensor &tensor, +static RankedTensorType getCorrespondingMLIRTensorType(refbackrt::Tensor &tensor, Builder &builder) { auto elementType = convertToMLIRType(tensor.getElementType(), builder); SmallVector extents; @@ -87,11 +87,11 @@ static RankedTensorType getCorrespondingMLIRTensorType(npcomprt::Tensor &tensor, return RankedTensorType::get(extents, elementType); } -static Attribute convertToMLIRAttribute(npcomprt::Tensor &tensor, +static Attribute convertToMLIRAttribute(refbackrt::Tensor &tensor, Builder &builder) { RankedTensorType type = getCorrespondingMLIRTensorType(tensor, builder); switch (tensor.getElementType()) { - case npcomprt::ElementType::F32: { + case refbackrt::ElementType::F32: { SmallVector values; auto *basePtr = tensor.getData(); for (int i = 0, e = type.getNumElements(); i < e; i++) @@ -101,14 +101,14 @@ static Attribute convertToMLIRAttribute(npcomprt::Tensor &tensor, } } -static void printOutput(npcomprt::Tensor &tensor, llvm::raw_ostream &os) { +static void printOutput(refbackrt::Tensor &tensor, llvm::raw_ostream &os) { MLIRContext context; Builder builder(&context); auto attr = convertToMLIRAttribute(tensor, builder); attr.print(os); } -static void printOutputs(ArrayRef> outputs, +static void printOutputs(ArrayRef> outputs, llvm::raw_ostream &os) { for (auto output : llvm::enumerate(outputs)) { os << "output #" << output.index() << ": ";