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 <map>
#include <unordered_map>
#include <vector>
#include <torch/csrc/Export.h>
#include <torch/csrc/jit/tensorexpr/mem_dependency_checker.h>
namespace torch {
namespace jit {
namespace tensorexpr {
class Expr;
class Buf;
class Stmt;
enum C10_API_ENUM TensorAccessKind { kLoad, kStore, kMutate };
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
struct TORCH_API TensorAccessBoundsInfo {
TensorAccessKind kind;
std::vector<ExprPtr> start;
std::vector<ExprPtr> stop;
};
using BoundsInfo =
std::unordered_map<BufPtr, std::vector<TensorAccessBoundsInfo>>;
TORCH_API BoundsInfo inferBounds(StmtPtr s, bool distinctAccessKinds = true);
// Bounds inference caching the analysis. The MemDependencyChecker must already
// have been run.
TORCH_API BoundsInfo getInferredBounds(
analysis::MemDependencyChecker& analyzer,
StmtPtr s,
bool distinctAccessKinds = true);
TORCH_API BoundsInfo getInferredBounds(
analysis::MemDependencyChecker& analyzer,
ExprPtr e,
bool distinctAccessKinds = true);
TORCH_API void printBoundsInfo(const BoundsInfo& v);
TORCH_API std::vector<ExprPtr> getBoundExtents(
const std::vector<TensorAccessBoundsInfo>& infos);
// The kind of dependency found, in increasing order of exclusivity.
enum class HazardKind {
ReadAfterWrite,
WriteAfterRead,
WriteAfterWrite,
NoDependency,
};
TORCH_API HazardKind getPotentialHazards(
analysis::MemDependencyChecker& analyzer,
StmtPtr A,
StmtPtr B);
// Returns true if there is a conflicting overlap between accesses in
// statements A and B. A conflicting overlap is an overlap in buffer accesses
// where at least one of the accesses is a Store.
TORCH_API bool hasConflictingOverlap(
analysis::MemDependencyChecker& analyzer,
StmtPtr A,
StmtPtr B);
// Same as above, between accesses in stores S1 and S2.
TORCH_API bool isOverlapping(
analysis::MemDependencyChecker& analyzer,
StorePtr S1,
StorePtr S2);
// Same as above, between accesses in store S and load L.
TORCH_API bool isOverlapping(
analysis::MemDependencyChecker& analyzer,
StorePtr S,
LoadPtr L);
} // namespace tensorexpr
} // namespace jit
} // namespace torch
|