nvidia_ballot.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 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_FUNCTIONAL_DETAIL_NVIDIA_BALLOT_HPP
  11. #define BOOST_COMPUTE_FUNCTIONAL_DETAIL_NVIDIA_BALLOT_HPP
  12. #include <boost/compute/function.hpp>
  13. #include <boost/compute/types/fundamental.hpp>
  14. namespace boost {
  15. namespace compute {
  16. namespace detail {
  17. template<class T>
  18. class nvidia_ballot : public function<uint_(T)>
  19. {
  20. public:
  21. nvidia_ballot()
  22. : function<uint_(T)>("nvidia_ballot")
  23. {
  24. this->set_source(
  25. "inline uint nvidia_ballot(const uint x)\n"
  26. "{\n"
  27. " uint result;\n"
  28. " asm volatile(\n"
  29. " \"setp.ne.u32 %%p1, %1, 0;\"\n"
  30. " \"vote.ballot.b32 %0, %%p1;\"\n"
  31. " : \"=r\"(result)\n"
  32. " : \"r\"(x)\n"
  33. " );\n"
  34. " return result;\n"
  35. "}\n"
  36. );
  37. }
  38. };
  39. } // end detail namespace
  40. } // end compute namespace
  41. } // end boost namespace
  42. #endif // BOOST_COMPUTE_FUNCTIONAL_DETAIL_NVIDIA_BALLOT_HPP