2
0
mirror of https://github.com/boostorg/compute.git synced 2026-02-20 14:42:16 +00:00

Fixes for Mac OS X

This commit is contained in:
Kyle Lutz
2014-12-22 19:59:39 -08:00
parent 88811e345b
commit 417cb03670
21 changed files with 171 additions and 61 deletions

View File

@@ -21,15 +21,14 @@ namespace compute {
namespace detail {
const char lexicographical_compare_source[] =
"__kernel void lexicographical_compare(uint size1,\n"
" uint size2,\n"
"__kernel void lexicographical_compare(const uint size1,\n"
" const uint size2,\n"
" __global const T1 *range1,\n"
" __global const T2 *range2,\n"
" __global bool *result_buf)\n"
"{\n"
" const int i = get_global_id(0);\n"
" if((i != size1) && (i != size2))\n"
" {\n"
" const uint i = get_global_id(0);\n"
" if((i != size1) && (i != size2)){\n"
//Individual elements are compared and results are stored in parallel.
//0 is true
" if(range1[i] < range2[i])\n"
@@ -83,8 +82,8 @@ inline bool dispatch_lexicographical_compare(InputIterator1 first1,
kernel lexicographical_compare_kernel(lexicographical_compare_program,
"lexicographical_compare");
lexicographical_compare_kernel.set_arg(0, (uint)iterator_size1);
lexicographical_compare_kernel.set_arg(1, (uint)iterator_size2);
lexicographical_compare_kernel.set_arg<uint_>(0, iterator_size1);
lexicographical_compare_kernel.set_arg<uint_>(1, iterator_size2);
lexicographical_compare_kernel.set_arg(2, first1.get_buffer());
lexicographical_compare_kernel.set_arg(3, first2.get_buffer());
lexicographical_compare_kernel.set_arg(4, result_vector.get_buffer());

View File

@@ -160,10 +160,10 @@ public:
// update block value
if(value){
block_value |= (1 << bit);
block_value |= (size_type(1) << bit);
}
else {
block_value &= ~(1 << bit);
block_value &= ~(size_type(1) << bit);
}
// store new block
@@ -179,7 +179,7 @@ public:
block_type block_value;
copy_n(m_bits.begin() + block, 1, &block_value, queue);
return block_value & (1 << bit);
return block_value & (size_type(1) << bit);
}
/// Flips the value of the bit at position \p n.

View File

@@ -251,6 +251,13 @@ private:
size_t cb,
void *user_data)
{
#ifdef __APPLE__
// on apple, every single opencl failure is reported through the
// context error handler. in order to let failures propogate
// via opencl_error, we don't throw context_errors from here.
return;
#endif
context *this_ = static_cast<context *>(user_data);
BOOST_THROW_EXCEPTION(

View File

@@ -0,0 +1,45 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
// See http://kylelutz.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_DETAIL_LITERAL_HPP
#define BOOST_COMPUTE_DETAIL_LITERAL_HPP
#include <iomanip>
#include <limits>
#include <sstream>
#include <boost/type_traits/is_same.hpp>
#include <boost/compute/types/fundamental.hpp>
namespace boost {
namespace compute {
namespace detail {
template<class T>
std::string make_literal(T x)
{
std::stringstream s;
s << std::setprecision(std::numeric_limits<T>::digits10)
<< std::scientific
<< x;
if(boost::is_same<T, float>::value || boost::is_same<T, float_>::value){
s << "f";
}
return s.str();
}
} // end detail namespace
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_DETAIL_LITERAL_HPP

View File

@@ -15,6 +15,7 @@
#include <boost/compute/function.hpp>
#include <boost/compute/types/fundamental.hpp>
#include <boost/compute/detail/iterator_range_size.hpp>
#include <boost/compute/detail/literal.hpp>
namespace boost {
namespace compute {
@@ -70,7 +71,7 @@ public:
return (convert_RealType(x) / MAX_RANDOM) < PARAM;
});
scale_random.define("PARAM", boost::lexical_cast<std::string>(m_p));
scale_random.define("PARAM", detail::make_literal(m_p));
scale_random.define("MAX_RANDOM", "UINT_MAX");
scale_random.define(
"convert_RealType", std::string("convert_") + type_name<RealType>()

View File

@@ -13,10 +13,11 @@
#include <boost/compute/command_queue.hpp>
#include <boost/compute/function.hpp>
#include <boost/compute/types/fundamental.hpp>
#include <boost/compute/algorithm/accumulate.hpp>
#include <boost/compute/algorithm/copy.hpp>
#include <boost/compute/algorithm/transform.hpp>
#include <boost/compute/detail/literal.hpp>
#include <boost/compute/types/fundamental.hpp>
namespace boost {
namespace compute {
@@ -90,15 +91,12 @@ public:
for(size_t i=0; i<m_n; i++)
{
source = source +
"if(rno <= " +
boost::lexical_cast<std::string>(m_probabilities[i]) +
")\n" +
" return " + boost::lexical_cast<std::string>(i) +
";\n";
"if(rno <= " + detail::make_literal<float>(m_probabilities[i]) + ")\n" +
" return " + detail::make_literal(i) + ";\n";
}
source = source +
"return " + boost::lexical_cast<std::string>(m_n-1) + ";\n" +
"return " + detail::make_literal(m_n - 1) + ";\n" +
"}\n";
BOOST_COMPUTE_FUNCTION(IntType, scale_random, (const uint_ x), {});

View File

@@ -74,7 +74,7 @@ public:
vector<g_result_type> tmp(size, queue.get_context());
vector<g_result_type> tmp2(size, queue.get_context());
uint_ bound = ((uint(-1))/(m_b-m_a+1))*(m_b-m_a+1);
uint_ bound = ((uint_(-1))/(m_b-m_a+1))*(m_b-m_a+1);
buffer_iterator<g_result_type> tmp2_iter;

View File

@@ -13,6 +13,7 @@
#include <boost/compute/command_queue.hpp>
#include <boost/compute/function.hpp>
#include <boost/compute/detail/literal.hpp>
#include <boost/compute/types/fundamental.hpp>
namespace boost {
@@ -71,8 +72,8 @@ public:
return LO + (convert_RealType(x) / MAX_RANDOM) * (HI - LO);
});
scale_random.define("LO", boost::lexical_cast<std::string>(m_a));
scale_random.define("HI", boost::lexical_cast<std::string>(m_b));
scale_random.define("LO", detail::make_literal(m_a));
scale_random.define("HI", detail::make_literal(m_b));
scale_random.define("MAX_RANDOM", "UINT_MAX");
scale_random.define(
"convert_RealType", std::string("convert_") + type_name<RealType>()