Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] raft::linalg::reduce won't compile when InType != OutType #165

Closed
Nyrio opened this issue Mar 2, 2021 · 3 comments · Fixed by #296
Closed

[BUG] raft::linalg::reduce won't compile when InType != OutType #165

Nyrio opened this issue Mar 2, 2021 · 3 comments · Fixed by #296
Assignees
Labels
bug Something isn't working cpp inactive-30d

Comments

@Nyrio
Copy link
Contributor

Nyrio commented Mar 2, 2021

Describe the bug
I am reducing a boolean matrix to an integer vector (cf code sample in the section below).
I only need coalescedReduction, but the reduce function instantiates stridedReduction too and this is where the problem happens, at line 150 of strided_reduction.cuh: the if statement is not determined at compile time (it's not a C++17 if constexpr) so it attempts to compile stridedSummationKernel even if the input and output types are different, in which case it can't compile.

Note that at the moment I solved the problem for my use case by calling directly coalescedReduction instead of reduce.

Steps/Code to reproduce bug
This is approximately what my code looks like:

bool* in;
int* out;
raft::linalg::reduce(
  out, in, N, N, 0, true, true, stream, false,
  [] __device__(bool value, int idx) {
    return static_cast<int>(value);
  },
  raft::Sum<int>(), raft::Nop<int>());

Compilation error:

include/raft/linalg/strided_reduction.cuh(152): error: no instance of function template "raft::linalg::stridedSummationKernel" matches the argument list
argument types are: (int *, const __nv_bool *, int, int, int, lambda [](__nv_bool, int)->int)
detected during: instantiation of "void raft::linalg::stridedReduction(OutType *, const InType *, IdxType, IdxType, OutType, cudaStream_t, __nv_bool, MainLambda, ReduceLambda, FinalLambda) [with InType=__nv_bool, OutType=int, IdxType=int, MainLambda=lambda [](__nv_bool, int)->int, ReduceLambda=raft::Sum<int>, FinalLambda=raft::Nop<int, int>]"

Expected behavior
The reduction should support different input and output types as suggested by the template parameters and the docs.

@Nyrio Nyrio added bug Something isn't working cpp labels Mar 2, 2021
@github-actions
Copy link

github-actions bot commented Apr 7, 2021

This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

@divyegala
Copy link
Member

@Nyrio now that RAFT uses C++17, do you think you could submit a PR with a fix for this?

@Nyrio
Copy link
Contributor Author

Nyrio commented Jul 19, 2021

do you think you could submit a PR with a fix for this?

@divyegala Yes, I will.

@rapids-bot rapids-bot bot closed this as completed in #296 Jul 21, 2021
rapids-bot bot pushed a commit that referenced this issue Jul 21, 2021
)

Closes #165 

Uses a C++17 `if constexpr` to discard at compile time a code path that doesn't support different input and output types, and adds a test for such a case (the test won't compile without that `constexpr` keyword).

Authors:
  - Louis Sugy (https://github.com/Nyrio)

Approvers:
  - Corey J. Nolet (https://github.com/cjnolet)
  - Brad Rees (https://github.com/BradReesWork)

URL: #296
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cpp inactive-30d
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants