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
|
#pragma once
#include <ostream>
#include <vector>
#include <c10/core/Scalar.h>
#include <torch/csrc/jit/passes/symbolic_shape_analysis.h>
#include <torch/csrc/lazy/core/hash.h>
C10_DECLARE_bool(ltc_enable_symbolic_shapes);
namespace torch {
namespace lazy {
class TORCH_API Shape {
public:
Shape() = default;
Shape(
at::ScalarType scalar_type,
c10::ArrayRef<int64_t> sizes,
c10::optional<std::vector<bool>> is_symbolic = c10::nullopt);
std::string to_string() const;
c10::ScalarType scalar_type() const {
return scalar_type_;
}
void set_scalar_type(at::ScalarType value) {
scalar_type_ = value;
}
int64_t dim() const {
return sizes_.size();
}
c10::ArrayRef<int64_t> sizes() const {
return sizes_;
}
int64_t size(int64_t dim) const {
return sizes_.at(dim);
}
void set_size(int64_t dim, int64_t size) {
sizes_.at(dim) = size;
}
const c10::optional<std::vector<bool>>& is_symbolic() const {
return is_symbolic_;
}
// Makes a copy with symbolic dims applied
Shape with_symbolic_dims(
c10::optional<std::vector<bool>> symbolic_dims) const;
size_t numel() const;
hash_t hash(bool bakeInSizes) const;
bool operator==(const Shape& other) const;
private:
c10::ScalarType scalar_type_{c10::ScalarType::Undefined};
// Sizes are the upper bound sizes for a tensor, used by XLA.
std::vector<int64_t> sizes_;
// Stores which dimmensions are symbolic
// If nullopt, either it hasn't been initialized or the symbolic
// dimmensions are not calculatable
c10::optional<std::vector<bool>> is_symbolic_ = c10::nullopt;
};
TORCH_API std::ostream& operator<<(std::ostream& out, const Shape& shape);
TORCH_API bool symbolicShapeEnabled();
// Calculate and applies symbolic shapes onto the
// Shape objects passed to result_shapes
TORCH_API void applySymbolicShapesOnLT(
const char* schema_str,
std::vector<c10::IValue> args,
std::vector<Shape>& result_shapes);
} // namespace lazy
} // namespace torch
|