2020-08-13 10:28:04 +08:00
|
|
|
//===- ATenDialect.h --------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-10-23 05:13:26 +08:00
|
|
|
#ifndef NPCOMP_DIALECT_ATEN_IR_DIALECT_H
|
|
|
|
#define NPCOMP_DIALECT_ATEN_IR_DIALECT_H
|
2020-08-13 10:28:04 +08:00
|
|
|
|
|
|
|
#include "mlir/IR/Builders.h"
|
2020-12-12 06:43:38 +08:00
|
|
|
#include "mlir/IR/BuiltinOps.h"
|
|
|
|
#include "mlir/IR/BuiltinTypes.h"
|
2020-08-13 10:28:04 +08:00
|
|
|
#include "mlir/IR/Dialect.h"
|
|
|
|
#include "mlir/IR/OpDefinition.h"
|
|
|
|
#include "mlir/IR/OpImplementation.h"
|
|
|
|
#include "mlir/IR/TypeSupport.h"
|
|
|
|
#include "mlir/IR/Types.h"
|
|
|
|
#include "mlir/Interfaces/SideEffectInterfaces.h"
|
2020-10-23 14:31:34 +08:00
|
|
|
#include "npcomp/Dialect/Torch/IR/OpInterfaces.h"
|
2020-08-13 10:28:04 +08:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace mlir {
|
|
|
|
namespace NPCOMP {
|
|
|
|
namespace aten {
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////// Custom Types for the Dialect ///////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
struct ATenListTypeStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A variadic list of arguments in ATen
|
|
|
|
class ATenListType : public mlir::Type::TypeBase<ATenListType, mlir::Type,
|
|
|
|
detail::ATenListTypeStorage> {
|
|
|
|
public:
|
|
|
|
using Base::Base;
|
|
|
|
|
|
|
|
/// Return the type of individual elements in the array.
|
|
|
|
mlir::Type getElementType();
|
|
|
|
|
|
|
|
/// Get the unique instance of this Type from the context.
|
|
|
|
static ATenListType get(mlir::Type elementType);
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////// Custom Operations for the Dialect /////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Return the tensor volume (i.e., the number of elements) of the given shaped
|
|
|
|
// type. If the type does not have a rank, return 1. If the type doesn't
|
|
|
|
// have a static shape, return 0.
|
2020-10-23 05:13:26 +08:00
|
|
|
inline uint64_t getTensorVolume(const ShapedType ty) {
|
2020-08-13 10:28:04 +08:00
|
|
|
if (!ty.hasRank())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (!ty.hasStaticShape())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
uint64_t volume = 1;
|
|
|
|
for (auto &d : ty.getShape())
|
|
|
|
volume *= d;
|
|
|
|
return volume;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the tensor volume (i.e., the number of elements) of the given type.
|
|
|
|
// If the type doesn't have a shape, return 1. If the type is shaped, but
|
|
|
|
// does not have a rank, return 1. If the type is shaped, but doesn't have a
|
|
|
|
// static shape, return 0.
|
2020-10-23 05:13:26 +08:00
|
|
|
inline uint64_t getTensorVolume(const Type ty) {
|
2020-08-13 10:28:04 +08:00
|
|
|
if (auto t = ty.dyn_cast<ShapedType>()) {
|
|
|
|
return getTensorVolume(t);
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace aten
|
|
|
|
} // namespace NPCOMP
|
|
|
|
} // namespace mlir
|
|
|
|
|
2020-10-23 05:13:26 +08:00
|
|
|
#include "npcomp/Dialect/ATen/IR/ATenOpInterfaces.h"
|
2020-08-13 10:28:04 +08:00
|
|
|
|
|
|
|
// include TableGen generated Op definitions
|
|
|
|
#define GET_OP_CLASSES
|
2020-10-23 05:13:26 +08:00
|
|
|
#include "npcomp/Dialect/ATen/IR/ATenOps.h.inc"
|
2020-08-13 10:28:04 +08:00
|
|
|
|
2020-10-23 05:13:26 +08:00
|
|
|
#include "npcomp/Dialect/ATen/IR/ATenDialect.h.inc"
|
2020-08-28 06:09:10 +08:00
|
|
|
|
2020-10-23 05:13:26 +08:00
|
|
|
#endif // NPCOMP_DIALECT_ATEN_IR_DIALECT_H
|