xref: /aosp_15_r20/external/pytorch/torch/csrc/jit/passes/inplace_check.cpp (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #include <torch/csrc/jit/passes/inplace_check.h>
2 
3 namespace torch::jit {
4 
CheckInplace(Block * block)5 static void CheckInplace(Block* block) {
6   for (auto node : block->nodes()) {
7     if (node->kind() == prim::PythonOp && node->hasAttribute(attr::inplace)) {
8       if (node->i(attr::inplace)) {
9         throw std::runtime_error(
10             std::string("inplace ") + static_cast<PythonOp*>(node)->name() +
11             " not supported in the JIT");
12       }
13     }
14   }
15 }
16 
CheckInplace(std::shared_ptr<Graph> & graph)17 void CheckInplace(std::shared_ptr<Graph>& graph) {
18   CheckInplace(graph->block());
19 }
20 
21 } // namespace torch::jit
22