Skip to content

Conversation

@r-barnes
Copy link
Contributor

@r-barnes r-barnes commented May 3, 2022

When I run this code with LLVM-12's undefined behaviour sanitizer enabled, I see:

pytorch/torch-scatter/csrc/cpu/segment_csr_cpu.cpp:60:3: runtime error: applying non-zero offset 8 to null pointer
    #0 0x7fa95da15396 in segment_csr_cpu(at::Tensor, at::Tensor, c10::optional<at::Tensor>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)::$_0::operator()() const::'lambda2'()::operator()() const::'lambda'()::operator()() const::'lambda'()::operator()() const pytorch/torch-scatter/csrc/cpu/segment_csr_cpu.cpp:60

This is because on Line 41 we have int64_t *arg_out_data = nullptr;. The value of arg_out_data is set conditionally, but arg_out_data is used unconditionally within the "segment_csr" kernel. Adding an if-statement gates that.

I've also added const and de-shadowed variables in a few places to make the code more readable.

When I run this code with LLVM-12's undefined behaviour sanitizer enabled, I see:
```
pytorch/torch-scatter/csrc/cpu/segment_csr_cpu.cpp:60:3: runtime error: applying non-zero offset 8 to null pointer
    #0 0x7fa95da15396 in segment_csr_cpu(at::Tensor, at::Tensor, c10::optional<at::Tensor>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)::$_0::operator()() const::'lambda2'()::operator()() const::'lambda'()::operator()() const::'lambda'()::operator()() const pytorch/torch-scatter/csrc/cpu/segment_csr_cpu.cpp:60
```
This is because on Line 41 we have `int64_t *arg_out_data = nullptr;`. The value of `arg_out_data` is set conditionally, but `arg_out_data` is used unconditionally within the "segment_csr" kernel. Adding an if-statement gates that.

I've also added `const` and de-shadowed variables in a few places to make the code more readable.
Copy link
Owner

@rusty1s rusty1s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!


for (auto k = 0; k < K; k++)
Reducer<scalar_t, REDUCE>::write(out_data + n * K + k, vals[k],
if (reduce2REDUCE.at(reduce) == MIN || reduce2REDUCE.at(reduce) == MAX) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we skip writing to the destination here for any other reduction (which is likely unintented - see test failures).

@r-barnes
Copy link
Contributor Author

r-barnes commented May 4, 2022 via email

@rusty1s
Copy link
Owner

rusty1s commented May 4, 2022

I think we could overload Reducer::write such that it supports arg_out_data or not. We can then pass in arg_out_data in case reduce == min | max, and otherwise not.

@github-actions
Copy link

github-actions bot commented Nov 1, 2022

This pull request had no activity for 6 months. It will be closed in 2 weeks unless there is some new activity.

@github-actions github-actions bot added the stale label Nov 1, 2022
@github-actions github-actions bot closed this Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants