Skip to content

Commit

Permalink
Fixed tied sort and reduce_by_key for Visual Studio
Browse files Browse the repository at this point in the history
std::tuple is not a fusion sequence in Visual Studio 2010,
because std::tuple fusion adaptor uses variadic templates.
Users will have to use boost::fusion::vector_tie instead
of std::tie.
  • Loading branch information
ddemidov committed Dec 24, 2013
1 parent cbc3135 commit 6453690
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 32 deletions.
32 changes: 15 additions & 17 deletions tests/reduce_by_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ BOOST_AUTO_TEST_CASE(rbk)
}

struct comp {
const int *k1;
const long *k2;
const cl_int *k1;
const cl_long *k2;

comp(const int * k1, const long *k2) : k1(k1), k2(k2) {}
comp(const cl_int * k1, const cl_long *k2) : k1(k1), k2(k2) {}

template <class Tuple>
bool operator()(size_t i, Tuple t) const {
Expand All @@ -58,17 +58,16 @@ struct comp {
}
};

#ifndef _MSC_VER // Damn you Visual Studio!
BOOST_AUTO_TEST_CASE(rbk_tuple)
{
const int n = 1000 * 1000;

std::vector<int> k1(n);
std::vector<long> k2(n);
std::vector<cl_int> k1(n);
std::vector<cl_long> k2(n);

{
std::vector<int> k1s = random_vector<int> (n);
std::vector<long> k2s = random_vector<long>(n);
std::vector<cl_int> k1s = random_vector<cl_int> (n);
std::vector<cl_long> k2s = random_vector<cl_long>(n);

std::vector<size_t> idx(n);
std::iota(idx.begin(), idx.end(), 0);
Expand All @@ -87,15 +86,15 @@ BOOST_AUTO_TEST_CASE(rbk_tuple)

std::vector<vex::backend::command_queue> queue(1, ctx.queue(0));

vex::vector<int> ikey1(queue, k1);
vex::vector<long> ikey2(queue, k2);
vex::vector<double> ivals(queue, y);
vex::vector<cl_int> ikey1(queue, k1);
vex::vector<cl_long> ikey2(queue, k2);
vex::vector<double> ivals(queue, y);

vex::vector<int> okey1;
vex::vector<long> okey2;
vex::vector<double> ovals;
vex::vector<cl_int> okey1;
vex::vector<cl_long> okey2;
vex::vector<double> ovals;

VEX_FUNCTION(equal, bool(int, long, int, long),
VEX_FUNCTION(equal, bool(cl_int, cl_long, cl_int, cl_long),
"return (prm1 == prm3) && (prm2 == prm4);"
);

Expand Down Expand Up @@ -124,7 +123,7 @@ BOOST_AUTO_TEST_CASE(rbk_tuple)
std::vector<size_t> idx(n);
std::iota(idx.begin(), idx.end(), 0);

check_sample(okey1, okey2, ovals, [&](size_t, int key1, long key2, double dev_sum) {
check_sample(okey1, okey2, ovals, [&](size_t, cl_int key1, cl_long key2, double dev_sum) {
auto r = std::equal_range(idx.begin(), idx.end(),
std::make_tuple(key1, key2), comp(k1.data(), k2.data()));

Expand All @@ -136,6 +135,5 @@ BOOST_AUTO_TEST_CASE(rbk_tuple)
BOOST_CHECK_CLOSE(dev_sum, host_sum, 1e-8);
});
}
#endif

BOOST_AUTO_TEST_SUITE_END()
18 changes: 8 additions & 10 deletions tests/sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ BOOST_AUTO_TEST_CASE(sort_keys_vals)
BOOST_CHECK(std::is_sorted(k.begin(), k.end(), even_first));
}

#ifndef _MSC_VER
BOOST_AUTO_TEST_CASE(sort_keys_tuple)
{
const size_t n = 1000 * 1000;
Expand Down Expand Up @@ -99,15 +98,15 @@ BOOST_AUTO_TEST_CASE(sort_keys_vals_tuple)
{
const size_t n = 1000 * 1000;

std::vector<int> k1 = random_vector<int> (n);
std::vector<float> k2 = random_vector<float>(n);
std::vector<long> v1 = random_vector<long> (n);
std::vector<short> v2 = random_vector<short>(n);
std::vector<int> k1 = random_vector<int> (n);
std::vector<float> k2 = random_vector<float> (n);
std::vector<cl_long> v1 = random_vector<cl_long>(n);
std::vector<short> v2 = random_vector<short> (n);

vex::vector<int> keys1(ctx, k1);
vex::vector<float> keys2(ctx, k2);
vex::vector<long> vals1(ctx, v1);
vex::vector<short> vals2(ctx, v2);
vex::vector<int> keys1(ctx, k1);
vex::vector<float> keys2(ctx, k2);
vex::vector<cl_long> vals1(ctx, v1);
vex::vector<short> vals2(ctx, v2);

struct less_t {
typedef bool result_type;
Expand Down Expand Up @@ -135,6 +134,5 @@ BOOST_AUTO_TEST_CASE(sort_keys_vals_tuple)
return std::make_tuple(k1[i], k2[i]) < std::make_tuple(k1[j], k2[j]);
} ) );
}
#endif

BOOST_AUTO_TEST_SUITE_END()
10 changes: 10 additions & 0 deletions vexcl/detail/fusion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ template <class Tuple>
struct extract_value_types {
typedef typename std::decay<Tuple>::type T;

#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable : 4348)
#endif

template <size_t I, size_t N, class Enable = void>
struct loop;

Expand All @@ -58,6 +63,11 @@ struct extract_value_types {
};

typedef typename loop<0, boost::fusion::result_of::size<T>::value>::type type;

#ifdef _MSC_VER
# pragma warning(pop)
#endif

};

struct type_iterator {
Expand Down
2 changes: 1 addition & 1 deletion vexcl/reduce_by_key.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ int reduce_by_key_sink(
krn1(queue[0]);

/***** Kernel 2 *****/
uint work_per_thread = std::max<uint>(1U, scan_buf_size / NT);
uint work_per_thread = std::max<uint>(1U, static_cast<uint>(scan_buf_size / NT));

auto krn2 = is_cpu(queue[0]) ?
detail::block_inclusive_scan_by_key<NT_cpu, V, Oper>(queue[0]) :
Expand Down
2 changes: 1 addition & 1 deletion vexcl/scan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ void scan(
intra_block_inclusive_scan<NT_cpu, T, Oper>(queue) :
intra_block_inclusive_scan<NT_gpu, T, Oper>(queue);

uint work_per_thread = std::max<uint>(1U, scan_buf_size / NT);
uint work_per_thread = std::max<uint>(1U, static_cast<uint>(scan_buf_size / NT));
krn1.push_arg(num_blocks);
krn1.push_arg(post_sum);
krn1.push_arg(pre_sum1);
Expand Down
6 changes: 3 additions & 3 deletions vexcl/sort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ backend::device_vector<int> merge_path_partitions(

auto merge_partition = merge_partition_kernel<NT, K, Comp>(queue);

int a_count = boost::fusion::at_c<0>(keys).size();
int a_count = static_cast<int>(boost::fusion::at_c<0>(keys).size());
int b_count = 0;

merge_partition.push_arg(a_count);
Expand Down Expand Up @@ -1813,7 +1813,7 @@ void sort(const backend::command_queue &queue, KT &keys, Comp) {
const int VT = (sizeof_keys::value > 4) ? 7 : 11;
const int NV = NT * VT;

const int count = at_c<0>(keys).size();
const int count = static_cast<int>(at_c<0>(keys).size());
const int num_blocks = (count + NV - 1) / NV;
const int num_passes = detail::find_log2(num_blocks, true);

Expand Down Expand Up @@ -1882,7 +1882,7 @@ void sort_by_key(const backend::command_queue &queue, KTup &&keys, VTup &&vals,
const int VT = (sizeof(K) > 4) ? 7 : 11;
const int NV = NT * VT;

const int count = at_c<0>(keys).size();
const int count = static_cast<int>(at_c<0>(keys).size());
const int num_blocks = (count + NV - 1) / NV;
const int num_passes = detail::find_log2(num_blocks, true);

Expand Down

0 comments on commit 6453690

Please sign in to comment.