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

[FEA]: Add tests that verify Thrust/CUB algorithms satisfy necessary requirements about how many times they access inputs/outputs #1662

Open
1 task done
jrhemstad opened this issue Apr 23, 2024 · 3 comments
Labels
feature request New feature or request.

Comments

@jrhemstad
Copy link
Collaborator

Is this a duplicate?

Area

General CCCL

Is your feature request related to a problem? Please describe.

As a user of Thrust/CUB algorithms, I want to be sure that they satisfy any explicit/implicit requirements about how many times elements in the input/output range are dereferenced.

For example, for_each must guarantee that each input is only dereferenced exactly once to allow the operator to have side-effects. We don't actually test that today.

Describe the solution you'd like

We should add testing utilities that verify input/output iterators are dereferenced only once and use those in the appropriate algorithms (e.g., for_each).

Describe alternatives you've considered

No response

Additional context

Today, for_each is the only algorithm where we fundamentally require the input elements are only dereferenced once. However, there is interest in potentially expanding this to other algorithms as needed or as possible.

@jrhemstad jrhemstad added the feature request New feature or request. label Apr 23, 2024
@jrhemstad
Copy link
Collaborator Author

Related to #1661

@jrhemstad
Copy link
Collaborator Author

I'm thinking we could create a "SingleAccessIterator" adaptor type something like this. We could kill two birds with one stone and also make it do bounds checking.

template<typename Iterator>
class SingleAccessIterator {
public:
    using iterator_category = std::random_access_iterator_tag;
    using value_type        = typename std::iterator_traits<Iterator>::value_type;
    using difference_type   = typename std::iterator_traits<Iterator>::difference_type;
    using pointer           = typename std::iterator_traits<Iterator>::pointer;
    using reference         = typename std::iterator_traits<Iterator>::reference;

private:
    Iterator base_iterator;
    thrust::device_vector<cuda::std::atomic_flag> accessed;
    size_t index{};

public:
    reference operator*() {
        if (index >= accessed.size() || accessed[index].test_and_set()) {
            CCCL_FAIL("Element accessed more than once or out of bounds access");
        }
        return *base_iterator;
    }
...

@jrhemstad
Copy link
Collaborator Author

@gevtushenko it occurs to me that we could make this an intrinsic part of the c2h custom type input generator? Something like:

using type = c2h::custom_type_t<c2h::accumulateable_t,
                                c2h::equal_comparable_t, 
                                c2h::single_access_t,
                                c2h::bounds_check_t>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request.
Projects
Status: Todo
Development

No branches or pull requests

1 participant