Exemplo n.º 1
0
    binary_find_kernel(InputIterator first,
                       InputIterator last,
                       UnaryPredicate predicate)
        : meta_kernel("binary_find")
    {
        typedef typename std::iterator_traits<InputIterator>::value_type value_type;

        m_index_arg = add_arg<uint_ *>(memory_object::global_memory, "index");
        m_block_arg = add_arg<uint_>("block");

        atomic_min<uint_> atomic_min_uint;

        *this <<
            "uint i = get_global_id(0) * block;\n" <<
            decl<value_type>("value") << "=" << first[var<uint_>("i")] << ";\n" <<
            "if(" << predicate(var<value_type>("value")) << ") {\n" <<
                atomic_min_uint(var<uint_ *>("index"), var<uint_>("i")) << ";\n" <<
            "}\n";
    }
Exemplo n.º 2
0
    void set_range(InputIterator first,
                   InputIterator last,
                   UnaryPredicate predicate)
    {
        typedef typename std::iterator_traits<InputIterator>::value_type value_type;
        int block = (iterator_range_size(first, last)-1)/(m_threads-1);

        m_index_arg = add_arg<uint_ *>(memory_object::global_memory, "index");

        atomic_min<uint_> atomic_min_uint;

        *this <<
            "uint i = get_global_id(0) * " << block << ";\n" <<
            decl<value_type>("value") << "=" << first[var<uint_>("i")] << ";\n" <<
            "if(" << predicate(var<value_type>("value")) << ") {\n" <<
                atomic_min_uint(var<uint_ *>("index"), var<uint_>("i")) << ";\n" <<
            "}\n";

    }