Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #369 from thrust/fix-radix-sort-char
Browse files Browse the repository at this point in the history
Check for signedness of char when performing key conversion in CUDA's ra...
  • Loading branch information
jaredhoberock committed May 2, 2013
2 parents ef58122 + 69ed400 commit 1e430ed
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions thrust/system/cuda/detail/detail/b40c/radixsort_key_conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,25 +164,33 @@ struct PostprocessKeyFunctor<double> {
//

template <> struct KeyConversion<char> {
typedef unsigned char UnsignedBits;
typedef unsigned char UnsignedBits;
};

template <>
struct PreprocessKeyFunctor<char> {
__device__ __host__ __forceinline__ void operator()(unsigned char &converted_key) {
const unsigned int SIGN_MASK = 1u << ((sizeof(char) * 8) - 1);
converted_key ^= SIGN_MASK;
}
__device__ __host__ __forceinline__ static bool MustApply(){ return true;}
__device__ __host__ __forceinline__ void operator()(unsigned char &converted_key) {
// char is unsigned on some platforms, so we have to check
if(std::numeric_limits<char>::is_signed)
{
const unsigned int SIGN_MASK = 1u << ((sizeof(char) * 8) - 1);
converted_key ^= SIGN_MASK;
}
}
__device__ __host__ __forceinline__ static bool MustApply(){ return std::numeric_limits<char>::is_signed;}
};

template <>
struct PostprocessKeyFunctor<char> {
__device__ __host__ __forceinline__ void operator()(unsigned char &converted_key) {
const unsigned int SIGN_MASK = 1u << ((sizeof(char) * 8) - 1);
converted_key ^= SIGN_MASK;
__device__ __host__ __forceinline__ void operator()(unsigned char &converted_key) {
// char is unsigned on some platforms, so we have to check
if(std::numeric_limits<char>::is_signed)
{
const unsigned int SIGN_MASK = 1u << ((sizeof(char) * 8) - 1);
converted_key ^= SIGN_MASK;
}
__device__ __host__ __forceinline__ static bool MustApply(){ return true;}
}
__device__ __host__ __forceinline__ static bool MustApply(){ return std::numeric_limits<char>::is_signed;}
};


Expand Down

0 comments on commit 1e430ed

Please sign in to comment.