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

FEAT: topk function in all backends. #2061

Merged
merged 1 commit into from
Feb 25, 2018
Merged

Conversation

umar456
Copy link
Member

@umar456 umar456 commented Feb 22, 2018

CUDA backend alone implements a custom kernel to fetch top k elements
without sorting all the values. CPU backends sorts the data and fetch
the top k elements. The OpenCL backend is optimized for CPU devices
to map the memory and perform a partial sort to get the results.

Sponsored by SDL

Copy link
Member

@9prady9 9prady9 left a comment

Choose a reason for hiding this comment

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

Minor text changes, everything else looks good.

@@ -1,7 +1,7 @@
/*!
\page batch_detail_stat statistics

This function performs the operation across all batches present in the input simultaneously.
This function performs the operation across all dimension of the input array.
Copy link
Member

Choose a reason for hiding this comment

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

across all dimensions of

using namespace detail;

template<typename T>
af_err topkWithIndices(af_array *v, af_array* i, const af_array in,
Copy link
Member

Choose a reason for hiding this comment

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

can you change this function name to be topk as well since we are not explicitly saying with indices anywhere now.

array. The indices along with their values are returned. If the input is a
multi-dimensional array, the indices will be the index of the value in that
dimension. Order of duplicate values are not preserved. This function is
optimized for small values of k.
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice if we can add some sort of guideline as to from which value of k does the performance deteriorate.

Copy link
Member Author

Choose a reason for hiding this comment

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

This would be different for different devices and implementations.

test/topk.cpp Outdated
TYPED_TEST_CASE(TopK, TestTypes);

template<typename T>
void topkIndexTest(const unsigned ndims, const dim_t* dims,
Copy link
Member

Choose a reason for hiding this comment

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

We can just make it topkTest instead of topkIndexTest now.

@pavanky
Copy link
Member

pavanky commented Feb 22, 2018

@umar456 why not partial_sort for cpu devices?

@9prady9 9prady9 dismissed their stale review February 23, 2018 04:04

More changes coming in.

Copy link
Member Author

@umar456 umar456 left a comment

Choose a reason for hiding this comment

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

Addressed feedback.
@pavanky I have updated the CPU backend to use partial_sort.

array. The indices along with their values are returned. If the input is a
multi-dimensional array, the indices will be the index of the value in that
dimension. Order of duplicate values are not preserved. This function is
optimized for small values of k.
Copy link
Member Author

Choose a reason for hiding this comment

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

This would be different for different devices and implementations.

CUDA backend alone implements a custom kernel to fetch top k elements
without sorting all the values. CPU backends sorts the data and fetch
the top k elements. The OpenCL backend is optimized for CPU devices
to map the memory and perform a partial sort to get the results.
@9prady9 9prady9 merged commit ea39981 into arrayfire:master Feb 25, 2018
@9prady9 9prady9 deleted the topk branch February 25, 2018 02:24
@umar456 umar456 mentioned this pull request Feb 27, 2018
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.

None yet

3 participants