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

[QST] How to use the sort function? #713

Closed
HugoPhibbs opened this issue Aug 12, 2024 · 2 comments
Closed

[QST] How to use the sort function? #713

HugoPhibbs opened this issue Aug 12, 2024 · 2 comments

Comments

@HugoPhibbs
Copy link
Contributor

HugoPhibbs commented Aug 12, 2024

Basically, I'm trying to run the below code, but I'm getting an error where its complaining both that the input tensor must be contiguous and that the sort function only takes tensors as input. Which makes me think, how does one use the sort function - especially if you intend to use it with an operator from further up the call chain?

Is there a way to force evaluate the result of an operator straight into a tensor?

Basically my code looks like this:

int n = 20000;
int D = 1000;

auto mockProjections = matx::random<float>({n, D}, matx::UNIFORM) * 100;

mockProjections.run();

cudaDeviceSynchronize();

auto start = tu::timeNow();

matx::tensor_t<float, 2> projectionsSorted = matx::make_tensor<float>({n, D});

(projectionsSorted = matx::sort(mockProjections, matx::SORT_DIR_ASC)).run();

cudaDeviceSynchronize();

tu::printDurationSinceStart(start);

And I'm getting the errors:

/usr/local/include/matx/transforms/cub.h(565): error: static assertion failed with "Sorting only accepts tensors for now (no operators)"
    static_assert(is_tensor_view_v<InputOperator>, "Sorting only accepts tensors for now (no operators)");

and

/usr/local/include/matx/transforms/cub.h(566): error: class "matx::detail::CastOp<matx::detail::matxBinaryOp<matx::detail::RandomOp<float, cuda::std::__4::array<matx::index_t, 2UL>>, int, matx::detail::BinOp<float, int, matx::detail::MulF<float, int>>>, int>" has no member "IsContiguous"
    { if ((a.IsContiguous()) != true) { { throw matx::detail::matxException(matxInvalidType, "a.IsContiguous()" ": " "Tensor must be contiguous in memory for sorting", "/usr/local/include/matx/transforms/cub.h", 566); }; } };

thx

@cliffburdick
Copy link
Collaborator

Hi @HugoPhibbs , this i think is the last place in the code where we have not automatically converted the operator to a tensor. We need to do that, so it can be prioritized.

In the meantime you can just create a tensor with the same shape as the operator and make a copy before calling sort

@cliffburdick
Copy link
Collaborator

Hi @HugoPhibbs , this one should be fixed now: 86b74bc

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

No branches or pull requests

2 participants