NVIDIA / MatX

An efficient C++17 GPU numerical computing library with Python-like syntax
https://nvidia.github.io/MatX
BSD 3-Clause "New" or "Revised" License
1.21k stars 83 forks source link

[QST] How to multiply two random tensors together? #714

Closed HugoPhibbs closed 2 months ago

HugoPhibbs commented 2 months ago

Basically I have the code:

int n = 70000;
int d = 784;
int D = 1024;

auto X = matx::random<float>({n, d}, matx::UNIFORM);
auto Y = matx::random<float>({d, D}, matx::UNIFORM);
auto Z = matx::matmul(X, Y);

Z.run();

But I get the error:

/usr/local/include/matx/operators/matmul.h(126): error: no instance of function template "matx::detail::RandomOp<T, ShapeType>::PreRun [with T=float, ShapeType=cuda::std::__4::array<matx::index_t, 2UL>]" matches the argument list and object (the object has type qualifiers that prevent a match)
            argument types are: (cuda::std::__4::array<matx::index_t, 2UL>, matx::cudaExecutor)
            object type is: const matx::detail::RandomOp<float, cuda::std::__4::array<matx::index_t, 2UL>>
              a_.PreRun(std::forward<ShapeType>(shape), std::forward<Executor>(ex));
                 ^
          detected during:
            instantiation of "void matx::detail::MatMulOp<OpA, OpB, PermDims>::InnerPreRun(ShapeType &&, Executor &&) const noexcept [with OpA=matx::detail::RandomOp<float, cuda::std::__4::array<matx::index_t, 2UL>>, OpB=matx::detail::RandomOp<float, cuda::std::__4::array<matx::index_t, 2UL>>, PermDims=matx::detail::no_permute_t, ShapeType=cuda::std::__4::array<matx::index_t, 2UL>, Executor=matx::cudaExecutor &]" at line 137
            instantiation of "void matx::detail::MatMulOp<OpA, OpB, PermDims>::PreRun(ShapeType &&, Executor &&) const noexcept [with OpA=matx::detail::RandomOp<float, cuda::std::__4::array<matx::index_t, 2UL>>, OpB=matx::detail::RandomOp<float, cuda::std::__4::array<matx::index_t, 2UL>>, PermDims=matx::detail::no_permute_t, ShapeType=cuda::std::__4::array<matx::index_t, 2UL>, Executor=matx::cudaExecutor &]" at line 74 of /usr/local/include/matx/operators/base_operator.h
            instantiation of "void matx::BaseOp<T>::run(cudaStream_t) [with T=matx::detail::MatMulOp<matx::detail::RandomOp<float, cuda::std::__4::array<matx::index_t, 2UL>>, matx::detail::RandomOp<float, cuda::std::__4::array<matx::index_t, 2UL>>, matx::detail::no_permute_t>]" at line 48 of /home/hphi344/Documents/GS-DBSCAN-CPP/test/gsDBSCAN/ProjectionsTest.cpp

I wasn't sure as to whether this was a real bug or not?

Thx

cliffburdick commented 2 months ago

This is a bug in random. Looks like a const issue. Will triage today.

cliffburdick commented 2 months ago

@HugoPhibbs please try https://github.com/NVIDIA/MatX/pull/715

I will test it this morning too if you don't have time.

HugoPhibbs commented 2 months ago

@cliffburdick ran the code with no errors. So LGTM!