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

spmv: template arguments not always inferrable #1964

Closed
brian-kelley opened this issue Sep 6, 2023 · 7 comments
Closed

spmv: template arguments not always inferrable #1964

brian-kelley opened this issue Sep 6, 2023 · 7 comments
Assignees
Labels

Comments

@brian-kelley
Copy link
Contributor

For a call like KokkosSparse::spmv(space, mode, alpha, A, x, beta, y);, template argument deduction fails.

@lucbv
Copy link
Contributor

lucbv commented Sep 6, 2023

I am wondering if in @e10harvey 's case the issue is related to wrapping the execution space in a std::vector.
This might somehow hide the underlying execution space type?

@brian-kelley
Copy link
Contributor Author

@lucbv Hmm, you might be right about that. Maybe for some type T, T& or const T& is the argument type but an enable_if only matches a T?

Anyway, the spmv unit tests do actually test this exact call with all template arguments deduced, so something else is going on.

@e10harvey
Copy link
Contributor

Hm. I would expect the template arg to be inferrable from instances[i], where std::vector<exec_space> instances;.

@brian-kelley
Copy link
Contributor Author

@e10harvey I just tried a spmv call similar to what you had (where the space is an element of a std::vector) but it compiled without errors. Could you post the error message you got?

@e10harvey
Copy link
Contributor

From the source branch in #1963:

$ git rev-parse HEAD
35d8ff92b320c27fb36ce2875187db6d3ef49c92
$ git diff
diff --git a/perf_test/sparse/KokkosSparse_gs.cpp b/perf_test/sparse/KokkosSparse_gs.cpp
index 163fdb2dd..b32940c6c 100644
--- a/perf_test/sparse/KokkosSparse_gs.cpp
+++ b/perf_test/sparse/KokkosSparse_gs.cpp
@@ -326,7 +326,7 @@ void runGS(const GS_Parameters& params) {
     double bnorm   = KokkosBlas::nrm2(instances[i], b[i]);
     scalar_t alpha = Kokkos::reduction_identity<scalar_t>::prod();
     scalar_t beta  = -alpha;
-    KokkosSparse::spmv<exec_space, scalar_t, crsMat_t, scalar_view_t, scalar_t,
+    KokkosSparse::spmv<scalar_t, crsMat_t, scalar_view_t, scalar_t,
                        scalar_view_t>(instances[i], "N", alpha, blk_A, x[i],
                                       beta, res);
     double resnorm = KokkosBlas::nrm2(instances[i], res);
$ make sparse_gs
build] [ 98%] Built target kokkoskernels
[build] [100%] Building CXX object perf_test/sparse/CMakeFiles/sparse_gs.dir/KokkosSparse_gs.cpp.o
[build] /path/to/perf_test/sparse/KokkosSparse_gs.cpp:329:5: error: no matching function for call to 'spmv'
[build]     KokkosSparse::spmv<scalar_t, crsMat_t, scalar_view_t, scalar_t,
[build]     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[build] /path/to/perf_test/sparse/KokkosSparse_gs.cpp:477:5: note: in instantiation of function template specialization 'runGS<Kokkos::Serial>' requested here
[build]     runGS<Kokkos::DefaultExecutionSpace>(params);
[build]     ^
[build] /path/to/sparse/src/KokkosSparse_spmv.hpp:1186:6: note: candidate function template not viable: no known conversion from 'value_type' (aka 'Kokkos::Serial') to 'KokkosKernels::Experimental::Controls' for 1st argument
[build] void spmv(KokkosKernels::Experimental::Controls controls, const char mode[],
[build]      ^
[build] /path/to/sparse/src/KokkosSparse_spmv.hpp:1288:6: note: candidate function template not viable: no known conversion from 'value_type' (aka 'Kokkos::Serial') to 'const scalar_t' (aka 'const double') for 1st argument
[build] void spmv(const ExecutionSpace& space, const char mode[],
[build]      ^
[build] /path/to/sparse/src/KokkosSparse_spmv.hpp:1205:6: note: candidate template ignored: requirement '!KokkosSparse::is_crs_matrix<KokkosSparse::CrsMatrix<double, int, Kokkos::Serial, void, unsigned long>>::value' was not satisfied [with AlphaType = scalar_t, AMatrix = crsMat_t, XVector = scalar_view_t, BetaType = scalar_t, YVector = scalar_view_t]
[build] void spmv(KokkosKernels::Experimental::Controls /*controls*/,
[build]      ^
[build] /path/to/sparse/src/KokkosSparse_spmv.hpp:1259:6: note: candidate function template not viable: requires 6 arguments, but 7 were provided
[build] void spmv(const char mode[], const AlphaType& alpha, const AMatrix& A,
[build]      ^
[build] /path/to/sparse/src/KokkosSparse_spmv.hpp:263:6: note: candidate function template not viable: requires 8 arguments, but 7 were provided
[build] void spmv(KokkosKernels::Experimental::Controls controls, const char mode[],
[build]      ^
[build] /path/to/sparse/src/KokkosSparse_spmv.hpp:458:6: note: candidate function template not viable: requires 8 arguments, but 7 were provided
[build] void spmv(KokkosKernels::Experimental::Controls controls, const char mode[],
[build]      ^
[build] /path/to/sparse/src/KokkosSparse_spmv.hpp:814:6: note: candidate function template not viable: requires 8 arguments, but 7 were provided
[build] void spmv(KokkosKernels::Experimental::Controls controls, const char mode[],
[build]      ^
[build] /path/to/sparse/src/KokkosSparse_spmv.hpp:1008:6: note: candidate function template not viable: requires 8 arguments, but 7 were provided
[build] void spmv(KokkosKernels::Experimental::Controls controls, const char mode[],
[build]      ^
[build] /path/to/sparse/src/KokkosSparse_spmv.hpp:1064:6: note: candidate function template not viable: requires 8 arguments, but 7 were provided
[build] void spmv(const ExecutionSpace& space,
[build]      ^
[build] /path/to/sparse/src/KokkosSparse_spmv.hpp:1227:6: note: candidate function template not viable: requires 8 arguments, but 7 were provided
[build] void spmv(const ExecutionSpace& /* space */,
[build]      ^
[build] /path/to/sparse/src/KokkosSparse_spmv.hpp:76:6: note: candidate function template not viable: requires 9 arguments, but 7 were provided
[build] void spmv(const ExecutionSpace& space,
[build]      ^
[build] /path/to/sparse/src/KokkosSparse_spmv.hpp:275:6: note: candidate function template not viable: requires 9 arguments, but 7 were provided
[build] void spmv(const ExecutionSpace& space,
[build]      ^
[build] /path/to/sparse/src/KokkosSparse_spmv.hpp:653:6: note: candidate function template not viable: requires 9 arguments, but 7 were provided
[build] void spmv(const ExecutionSpace& space,
[build]      ^
[build] /path/to/sparse/src/KokkosSparse_spmv.hpp:826:6: note: candidate function template not viable: requires 9 arguments, but 7 were provided
[build] void spmv(const ExecutionSpace& space,
[build]      ^
[build] 1 error generated.
[build] make[3]: *** [perf_test/sparse/CMakeFiles/sparse_gs.dir/KokkosSparse_gs.cpp.o] Error 1
[build] make[2]: *** [perf_test/sparse/CMakeFiles/sparse_gs.dir/all] Error 2
[build] make[1]: *** [perf_test/sparse/CMakeFiles/sparse_gs.dir/rule] Error 2
[build] make: *** [sparse_gs] Error 2

Not specifying any template argument does work though.

It looks like you must specify template arguments from left to right rather than right to left.

@brian-kelley
Copy link
Contributor Author

Oh yeah, I was thinking that not specifying any arguments should work, and is generally how I would expect spmv to be used.

@e10harvey
Copy link
Contributor

There should be a 'Easy close' and 'Almost impossible close' button next to 'close with comment' ; )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants