-
Notifications
You must be signed in to change notification settings - Fork 575
Expand file tree
/
Copy pathir_builder.h
More file actions
85 lines (77 loc) · 3.49 KB
/
Copy pathir_builder.h
File metadata and controls
85 lines (77 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef XLA_TORCH_XLA_CSRC_IR_BUILDER_H_
#define XLA_TORCH_XLA_CSRC_IR_BUILDER_H_
#include <torch/csrc/lazy/core/ir.h>
#include <torch/csrc/lazy/core/ir_builder.h>
#include "torch_xla/csrc/aten_xla_bridge.h"
#include "torch_xla/csrc/device.h"
#include "torch_xla/csrc/ops/as_strided.h"
#include "torch_xla/csrc/ops/cast.h"
#include "torch_xla/csrc/ops/device_data.h"
#include "torch_xla/csrc/ops/diagonal.h"
#include "torch_xla/csrc/ops/dynamic_ir.h"
#include "torch_xla/csrc/ops/expand.h"
#include "torch_xla/csrc/ops/generic.h"
#include "torch_xla/csrc/ops/ops.h"
#include "torch_xla/csrc/runtime/debug_macros.h"
#include "torch_xla/csrc/tensor_util.h"
namespace torch_xla {
struct XLAIrBuilder : torch::lazy::IrBuilder {
torch::lazy::NodePtr MakeDeviceData(
const std::shared_ptr<torch::lazy::BackendData>& data) const override {
return torch_xla::MakeNode<DeviceData>(data);
}
torch::lazy::NodePtr MakeScalar(const at::Scalar& value,
const at::ScalarType& type) const override {
XLA_ASSIGN_OR_THROW(const torch::lazy::BackendDevice* default_device,
bridge::GetDefaultDevice());
return torch_xla::MakeNode<Scalar>(
value, MakeXlaPrimitiveType(type, default_device));
}
torch::lazy::NodePtr MakeExpand(const torch::lazy::Value& input0,
const std::vector<int64_t>& size,
const bool& is_scalar_expand) const override {
// TODO(JackCaoG): handle is_scalar_expand
return torch_xla::MakeNode<Expand>(input0, size);
}
torch::lazy::NodePtr MakeCast(const torch::lazy::Value& input0,
const at::ScalarType& dtype,
const std::optional<at::ScalarType>& stype =
std::nullopt) const override {
return torch_xla::MakeNode<Cast>(input0, dtype, stype);
}
torch::lazy::NodePtr MakeTensorList(
const torch::lazy::OpList& inputs) const override {
// TODO(JackCaoG): implement tensorList IR. This is used by codegen.
XLA_ERROR() << "Need to implement";
return nullptr;
}
// Generic needs cleanup
torch::lazy::NodePtr MakeGeneric(
const torch::lazy::OpKind& op, const torch::lazy::OpList& operands,
const torch::lazy::Shape& shape, const size_t& num_outputs = 1,
const torch::lazy::hash_t& hash_seed =
static_cast<uint32_t>(0x5a2d296e9)) const override {
// TODO(JackCaoG): ltc generic op does not take lowering function
// return torch_xla::MakeNode<Generic>(
// op, operands, MakeXlaShapeFromLazyShape(shape,
// *bridge::GetDefaultDevice()), num_outputs, hash_seed);
}
torch::lazy::NodePtr MakeSizeNode(const torch::lazy::Value& input,
size_t dim) const override {
return torch_xla::MakeNode<SizeNode>(input, dim);
}
torch::lazy::NodePtr MakeSizeAdd(const torch::lazy::Value& a,
const torch::lazy::Value& b) const override {
return torch_xla::MakeNode<SizeAdd>(a, b);
}
torch::lazy::NodePtr MakeSizeMul(const torch::lazy::Value& a,
const torch::lazy::Value& b) const override {
return torch_xla::MakeNode<SizeMul>(a, b);
}
torch::lazy::NodePtr MakeSizeDiv(const torch::lazy::Value& a,
const torch::lazy::Value& b) const override {
return torch_xla::MakeNode<SizeDiv>(a, b);
}
};
} // namespace torch_xla
#endif // XLA_TORCH_XLA_CSRC_IR_BUILDER_H_