work_size.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #ifndef BOOST_COMPUTE_DETAIL_WORK_SIZE_HPP
  11. #define BOOST_COMPUTE_DETAIL_WORK_SIZE_HPP
  12. #include <cmath>
  13. namespace boost {
  14. namespace compute {
  15. namespace detail {
  16. // Given a total number of values (count), a number of values to
  17. // process per thread (vtp), and a number of threads to execute per
  18. // block (tpb), this function returns the global work size to be
  19. // passed to clEnqueueNDRangeKernel() for a 1D algorithm.
  20. inline size_t calculate_work_size(size_t count, size_t vpt, size_t tpb)
  21. {
  22. size_t work_size = static_cast<size_t>(std::ceil(float(count) / vpt));
  23. if(work_size % tpb != 0){
  24. work_size += tpb - work_size % tpb;
  25. }
  26. return work_size;
  27. }
  28. } // end detail namespace
  29. } // end compute namespace
  30. } // end boost namespace
  31. #endif // BOOST_COMPUTE_DETAIL_WORK_SIZE_HPP