pytorch_sparse icon indicating copy to clipboard operation
pytorch_sparse copied to clipboard

Issue compiling with pytorch:main and gcc 11.1

Open stestagg opened this issue 3 years ago • 3 comments
trafficstars

I've been compiling this library against pytorch:main (1.11.0a0+git1b66915), using gcc 11.1 and some change (I'm assuming pytorch) is causing compile errors:

csrc/cpu/neighbor_sample_cpu.cpp:157:62: error: expected primary-expression before ‘>’ token
  157 |     const auto *input_node_data = input_node.data_ptr<int64_t>();
      |                                                              ^
csrc/cpu/neighbor_sample_cpu.cpp:157:64: error: expected primary-expression before ‘)’ token
  157 |     const auto *input_node_data = input_node.data_ptr<int64_t>();
      |                                                                ^
csrc/cpu/neighbor_sample_cpu.cpp:183:74: error: expected primary-expression before ‘>’ token
  183 | const auto *colptr_data = colptr_dict.at(rel_type).data_ptr<int64_t>();
      |                                                                    ^

csrc/cpu/neighbor_sample_cpu.cpp:183:76: error: expected primary-expression before ‘)’ token
  183 | const auto *colptr_data = colptr_dict.at(rel_type).data_ptr<int64_t>();
      |                                                                      ^

csrc/cpu/neighbor_sample_cpu.cpp:184:68: error: expected primary-expression before ‘>’ token
  184 |       const auto *row_data = row_dict.at(rel_type).data_ptr<int64_t>();
      |                                                                    ^
csrc/cpu/neighbor_sample_cpu.cpp:184:70: error: expected primary-expression before ‘)’ token
  184 |       const auto *row_data = row_dict.at(rel_type).data_ptr<int64_t>();
      |                                                                      ^
csrc/cpu/neighbor_sample_cpu.cpp:264:60: error: expected primary-expression before ‘>’ token
  264 |       const auto *colptr_data = kv.value().data_ptr<int64_t>();
      |                                                            ^
csrc/cpu/neighbor_sample_cpu.cpp:264:62: error: expected primary-expression before ‘)’ token
  264 |       const auto *colptr_data = kv.value().data_ptr<int64_t>();
      |                                                              ^
csrc/cpu/neighbor_sample_cpu.cpp:265:68: error: expected primary-expression before ‘>’ token
  265 |       const auto *row_data = row_dict.at(rel_type).data_ptr<int64_t>();
      |                                                                    ^
csrc/cpu/neighbor_sample_cpu.cpp:265:70: error: expected primary-expression before ‘)’ token
  265 |       const auto *row_data = row_dict.at(rel_type).data_ptr<int64_t>();
      |                                                                      ^
csrc/cpu/neighbor_sample_cpu.cpp: In instantiation of ‘std::tuple<c10::Dict<std::__cxx11::basic_string<cha

A very tactical fix is this diff, but it probably should be adapted to match coding styles:

diff --git a/csrc/cpu/neighbor_sample_cpu.cpp b/csrc/cpu/neighbor_sample_cpu.cpp
index 23e3d49..46771b8 100644
--- a/csrc/cpu/neighbor_sample_cpu.cpp
+++ b/csrc/cpu/neighbor_sample_cpu.cpp
@@ -153,7 +153,7 @@ hetero_sample(const vector<node_t> &node_types,
   // Add the input nodes to the output nodes:
   for (const auto &kv : input_node_dict) {
     const auto &node_type = kv.key();
-    const auto &input_node = kv.value();
+    const torch::Tensor &input_node = kv.value();
     const auto *input_node_data = input_node.data_ptr<int64_t>();

     auto &samples = samples_dict.at(node_type);
@@ -180,8 +180,8 @@ hetero_sample(const vector<node_t> &node_types,
       auto &src_samples = samples_dict.at(src_node_type);
       auto &to_local_src_node = to_local_node_dict.at(src_node_type);

-      const auto *colptr_data = colptr_dict.at(rel_type).data_ptr<int64_t>();
-      const auto *row_data = row_dict.at(rel_type).data_ptr<int64_t>();
+      const auto *colptr_data = ((torch::Tensor)colptr_dict.at(rel_type)).data_ptr<int64_t>();
+      const auto *row_data = ((torch::Tensor)row_dict.at(rel_type)).data_ptr<int64_t>();

       auto &rows = rows_dict.at(rel_type);
       auto &cols = cols_dict.at(rel_type);
@@ -261,8 +261,8 @@ hetero_sample(const vector<node_t> &node_types,
       const auto &dst_samples = samples_dict.at(dst_node_type);
       auto &to_local_src_node = to_local_node_dict.at(src_node_type);

-      const auto *colptr_data = kv.value().data_ptr<int64_t>();
-      const auto *row_data = row_dict.at(rel_type).data_ptr<int64_t>();
+      const auto *colptr_data = ((torch::Tensor&)kv.value()).data_ptr<int64_t>();
+      const auto *row_data = ((torch::Tensor)row_dict.at(rel_type)).data_ptr<int64_t>();

       auto &rows = rows_dict.at(rel_type);
       auto &cols = cols_dict.at(rel_type);

stestagg avatar Jan 12 '22 11:01 stestagg

Thanks for posting. Can you create a PR with the applied changes? We can either merge this directly if it does not break PyTorch 1.10 backward compatibility, or once PyTorch 1.11 lands.

rusty1s avatar Jan 12 '22 14:01 rusty1s

Hey @rusty1s ! I've opened a PR with changes fixing that issue. Tested with 1.10 and 1.11. Please have a look, thanks! https://github.com/rusty1s/pytorch_sparse/pull/203

mmarcinkiewicz avatar Feb 08 '22 22:02 mmarcinkiewicz

This issue had no activity for 6 months. It will be closed in 2 weeks unless there is some new activity. Is this issue already resolved?

github-actions[bot] avatar Aug 08 '22 01:08 github-actions[bot]