lcompilers / lc

C++ compiler
MIT License
26 stars 7 forks source link

Initial support for PyTorch C++ API #116

Closed czgdp1807 closed 5 months ago

czgdp1807 commented 5 months ago

LC parses the AST of integration_tests/pytorch_01.cpp as follows,

|-FunctionDecl 0x13ebd1a78 </Users/czgdp1807/lc_project/lc/integration_tests/pytorch_01.cpp:4:1, line:10:1> line:4:6 used check 'void (const torch::Tensor &)'
| |-ParmVarDecl 0x13ebd16d0 <col:12, col:56> col:33 used tensor 'const torch::Tensor &' cinit
| | `-ExprWithCleanups 0x13ebd1a00 <col:40, col:56> 'const at::Tensor':'const at::Tensor' lvalue
| |   `-MaterializeTemporaryExpr 0x13ebd19e8 <col:40, col:56> 'const at::Tensor':'const at::Tensor' lvalue
| |     `-ImplicitCastExpr 0x13ebd19d0 <col:40, col:56> 'const at::Tensor':'const at::Tensor' <NoOp>
| |       `-CXXBindTemporaryExpr 0x13ebd19b0 <col:40, col:56> 'at::Tensor':'at::Tensor' (CXXTemporary 0x13ebd19b0)
| |         `-CallExpr 0x13ebd1858 <col:40, col:56> 'at::Tensor':'at::Tensor'
| |           |-ImplicitCastExpr 0x13ebd1840 <col:40, col:47> 'at::Tensor (*)(at::IntArrayRef, at::TensorOptions, c10::optional<at::MemoryFormat>)' <FunctionToPointerDecay>
| |           | `-DeclRefExpr 0x13ebd1810 <col:40, col:47> 'at::Tensor (at::IntArrayRef, at::TensorOptions, c10::optional<at::MemoryFormat>)' lvalue Function 0x154f5be28 'empty' 'at::Tensor (at::IntArrayRef, at::TensorOptions, c10::optional<at::MemoryFormat>)'
| |           |-CXXConstructExpr 0x13ebd1938 <col:53, col:55> 'at::IntArrayRef':'c10::ArrayRef<long long>' 'void (const std::initializer_list<long long> &)' list std::initializer_list
| |           | `-MaterializeTemporaryExpr 0x13ebd1920 <col:53, col:55> 'const std::initializer_list<long long>':'const std::initializer_list<long long>' lvalue
| |           |   `-CXXStdInitializerListExpr 0x13ebd1908 <col:53, col:55> 'const std::initializer_list<long long>':'const std::initializer_list<long long>'
| |           |     `-MaterializeTemporaryExpr 0x13ebd18f0 <col:53, col:55> 'const long long[1]' xvalue
| |           |       `-InitListExpr 0x13ebd1890 <col:53, col:55> 'const long long[1]'
| |           |         `-ImplicitCastExpr 0x13ebd18d8 <col:54> 'const long long' <IntegralCast>
| |           |           `-IntegerLiteral 0x13ebd17a8 <col:54> 'int' 1
| |           |-CXXDefaultArgExpr 0x13ebd1968 <<invalid sloc>> 'at::TensorOptions':'c10::TensorOptions'
| |           `-CXXDefaultArgExpr 0x13ebd1988 <<invalid sloc>> 'c10::optional<at::MemoryFormat>':'std::optional<c10::MemoryFormat>'
| `-CompoundStmt 0x13ebd7428 <col:59, line:10:1>
|   |-DeclStmt 0x13ebd1e20 <line:5:5, col:48>
|   | `-VarDecl 0x13ebd1bd0 <col:5, col:47> col:11 used array 'float[5]' cinit
|   |   `-InitListExpr 0x13ebd1d40 <col:22, col:47> 'float[5]'
|   |     |-ImplicitCastExpr 0x13ebd1da8 <col:23> 'float' <FloatingCast>
|   |     | `-FloatingLiteral 0x13ebd1c38 <col:23> 'double' 4.000000e+00
|   |     |-ImplicitCastExpr 0x13ebd1dc0 <col:28> 'float' <FloatingCast>
|   |     | `-FloatingLiteral 0x13ebd1c58 <col:28> 'double' 2.000000e+00
|   |     |-ImplicitCastExpr 0x13ebd1dd8 <col:33> 'float' <FloatingCast>
|   |     | `-FloatingLiteral 0x13ebd1c78 <col:33> 'double' 2.000000e+00
|   |     |-ImplicitCastExpr 0x13ebd1df0 <col:38> 'float' <FloatingCast>
|   |     | `-FloatingLiteral 0x13ebd1c98 <col:38> 'double' 1.200000e+01
|   |     `-ImplicitCastExpr 0x13ebd1e08 <col:44> 'float' <FloatingCast>
|   |       `-FloatingLiteral 0x13ebd1cb8 <col:44> 'double' 2.000000e+00
|   |-CXXOperatorCallExpr 0x13ebd4a10 <line:6:5, col:33> 'ostream':'std::ostream' lvalue '<<'
|   | |-ImplicitCastExpr 0x13ebd49f8 <col:25> 'ostream &(*)(ostream &(*)(ostream &))' <FunctionToPointerDecay>
|   | | `-DeclRefExpr 0x13ebd49d8 <col:25> 'ostream &(ostream &(*)(ostream &))' lvalue CXXMethod 0x128e2bcf0 'operator<<' 'ostream &(ostream &(*)(ostream &))'
|   | |-CXXOperatorCallExpr 0x13ebd3470 <col:5, col:18> 'std::ostream':'std::ostream' lvalue '<<' adl
|   | | |-ImplicitCastExpr 0x13ebd3458 <col:15> 'std::ostream &(*)(std::ostream &, const Tensor &)' <FunctionToPointerDecay>
|   | | | `-DeclRefExpr 0x13ebd33d8 <col:15> 'std::ostream &(std::ostream &, const Tensor &)' lvalue Function 0x14c25cd10 'operator<<' 'std::ostream &(std::ostream &, const Tensor &)'
|   | | |-DeclRefExpr 0x13ebd1e88 <col:5, col:10> 'ostream':'std::ostream' lvalue Var 0x12a69c720 'cout' 'ostream':'std::ostream'
|   | | `-DeclRefExpr 0x13ebd1eb8 <col:18> 'const torch::Tensor':'const at::Tensor' lvalue ParmVar 0x13ebd16d0 'tensor' 'const torch::Tensor &'
|   | `-ImplicitCastExpr 0x13ebd49c0 <col:28, col:33> 'basic_ostream<char, char_traits<char>> &(*)(basic_ostream<char, char_traits<char>> &)' <FunctionToPointerDecay>
|   |   `-DeclRefExpr 0x13ebd4988 <col:28, col:33> 'basic_ostream<char, char_traits<char>> &(basic_ostream<char, char_traits<char>> &)' lvalue Function 0x138b44cd8 'endl' 'basic_ostream<char, char_traits<char>> &(basic_ostream<char, char_traits<char>> &)' (FunctionTemplate 0x128e21290 'endl')
|   `-IfStmt 0x13ebd7408 <line:7:5, line:9:5>
|     |-ExprWithCleanups 0x13ebd7310 <line:7:9, col:89> 'bool':'bool'
|     | `-CXXMemberCallExpr 0x13ebd72d8 <col:9, col:89> 'bool':'bool'
|     |   `-MemberExpr 0x13ebd7260 <col:9, col:87> '<bound member function type>' .item 0x1549c0358
|     |     `-ImplicitCastExpr 0x13ebd72f8 <col:9, col:76> 'const at::Tensor' xvalue <NoOp>
|     |       `-MaterializeTemporaryExpr 0x13ebd7100 <col:9, col:76> 'at::Tensor':'at::Tensor' xvalue
|     |         `-CXXBindTemporaryExpr 0x13ebd70d0 <col:9, col:76> 'at::Tensor':'at::Tensor' (CXXTemporary 0x13ebd70d0)
|     |           `-CallExpr 0x13ebd7070 <col:9, col:76> 'at::Tensor':'at::Tensor'
|     |             |-ImplicitCastExpr 0x13ebd7058 <col:9, col:16> 'at::Tensor (*)(const at::Tensor &)' <FunctionToPointerDecay>
|     |             | `-DeclRefExpr 0x13ebd7000 <col:9, col:16> 'at::Tensor (const at::Tensor &)' lvalue Function 0x14d8f0b08 'any' 'at::Tensor (const at::Tensor &)'
|     |             `-MaterializeTemporaryExpr 0x13ebd70b0 <col:20, col:72> 'const Tensor':'const at::Tensor' lvalue
|     |               `-ImplicitCastExpr 0x13ebd7098 <col:20, col:72> 'const Tensor':'const at::Tensor' <NoOp>
|     |                 `-CXXBindTemporaryExpr 0x13ebd6fe0 <col:20, col:72> 'Tensor':'at::Tensor' (CXXTemporary 0x13ebd6fe0)
|     |                   `-CXXOperatorCallExpr 0x13ebd6fa0 <col:20, col:72> 'Tensor':'at::Tensor' '>' adl
|     |                     |-ImplicitCastExpr 0x13ebd6f88 <col:70> 'Tensor (*)(const Tensor &, const Scalar &)' <FunctionToPointerDecay>
|     |                     | `-DeclRefExpr 0x13ebd6f38 <col:70> 'Tensor (const Tensor &, const Scalar &)' lvalue Function 0x154a07ea8 'operator>' 'Tensor (const Tensor &, const Scalar &)'
|     |                     |-MaterializeTemporaryExpr 0x13ebd6888 <col:20, col:68> 'const at::Tensor':'const at::Tensor' lvalue
|     |                     | `-ImplicitCastExpr 0x13ebd6870 <col:20, col:68> 'const at::Tensor':'const at::Tensor' <NoOp>
|     |                     |   `-CXXBindTemporaryExpr 0x13ebd5bf0 <col:20, col:68> 'at::Tensor':'at::Tensor' (CXXTemporary 0x13ebd5bf0)
|     |                     |     `-CallExpr 0x13ebd5b90 <col:20, col:68> 'at::Tensor':'at::Tensor'
|     |                     |       |-ImplicitCastExpr 0x13ebd5b78 <col:20, col:27> 'at::Tensor (*)(const at::Tensor &)' <FunctionToPointerDecay>
|     |                     |       | `-DeclRefExpr 0x13ebd4ae8 <col:20, col:27> 'at::Tensor (const at::Tensor &)' lvalue Function 0x14d839608 'abs' 'at::Tensor (const at::Tensor &)'
|     |                     |       `-MaterializeTemporaryExpr 0x13ebd5bd0 <col:31, col:67> 'const Tensor':'const at::Tensor' lvalue
|     |                     |         `-ImplicitCastExpr 0x13ebd5bb8 <col:31, col:67> 'const Tensor':'const at::Tensor' <NoOp>
|     |                     |           `-CXXBindTemporaryExpr 0x13ebd5b58 <col:31, col:67> 'Tensor':'at::Tensor' (CXXTemporary 0x13ebd5b58)
|     |                     |             `-CXXOperatorCallExpr 0x13ebd5b18 <col:31, col:67> 'Tensor':'at::Tensor' '-' adl
|     |                     |               |-ImplicitCastExpr 0x13ebd5b00 <col:38> 'Tensor (*)(const Tensor &, const Tensor &)' <FunctionToPointerDecay>
|     |                     |               | `-DeclRefExpr 0x13ebd5ae0 <col:38> 'Tensor (const Tensor &, const Tensor &)' lvalue Function 0x1549f8a00 'operator-' 'Tensor (const Tensor &, const Tensor &)'
|     |                     |               |-DeclRefExpr 0x13ebd4b18 <col:31> 'const torch::Tensor':'const at::Tensor' lvalue ParmVar 0x13ebd16d0 'tensor' 'const torch::Tensor &'
|     |                     |               `-MaterializeTemporaryExpr 0x13ebd5ac8 <col:40, col:67> 'const at::Tensor':'const at::Tensor' lvalue
|     |                     |                 `-ImplicitCastExpr 0x13ebd5ab0 <col:40, col:67> 'const at::Tensor':'const at::Tensor' <NoOp>
|     |                     |                   `-CXXBindTemporaryExpr 0x13ebd4e18 <col:40, col:67> 'at::Tensor':'at::Tensor' (CXXTemporary 0x13ebd4e18)
|     |                     |                     `-CallExpr 0x13ebd4cb0 <col:40, col:67> 'at::Tensor':'at::Tensor'
|     |                     |                       |-ImplicitCastExpr 0x13ebd4c98 <col:40, col:47> 'at::Tensor (*)(void *, at::IntArrayRef, const at::TensorOptions &)' <FunctionToPointerDecay>
|     |                     |                       | `-DeclRefExpr 0x13ebd4c40 <col:40, col:47> 'at::Tensor (void *, at::IntArrayRef, const at::TensorOptions &)' lvalue Function 0x154f1a4a8 'from_blob' 'at::Tensor (void *, at::IntArrayRef, const at::TensorOptions &)'
|     |                     |                       |-ImplicitCastExpr 0x13ebd4d00 <col:57> 'void *' <BitCast>
|     |                     |                       | `-ImplicitCastExpr 0x13ebd4ce8 <col:57> 'float *' <ArrayToPointerDecay>
|     |                     |                       |   `-DeclRefExpr 0x13ebd4bb8 <col:57> 'float[5]' lvalue Var 0x13ebd1bd0 'array' 'float[5]'
|     |                     |                       |-CXXConstructExpr 0x13ebd4dc0 <col:64, col:66> 'at::IntArrayRef':'c10::ArrayRef<long long>' 'void (const std::initializer_list<long long> &)' list std::initializer_list
|     |                     |                       | `-MaterializeTemporaryExpr 0x13ebd4da8 <col:64, col:66> 'const std::initializer_list<long long>':'const std::initializer_list<long long>' lvalue
|     |                     |                       |   `-CXXStdInitializerListExpr 0x13ebd4d90 <col:64, col:66> 'const std::initializer_list<long long>':'const std::initializer_list<long long>'
|     |                     |                       |     `-MaterializeTemporaryExpr 0x13ebd4d78 <col:64, col:66> 'const long long[1]' xvalue
|     |                     |                       |       `-InitListExpr 0x13ebd4d18 <col:64, col:66> 'const long long[1]'
|     |                     |                       |         `-ImplicitCastExpr 0x13ebd4d60 <col:65> 'const long long' <IntegralCast>
|     |                     |                       |           `-IntegerLiteral 0x13ebd4bd8 <col:65> 'int' 5
|     |                     |                       `-CXXDefaultArgExpr 0x13ebd4df0 <<invalid sloc>> 'const at::TensorOptions':'const c10::TensorOptions' lvalue
|     |                     `-MaterializeTemporaryExpr 0x13ebd6f20 <col:72> 'const Scalar':'const c10::Scalar' lvalue
|     |                       `-CXXBindTemporaryExpr 0x13ebd6f00 <col:72> 'const Scalar':'const c10::Scalar' (CXXTemporary 0x13ebd6f00)
|     |                         `-CXXConstructExpr 0x13ebd6ec8 <col:72> 'const Scalar':'const c10::Scalar' 'void (double)'
|     |                           `-FloatingLiteral 0x13ebd5c10 <col:72> 'double' 1.000000e-06
|     `-CompoundStmt 0x13ebd73f0 <col:93, line:9:5>
|       `-CallExpr 0x13ebd73c8 <line:8:7, col:13> 'void'
|         |-ImplicitCastExpr 0x13ebd73b0 <col:7> 'void (*)(int) __attribute__((noreturn))' <FunctionToPointerDecay>
|         | `-DeclRefExpr 0x13ebd7390 <col:7> 'void (int) __attribute__((noreturn))' lvalue Function 0x141218db8 'exit' 'void (int) __attribute__((noreturn))'
|         `-IntegerLiteral 0x13ebd7370 <col:12> 'int' 2
`-FunctionDecl 0x13ebd7478 <line:12:1, line:19:1> line:12:5 main 'int ()'
  `-CompoundStmt 0x13ebde810 <col:12, line:19:1>
    |-DeclStmt 0x13ebd8698 <line:13:5, col:42>
    | `-VarDecl 0x13ebd75c8 <col:5, col:41> col:19 used tensor 'torch::Tensor':'at::Tensor' cinit destroyed
    |   `-ExprWithCleanups 0x13ebd8680 <col:28, col:41> 'at::Tensor':'at::Tensor'
    |     `-CXXBindTemporaryExpr 0x13ebd8660 <col:28, col:41> 'at::Tensor':'at::Tensor' (CXXTemporary 0x13ebd8660)
    |       `-CallExpr 0x13ebd7e60 <col:28, col:41> 'at::Tensor':'at::Tensor'
    |         |-ImplicitCastExpr 0x13ebd7e48 <col:28, col:35> 'at::Tensor (*)(at::IntArrayRef, at::TensorOptions)' <FunctionToPointerDecay>
    |         | `-DeclRefExpr 0x13ebd7df0 <col:28, col:35> 'at::Tensor (at::IntArrayRef, at::TensorOptions)' lvalue Function 0x155057e08 'ones' 'at::Tensor (at::IntArrayRef, at::TensorOptions)'
    |         |-ImplicitCastExpr 0x13ebd8620 <col:40> 'at::IntArrayRef':'c10::ArrayRef<long long>' <ConstructorConversion>
    |         | `-CXXConstructExpr 0x13ebd85f0 <col:40> 'at::IntArrayRef':'c10::ArrayRef<long long>' 'void (const long long &)'
    |         |   `-MaterializeTemporaryExpr 0x13ebd85d8 <col:40> 'const long long':'const long long' lvalue
    |         |     `-ImplicitCastExpr 0x13ebd85c0 <col:40> 'const long long':'const long long' <IntegralCast>
    |         |       `-IntegerLiteral 0x13ebd76a0 <col:40> 'int' 5
    |         `-CXXDefaultArgExpr 0x13ebd8638 <<invalid sloc>> 'at::TensorOptions':'c10::TensorOptions'
    |-ExprWithCleanups 0x13ebd9ac8 <line:14:5, col:17> 'Tensor':'at::Tensor' lvalue
    | `-CXXOperatorCallExpr 0x13ebd9a90 <col:5, col:17> 'Tensor':'at::Tensor' lvalue '='
    |   |-ImplicitCastExpr 0x13ebd9a78 <col:15> 'Tensor &(*)(const Scalar &) &&' <FunctionToPointerDecay>
    |   | `-DeclRefExpr 0x13ebd9a58 <col:15> 'Tensor &(const Scalar &) &&' lvalue CXXMethod 0x149f2d3f0 'operator=' 'Tensor &(const Scalar &) &&'
    |   |-MaterializeTemporaryExpr 0x13ebd9a40 <col:5, col:13> 'Tensor':'at::Tensor' xvalue
    |   | `-CXXBindTemporaryExpr 0x13ebd8d98 <col:5, col:13> 'Tensor':'at::Tensor' (CXXTemporary 0x13ebd8d98)
    |   |   `-CXXOperatorCallExpr 0x13ebd8d58 <col:5, col:13> 'Tensor':'at::Tensor' '[]'
    |   |     |-ImplicitCastExpr 0x13ebd8d40 <col:11, col:13> 'Tensor (*)(int64_t) const' <FunctionToPointerDecay>
    |   |     | `-DeclRefExpr 0x13ebd8d20 <col:11, col:13> 'Tensor (int64_t) const' lvalue CXXMethod 0x149f311c8 'operator[]' 'Tensor (int64_t) const'
    |   |     |-ImplicitCastExpr 0x13ebd8cf0 <col:5> 'const at::Tensor' lvalue <NoOp>
    |   |     | `-DeclRefExpr 0x13ebd86b0 <col:5> 'torch::Tensor':'at::Tensor' lvalue Var 0x13ebd75c8 'tensor' 'torch::Tensor':'at::Tensor'
    |   |     `-ImplicitCastExpr 0x13ebd8d08 <col:12> 'int64_t':'long long' <IntegralCast>
    |   |       `-IntegerLiteral 0x13ebd86d0 <col:12> 'int' 0
    |   `-MaterializeTemporaryExpr 0x13ebd9a28 <col:17> 'const Scalar':'const c10::Scalar' lvalue
    |     `-CXXBindTemporaryExpr 0x13ebd9a08 <col:17> 'const Scalar':'const c10::Scalar' (CXXTemporary 0x13ebd9a08)
    |       `-CXXConstructExpr 0x13ebd99d0 <col:17> 'const Scalar':'const c10::Scalar' 'void (double)'
    |         `-FloatingLiteral 0x13ebd8db8 <col:17> 'double' 2.000000e+00
    |-ExprWithCleanups 0x13ebdaef8 <line:15:5, col:17> 'Tensor':'at::Tensor' lvalue
    | `-CXXOperatorCallExpr 0x13ebdaec0 <col:5, col:17> 'Tensor':'at::Tensor' lvalue '='
    |   |-ImplicitCastExpr 0x13ebdaea8 <col:15> 'Tensor &(*)(const Scalar &) &&' <FunctionToPointerDecay>
    |   | `-DeclRefExpr 0x13ebdae88 <col:15> 'Tensor &(const Scalar &) &&' lvalue CXXMethod 0x149f2d3f0 'operator=' 'Tensor &(const Scalar &) &&'
    |   |-MaterializeTemporaryExpr 0x13ebdae70 <col:5, col:13> 'Tensor':'at::Tensor' xvalue
    |   | `-CXXBindTemporaryExpr 0x13ebda1c8 <col:5, col:13> 'Tensor':'at::Tensor' (CXXTemporary 0x13ebda1c8)
    |   |   `-CXXOperatorCallExpr 0x13ebda188 <col:5, col:13> 'Tensor':'at::Tensor' '[]'
    |   |     |-ImplicitCastExpr 0x13ebda170 <col:11, col:13> 'Tensor (*)(int64_t) const' <FunctionToPointerDecay>
    |   |     | `-DeclRefExpr 0x13ebda150 <col:11, col:13> 'Tensor (int64_t) const' lvalue CXXMethod 0x149f311c8 'operator[]' 'Tensor (int64_t) const'
    |   |     |-ImplicitCastExpr 0x13ebda120 <col:5> 'const at::Tensor' lvalue <NoOp>
    |   |     | `-DeclRefExpr 0x13ebd9ae0 <col:5> 'torch::Tensor':'at::Tensor' lvalue Var 0x13ebd75c8 'tensor' 'torch::Tensor':'at::Tensor'
    |   |     `-ImplicitCastExpr 0x13ebda138 <col:12> 'int64_t':'long long' <IntegralCast>
    |   |       `-IntegerLiteral 0x13ebd9b00 <col:12> 'int' 3
    |   `-MaterializeTemporaryExpr 0x13ebdae58 <col:17> 'const Scalar':'const c10::Scalar' lvalue
    |     `-CXXBindTemporaryExpr 0x13ebdae38 <col:17> 'const Scalar':'const c10::Scalar' (CXXTemporary 0x13ebdae38)
    |       `-CXXConstructExpr 0x13ebdae00 <col:17> 'const Scalar':'const c10::Scalar' 'void (double)'
    |         `-FloatingLiteral 0x13ebda1e8 <col:17> 'double' 6.000000e+00
    |-ExprWithCleanups 0x13ebdbd48 <line:16:5, col:18> 'Tensor':'at::Tensor' lvalue
    | `-CXXOperatorCallExpr 0x13ebdbce0 <col:5, col:18> 'Tensor':'at::Tensor' lvalue '='
    |   |-ImplicitCastExpr 0x13ebdbcc8 <col:12> 'Tensor &(*)(Tensor &&) & noexcept' <FunctionToPointerDecay>
    |   | `-DeclRefExpr 0x13ebdbca8 <col:12> 'Tensor &(Tensor &&) & noexcept' lvalue CXXMethod 0x149f2d188 'operator=' 'Tensor &(Tensor &&) & noexcept'
    |   |-DeclRefExpr 0x13ebdaf10 <col:5> 'torch::Tensor':'at::Tensor' lvalue Var 0x13ebd75c8 'tensor' 'torch::Tensor':'at::Tensor'
    |   `-MaterializeTemporaryExpr 0x13ebdbc90 <col:14, col:18> 'Tensor':'at::Tensor' xvalue
    |     `-CXXBindTemporaryExpr 0x13ebdbc70 <col:14, col:18> 'Tensor':'at::Tensor' (CXXTemporary 0x13ebdbc70)
    |       `-CXXOperatorCallExpr 0x13ebdbc30 <col:14, col:18> 'Tensor':'at::Tensor' '*' adl
    |         |-ImplicitCastExpr 0x13ebdbc18 <col:16> 'Tensor (*)(const Scalar &, const Tensor &)' <FunctionToPointerDecay>
    |         | `-DeclRefExpr 0x13ebdbbf8 <col:16> 'Tensor (const Scalar &, const Tensor &)' lvalue Function 0x1549f86a8 'operator*' 'Tensor (const Scalar &, const Tensor &)'
    |         |-MaterializeTemporaryExpr 0x13ebdbbc8 <col:14> 'const Scalar':'const c10::Scalar' lvalue
    |         | `-CXXBindTemporaryExpr 0x13ebdbba8 <col:14> 'const Scalar':'const c10::Scalar' (CXXTemporary 0x13ebdbba8)
    |         |   `-CXXConstructExpr 0x13ebdbb70 <col:14> 'const Scalar':'const c10::Scalar' 'void (int)'
    |         |     `-IntegerLiteral 0x13ebdaf30 <col:14> 'int' 2
    |         `-ImplicitCastExpr 0x13ebdbbe0 <col:18> 'const Tensor':'const at::Tensor' lvalue <NoOp>
    |           `-DeclRefExpr 0x13ebdaf50 <col:18> 'torch::Tensor':'at::Tensor' lvalue Var 0x13ebd75c8 'tensor' 'torch::Tensor':'at::Tensor'
    |-CallExpr 0x13ebdbe30 <line:17:5, col:17> 'void'
    | |-ImplicitCastExpr 0x13ebdbe18 <col:5> 'void (*)(const torch::Tensor &)' <FunctionToPointerDecay>
    | | `-DeclRefExpr 0x13ebdbdc8 <col:5> 'void (const torch::Tensor &)' lvalue Function 0x13ebd1a78 'check' 'void (const torch::Tensor &)'
    | `-ImplicitCastExpr 0x13ebdbe58 <col:11> 'const torch::Tensor':'const at::Tensor' lvalue <NoOp>
    |   `-DeclRefExpr 0x13ebdbda8 <col:11> 'torch::Tensor':'at::Tensor' lvalue Var 0x13ebd75c8 'tensor' 'torch::Tensor':'at::Tensor'
    `-CXXOperatorCallExpr 0x13ebde7d8 <line:18:5, col:33> 'ostream':'std::ostream' lvalue '<<'
      |-ImplicitCastExpr 0x13ebde7c0 <col:25> 'ostream &(*)(ostream &(*)(ostream &))' <FunctionToPointerDecay>
      | `-DeclRefExpr 0x13ebde7a0 <col:25> 'ostream &(ostream &(*)(ostream &))' lvalue CXXMethod 0x128e2bcf0 'operator<<' 'ostream &(ostream &(*)(ostream &))'
      |-CXXOperatorCallExpr 0x13ebdd238 <col:5, col:18> 'std::ostream':'std::ostream' lvalue '<<' adl
      | |-ImplicitCastExpr 0x13ebdd220 <col:15> 'std::ostream &(*)(std::ostream &, const Tensor &)' <FunctionToPointerDecay>
      | | `-DeclRefExpr 0x13ebdd200 <col:15> 'std::ostream &(std::ostream &, const Tensor &)' lvalue Function 0x14c25cd10 'operator<<' 'std::ostream &(std::ostream &, const Tensor &)'
      | |-DeclRefExpr 0x13ebdbec0 <col:5, col:10> 'ostream':'std::ostream' lvalue Var 0x12a69c720 'cout' 'ostream':'std::ostream'
      | `-ImplicitCastExpr 0x13ebdd1e8 <col:18> 'const Tensor':'const at::Tensor' lvalue <NoOp>
      |   `-DeclRefExpr 0x13ebdbef0 <col:18> 'torch::Tensor':'at::Tensor' lvalue Var 0x13ebd75c8 'tensor' 'torch::Tensor':'at::Tensor'
      `-ImplicitCastExpr 0x13ebde788 <col:28, col:33> 'basic_ostream<char, char_traits<char>> &(*)(basic_ostream<char, char_traits<char>> &)' <FunctionToPointerDecay>
        `-DeclRefExpr 0x13ebde750 <col:28, col:33> 'basic_ostream<char, char_traits<char>> &(basic_ostream<char, char_traits<char>> &)' lvalue Function 0x138b44cd8 'endl' 'basic_ostream<char, char_traits<char>> &(basic_ostream<char, char_traits<char>> &)' (FunctionTemplate 0x128e21290 'endl')
czgdp1807 commented 5 months ago

libtorch is 160 MB in size, so unzip fails on CI. Locally tests work on my system,

1:37:38:~/lc_project/lc/integration_tests % python run_tests.py -b=pytorch
/Users/czgdp1807/lc_project/lc/integration_tests/run_tests.py:47: SyntaxWarning: invalid escape sequence '\w'
  mod = re.compile("(module|MODULE) (\w+)")
+ rm -rf /Users/czgdp1807/lc_project/lc/integration_tests/test-llvm
+ rm -rf /Users/czgdp1807/lc_project/lc/integration_tests/test-llvm2
+ rm -rf /Users/czgdp1807/lc_project/lc/integration_tests/test-llvm_rtlib
+ rm -rf /Users/czgdp1807/lc_project/lc/integration_tests/test-c
+ rm -rf /Users/czgdp1807/lc_project/lc/integration_tests/test-cpp
+ rm -rf /Users/czgdp1807/lc_project/lc/integration_tests/test-x86
+ rm -rf /Users/czgdp1807/lc_project/lc/integration_tests/test-wasm
+ rm -rf /Users/czgdp1807/lc_project/lc/integration_tests/test-gcc
+ rm -rf /Users/czgdp1807/lc_project/lc/integration_tests/test-llvmImplicit
+ rm -rf /Users/czgdp1807/lc_project/lc/integration_tests/test-llvmStackArray
+ rm -rf /Users/czgdp1807/lc_project/lc/integration_tests/test-fortran
+ rm -rf /Users/czgdp1807/lc_project/lc/integration_tests/test-c_nopragma
+ rm -rf /Users/czgdp1807/lc_project/lc/integration_tests/test-llvm_nopragma
+ rm -rf /Users/czgdp1807/lc_project/lc/integration_tests/test-pytorch
+ mkdir /Users/czgdp1807/lc_project/lc/integration_tests/test-pytorch
+ cmake -DLC_BACKEND=pytorch -DFAST=no -DCURRENT_BINARY_DIR=/Users/czgdp1807/lc_project/lc/integration_tests/test-pytorch -S /Users/czgdp1807/lc_project/lc/integration_tests -B /Users/czgdp1807/lc_project/lc/integration_tests/test-pytorch
-- The C compiler identification is AppleClang 15.0.0.15000309
-- The CXX compiler identification is AppleClang 15.0.0.15000309
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done

Configuration results
---------------------
Fortran compiler: 
C compiler      : /Library/Developer/CommandLineTools/usr/bin/cc
Build type: Debug
Fortran compiler flags: 
C compiler flags      : -g
Installation prefix: /usr/local
LC_BACKEND: pytorch
FAST: no
-- Found Torch: /Users/czgdp1807/mambaforge/envs/lc/lib/libtorch.dylib  
-- Configuring done (0.6s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/czgdp1807/lc_project/lc/integration_tests/test-pytorch
+ make -j8
[ 50%] Building CXX object CMakeFiles/pytorch_01.cpp.dir/pytorch_01.cpp.o
[100%] Linking CXX executable pytorch_01.cpp
[100%] Built target pytorch_01.cpp
+ ctest -j8 --output-on-failure
Test project /Users/czgdp1807/lc_project/lc/integration_tests/test-pytorch
    Start 1: pytorch_01.cpp
1/1 Test #1: pytorch_01.cpp ...................   Passed    0.16 sec

100% tests passed, 0 tests failed out of 1

Label Time Summary:
pytorch    =   0.16 sec*proc (1 test)

Total Test time (real) =   0.17 sec
czgdp1807 commented 5 months ago

It builds on CI, but gives SEGFAULT,

-- Found Torch: /Users/runner/micromamba/envs/lc/lib/libtorch.dylib  
-- Configuring done (3.4s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/runner/work/lc/lc/integration_tests/test-pytorch
[ 50%] Building CXX object CMakeFiles/pytorch_01.cpp.dir/pytorch_01.cpp.o
[100%] Linking CXX executable pytorch_01.cpp
ld: warning: directory not found for option '-L/Users/runner/micromamba/envs/lc/lib/intel64'
ld: warning: directory not found for option '-L/Users/runner/micromamba/envs/lc/lib/intel64_win'
ld: warning: directory not found for option '-L/Users/runner/micromamba/envs/lc/lib/win-x64'
[100%] Built target pytorch_01.cpp
Test project /Users/runner/work/lc/lc/integration_tests/test-pytorch
    Start 1: pytorch_01.cpp
Errors while running CTest
1/1 Test #1: pytorch_01.cpp ...................***Exception: SegFault  1.51 sec
czgdp1807 commented 5 months ago

So PyTorch C++ API testing works good on Linux CI. On macOS there is some issue with clang available on conda. It gives segmentation faults/bus errors. So we will test on Linux CI for now.

czgdp1807 commented 5 months ago

Okay. So the work flow is clear for PyTorch. Tomorrow I will make LC compile PyTorch C++ API code.