Skip to content

Commit

Permalink
Merge pull request PaddlePaddle#8 from Superjomn/fea/intric_operation
Browse files Browse the repository at this point in the history
fea/intric operation
  • Loading branch information
Superjomn authored Feb 1, 2020
2 parents e45098b + e68ca2e commit 408878c
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 3 deletions.
1 change: 1 addition & 0 deletions cinn/ir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cc_library(ir SRCS
buffer.cc
tensor.cc
function_base.cc
operation.cc
DEPS common boost
)

Expand Down
1 change: 1 addition & 0 deletions cinn/ir/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Buffer _Buffer_::Make(Var data,
node->scope = scope;
node->data_alignment = data_alignment;
node->offset_factor = offset_factor;
return Buffer(node);
}

void _Buffer_::Accept(IrVisitor *v) const { v->Visit(this); }
Expand Down
27 changes: 27 additions & 0 deletions cinn/ir/operation.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "cinn/ir/operation.h"

namespace cinn {
namespace ir {

Operation ExternOp::Make(std::string name,
std::string tag,
std::map<std::string, IrNodeRef> attrs,
std::vector<Tensor> inputs,
std::vector<Buffer> input_placeholders,
std::vector<Buffer> output_placeholders,
Stmt body) {
auto n = common::make_shared<ExternOp>();
n->name = std::move(name);
n->tag = std::move(tag);
n->attrs = std::move(attrs);
CHECK_EQ(inputs.size(), input_placeholders.size());

n->inputs = std::move(inputs);
n->input_placeholders = std::move(input_placeholders);
n->output_placeholders = std::move(output_placeholders);
n->body = std::move(body);
return Operation(n);
}

} // namespace ir
} // namespace cinn
82 changes: 82 additions & 0 deletions cinn/ir/operation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#pragma once

#include <map>
#include <string>
#include <utility>
#include <vector>

#include "cinn/ir/buffer.h"
#include "cinn/ir/ir.h"
#include "cinn/ir/tensor.h"

namespace cinn {
namespace ir {

struct ExternOp : public _Operation_ {
//! The input tensors.
std::vector<Tensor> inputs;
//! Symbolic placeholder representation of inputs.
std::vector<Buffer> input_placeholders;
//! Symbolic placeholder representation of outputs.
std::vector<Buffer> output_placeholders;
//! The statement that generates the computation.
Stmt body;

ExternOp() = default;

static Operation Make(std::string name,
std::string tag,
std::map<std::string, IrNodeRef> attrs,
std::vector<Tensor> inputs,
std::vector<Buffer> input_placeholders,
std::vector<Buffer> output_placeholders,
Stmt body);
};

/**
* @brief A placeholder op represents an input placeholder.
*/
struct PlaceholderOp : public _Operation_ {
//! The shape of the input.
std::vector<Expr> shape;
//! The data type of the input.
Type dtype;

static Operation Make(std::string name, std::vector<Expr> shape, Type dtype) {
auto n = common::make_shared<PlaceholderOp>();
n->name = name;
n->shape = shape;
n->dtype = dtype;
return Operation(n);
}
};

/**
* @brief A Compute op that compute a tensor on certain domain.
*/
struct ComputeOp : public _Operation_ {
//! Vars on each axis.
std::vector<Var> axis;
//! Var on each reduction axis, if the body is a Reduction.
std::vector<Var> reduce_axis;
//! The compute expression.
std::vector<Expr> body;

ComputeOp() = default;

static Operation Make(std::string name,
std::string tag,
std::map<std::string, IrNodeRef> attrs,
std::vector<Var> axis,
std::vector<Expr> body) {
auto n = common::make_shared<ComputeOp>();
n->name = std::move(name);
n->tag = std::move(tag);
n->attrs = std::move(attrs);
n->body = std::move(body);
return Operation(n);
}
};

} // namespace ir
} // namespace cinn
1 change: 0 additions & 1 deletion cinn/ir/tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace cinn {
namespace ir {

Tensor::Tensor(const std::vector<Var> &shape, Type type) : IrNodeRef(common::make_shared<_Tensor_>()) {
LOG(INFO) << "tensor to set type " << type;
operator->()->shape.clear();
for (auto &v : shape) {
operator->()->shape.push_back(Expr(v));
Expand Down
4 changes: 2 additions & 2 deletions cinn/ir/tensor.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <unordered_map>
#include <map>
#include "cinn/common/graph_utils.h"
#include "cinn/ir/function_base.h"
#include "cinn/ir/ir.h"
Expand Down Expand Up @@ -129,7 +129,7 @@ class _Operation_ : public ir::FunctionBase {
//! Optional tag of the operation.
std::string tag;
//! Additional attributes of the operation.
std::unordered_map<std::string, IrNodeRef> attrs;
std::map<std::string, IrNodeRef> attrs;

const std::string& func_name() const final { return name; }
};
Expand Down

0 comments on commit 408878c

Please sign in to comment.