diff --git a/cmake/ThrustBuildCompilerTargets.cmake b/cmake/ThrustBuildCompilerTargets.cmake index bf0b31ed4..282d70a31 100644 --- a/cmake/ThrustBuildCompilerTargets.cmake +++ b/cmake/ThrustBuildCompilerTargets.cmake @@ -77,7 +77,7 @@ function(thrust_build_compiler_targets) # "Oh right, this is Visual Studio." list(APPEND cxx_compile_definitions "NOMINMAX") else() - append_option_if_available("-Werror" cxx_compile_options) + #append_option_if_available("-Werror" cxx_compile_options) append_option_if_available("-Wall" cxx_compile_options) append_option_if_available("-Wextra" cxx_compile_options) append_option_if_available("-Winit-self" cxx_compile_options) @@ -86,6 +86,7 @@ function(thrust_build_compiler_targets) append_option_if_available("-Wpointer-arith" cxx_compile_options) append_option_if_available("-Wunused-local-typedef" cxx_compile_options) append_option_if_available("-Wvla" cxx_compile_options) + append_option_if_available("-Wconversion" cxx_compile_options) # Disable GNU extensions (flag is clang only) append_option_if_available("-Wgnu" cxx_compile_options) diff --git a/examples/bucket_sort2d.cu b/examples/bucket_sort2d.cu index 9e3bb2720..aaa193c5a 100644 --- a/examples/bucket_sort2d.cu +++ b/examples/bucket_sort2d.cu @@ -37,8 +37,8 @@ struct point_to_bucket_index : public thrust::unary_function unsigned int operator()(const vec2& v) const { // find the raster indices of p's bucket - unsigned int x = static_cast(thrust::get<0>(v) * width); - unsigned int y = static_cast(thrust::get<1>(v) * height); + unsigned int x = static_cast(thrust::get<0>(v)) * width; + unsigned int y = static_cast(thrust::get<1>(v)) * height; // return the bucket's linear index return y * width + x; diff --git a/examples/cuda/range_view.cu b/examples/cuda/range_view.cu index 2ede62047..ce14c7165 100644 --- a/examples/cuda/range_view.cu +++ b/examples/cuda/range_view.cu @@ -181,7 +181,7 @@ __host__ __device__ void saxpy(float A, View1 X, View2 Y, View3 Z) { // Z = A * X + Y - const int size = X.size(); + const int size = static_cast(X.size()); thrust::for_each(thrust::device, thrust::make_counting_iterator(0), thrust::make_counting_iterator(size), diff --git a/examples/discrete_voronoi.cu b/examples/discrete_voronoi.cu index bfbf2242d..2d68e1e12 100644 --- a/examples/discrete_voronoi.cu +++ b/examples/discrete_voronoi.cu @@ -229,7 +229,7 @@ int main(void) } display_time(t); - std::cout <<" ( " << seeds.size() / (1e6 * t.elapsed()) << " MPixel/s ) " << std::endl; + std::cout <<" ( " << static_cast(seeds.size()) / (1e6 * t.elapsed()) << " MPixel/s ) " << std::endl; std::cout << "[Device to Host Copy]" << std::endl; t.restart(); diff --git a/examples/monte_carlo.cu b/examples/monte_carlo.cu index 4a11c4de8..221689f91 100644 --- a/examples/monte_carlo.cu +++ b/examples/monte_carlo.cu @@ -56,7 +56,7 @@ struct estimate_pi : public thrust::unary_function sum *= 4.0f; // divide by N - return sum / N; + return sum / static_cast(N); } }; @@ -70,7 +70,7 @@ int main(void) estimate_pi(), 0.0f, thrust::plus()); - estimate /= M; + estimate /= static_cast(M); std::cout << std::setprecision(3); std::cout << "pi is approximately " << estimate << std::endl; diff --git a/examples/monte_carlo_disjoint_sequences.cu b/examples/monte_carlo_disjoint_sequences.cu index 77b0d0086..eab74887e 100644 --- a/examples/monte_carlo_disjoint_sequences.cu +++ b/examples/monte_carlo_disjoint_sequences.cu @@ -62,7 +62,7 @@ struct estimate_pi : public thrust::unary_function sum *= 4.0f; // divide by N - return sum / N; + return sum / static_cast(N); } }; @@ -76,7 +76,7 @@ int main(void) estimate_pi(), 0.0f, thrust::plus()); - estimate /= M; + estimate /= static_cast(M); std::cout << "pi is around " << estimate << std::endl; diff --git a/examples/sort.cu b/examples/sort.cu index 1bbb5d897..97deb9423 100644 --- a/examples/sort.cu +++ b/examples/sort.cu @@ -19,7 +19,7 @@ void initialize(thrust::device_vector& v) thrust::default_random_engine rng(123456); thrust::uniform_int_distribution dist(2, 19); for(size_t i = 0; i < v.size(); i++) - v[i] = dist(rng) / 2.0f; + v[i] = static_cast(dist(rng)) / 2.0f; } void initialize(thrust::device_vector< thrust::pair >& v) diff --git a/testing/async/inclusive_scan/counting_iterator.cu b/testing/async/inclusive_scan/counting_iterator.cu index fe9fdeb80..f156f3833 100644 --- a/testing/async/inclusive_scan/counting_iterator.cu +++ b/testing/async/inclusive_scan/counting_iterator.cu @@ -33,7 +33,7 @@ struct test_counting_iterator { void operator()(std::size_t num_values) const { - num_values = unittest::truncate_to_max_representable(num_values); + num_values = static_cast(unittest::truncate_to_max_representable(num_values)); testing::async::test_policy_overloads>::run(num_values); } }; diff --git a/testing/cuda/for_each.cu b/testing/cuda/for_each.cu index be6a7738c..59b0ad828 100644 --- a/testing/cuda/for_each.cu +++ b/testing/cuda/for_each.cu @@ -74,7 +74,7 @@ void TestForEachDeviceSeq(const size_t n) thrust::host_vector h_input = unittest::random_integers(n); for(size_t i = 0; i < n; i++) - h_input[i] = ((size_t) h_input[i]) % output_size; + h_input[i] = static_cast(((size_t) h_input[i]) % output_size); thrust::device_vector d_input = h_input; @@ -105,7 +105,7 @@ void TestForEachDeviceDevice(const size_t n) thrust::host_vector h_input = unittest::random_integers(n); for(size_t i = 0; i < n; i++) - h_input[i] = ((size_t) h_input[i]) % output_size; + h_input[i] = static_cast(((size_t) h_input[i]) % output_size); thrust::device_vector d_input = h_input; diff --git a/testing/cuda/gather.cu b/testing/cuda/gather.cu index a9a8c9333..685ca921b 100644 --- a/testing/cuda/gather.cu +++ b/testing/cuda/gather.cu @@ -24,7 +24,7 @@ void TestGatherDevice(ExecutionPolicy exec, const size_t n) thrust::host_vector h_map = unittest::random_integers(n); for(size_t i = 0; i < n; i++) - h_map[i] = h_map[i] % source_size; + h_map[i] = h_map[i] % static_cast(source_size); thrust::device_vector d_map = h_map; @@ -117,7 +117,7 @@ void TestGatherIfDevice(ExecutionPolicy exec, const size_t n) thrust::host_vector h_map = unittest::random_integers(n); for(size_t i = 0; i < n; i++) - h_map[i] = h_map[i] % source_size; + h_map[i] = h_map[i] % static_cast(source_size); thrust::device_vector d_map = h_map; diff --git a/testing/cuda/scan_by_key.cu b/testing/cuda/scan_by_key.cu index e65560edf..d1de791e4 100644 --- a/testing/cuda/scan_by_key.cu +++ b/testing/cuda/scan_by_key.cu @@ -47,7 +47,7 @@ void TestScanByKeyDevice(ExecutionPolicy exec) thrust::host_vector h_vals = unittest::random_integers(n); for(size_t i = 0; i < n; i++) { - h_vals[i] = i % 10; + h_vals[i] = static_cast(i % 10); } thrust::device_vector d_vals = h_vals; diff --git a/testing/cuda/scatter.cu b/testing/cuda/scatter.cu index 52bd9755f..86d5d8b62 100644 --- a/testing/cuda/scatter.cu +++ b/testing/cuda/scatter.cu @@ -24,7 +24,7 @@ void TestScatterDevice(ExecutionPolicy exec) for(size_t i = 0; i < n; i++) { - h_map[i] = h_map[i] % output_size; + h_map[i] = h_map[i] % static_cast(output_size); } thrust::device_vector d_map = h_map; @@ -82,7 +82,7 @@ void TestScatterIfDevice(ExecutionPolicy exec) for(size_t i = 0; i < n; i++) { - h_map[i] = h_map[i] % output_size; + h_map[i] = h_map[i] % static_cast(output_size); } thrust::device_vector d_map = h_map; diff --git a/testing/for_each.cu b/testing/for_each.cu index 8040e5f78..2c7a5212e 100644 --- a/testing/for_each.cu +++ b/testing/for_each.cu @@ -199,7 +199,7 @@ void TestForEach(const size_t n) thrust::host_vector h_input = unittest::random_integers(n); for(size_t i = 0; i < n; i++) - h_input[i] = ((size_t) h_input[i]) % output_size; + h_input[i] = static_cast(((size_t) h_input[i]) % output_size); thrust::device_vector d_input = h_input; @@ -232,7 +232,7 @@ void TestForEachN(const size_t n) thrust::host_vector h_input = unittest::random_integers(n); for(size_t i = 0; i < n; i++) - h_input[i] = ((size_t) h_input[i]) % output_size; + h_input[i] = static_cast(((size_t) h_input[i]) % output_size); thrust::device_vector d_input = h_input; @@ -280,7 +280,8 @@ void _TestForEachWithLargeTypes(void) thrust::host_vector< FixedVector > h_data(n); for(size_t i = 0; i < h_data.size(); i++) - h_data[i] = FixedVector(i); + //h_data[i] = static_cast(FixedVector(i)); + h_data[i] = FixedVector(static_cast(i)); thrust::device_vector< FixedVector > d_data = h_data; @@ -321,6 +322,7 @@ void _TestForEachNWithLargeTypes(void) thrust::host_vector< FixedVector > h_data(n); for(size_t i = 0; i < h_data.size(); i++) + //h_data[i] = static_cast(FixedVector(i)); h_data[i] = FixedVector(i); thrust::device_vector< FixedVector > d_data = h_data; diff --git a/testing/gather.cu b/testing/gather.cu index c164e44b2..1b2a3b42f 100644 --- a/testing/gather.cu +++ b/testing/gather.cu @@ -89,7 +89,7 @@ void TestGather(const size_t n) thrust::host_vector h_map = unittest::random_integers(n); for(size_t i = 0; i < n; i++) - h_map[i] = h_map[i] % source_size; + h_map[i] = h_map[i] % static_cast(source_size); thrust::device_vector d_map = h_map; @@ -118,7 +118,7 @@ void TestGatherToDiscardIterator(const size_t n) thrust::host_vector h_map = unittest::random_integers(n); for(size_t i = 0; i < n; i++) - h_map[i] = h_map[i] % source_size; + h_map[i] = h_map[i] % static_cast(source_size); thrust::device_vector d_map = h_map; @@ -244,7 +244,7 @@ void TestGatherIf(const size_t n) thrust::host_vector h_map = unittest::random_integers(n); for(size_t i = 0; i < n; i++) - h_map[i] = h_map[i] % source_size; + h_map[i] = h_map[i] % static_cast(source_size); thrust::device_vector d_map = h_map; @@ -282,7 +282,7 @@ void TestGatherIfToDiscardIterator(const size_t n) thrust::host_vector h_map = unittest::random_integers(n); for(size_t i = 0; i < n; i++) - h_map[i] = h_map[i] % source_size; + h_map[i] = h_map[i] % static_cast(source_size); thrust::device_vector d_map = h_map; diff --git a/testing/pair_transform.cu b/testing/pair_transform.cu index 612a77af0..3abb375c3 100644 --- a/testing/pair_transform.cu +++ b/testing/pair_transform.cu @@ -20,7 +20,8 @@ struct add_pairs __host__ __device__ Pair1 operator()(const Pair1 &x, const Pair2 &y) { - return thrust::make_pair(x.first + y.first, x.second + y.second); + return thrust::make_pair(x.first + static_cast(y.first), + x.second + static_cast(y.second)); } // end operator() }; // end add_pairs diff --git a/testing/reduce.cu b/testing/reduce.cu index cb08bc889..e3c976ea1 100644 --- a/testing/reduce.cu +++ b/testing/reduce.cu @@ -11,7 +11,7 @@ template __host__ __device__ T operator()(T lhs, T rhs) const { - return ((lhs % 10) + (rhs % 10)) % 10; + return static_cast(((lhs % 10) + (rhs % 10)) % 10); } }; diff --git a/testing/scan_by_key.cu b/testing/scan_by_key.cu index 8d0cd20b9..e9f58a9c5 100644 --- a/testing/scan_by_key.cu +++ b/testing/scan_by_key.cu @@ -376,7 +376,7 @@ void TestInclusiveScanByKey(const size_t n) thrust::host_vector h_vals = unittest::random_integers(n); for(size_t i = 0; i < n; i++) - h_vals[i] = static_cast(i % 10); + h_vals[i] = static_cast(i % 10); thrust::device_vector d_vals = h_vals; thrust::host_vector h_output(n); @@ -406,7 +406,7 @@ void TestExclusiveScanByKey(const size_t n) thrust::host_vector h_vals = unittest::random_integers(n); for(size_t i = 0; i < n; i++) { - h_vals[i] = static_cast(i % 10); + h_vals[i] = static_cast(i % 10); } thrust::device_vector d_vals = h_vals; @@ -443,7 +443,7 @@ void TestInclusiveScanByKeyInPlace(const size_t n) thrust::host_vector h_vals = unittest::random_integers(n); for(size_t i = 0; i < n; i++) { - h_vals[i] = static_cast(i % 10); + h_vals[i] = static_cast(i % 10); } thrust::device_vector d_vals = h_vals; @@ -477,7 +477,7 @@ void TestExclusiveScanByKeyInPlace(const size_t n) thrust::host_vector h_vals = unittest::random_integers(n); for(size_t i = 0; i < n; i++) { - h_vals[i] = static_cast(i % 10); + h_vals[i] = static_cast(i % 10); } thrust::device_vector d_vals = h_vals; diff --git a/testing/scatter.cu b/testing/scatter.cu index ffd56f27c..b28557604 100644 --- a/testing/scatter.cu +++ b/testing/scatter.cu @@ -98,7 +98,7 @@ void TestScatter(const size_t n) thrust::host_vector h_map = unittest::random_integers(n); for(size_t i = 0; i < n; i++) - h_map[i] = h_map[i] % output_size; + h_map[i] = h_map[i] % static_cast(output_size); thrust::device_vector d_map = h_map; @@ -124,7 +124,7 @@ void TestScatterToDiscardIterator(const size_t n) thrust::host_vector h_map = unittest::random_integers(n); for(size_t i = 0; i < n; i++) - h_map[i] = h_map[i] % output_size; + h_map[i] = h_map[i] % static_cast(output_size); thrust::device_vector d_map = h_map; @@ -241,7 +241,7 @@ void TestScatterIf(const size_t n) thrust::host_vector h_map = unittest::random_integers(n); for(size_t i = 0; i < n; i++) - h_map[i] = h_map[i] % output_size; + h_map[i] = h_map[i] % static_cast(output_size); thrust::device_vector d_map = h_map; @@ -267,7 +267,7 @@ void TestScatterIfToDiscardIterator(const size_t n) thrust::host_vector h_map = unittest::random_integers(n); for(size_t i = 0; i < n; i++) - h_map[i] = h_map[i] % output_size; + h_map[i] = h_map[i] % static_cast(output_size); thrust::device_vector d_map = h_map; diff --git a/testing/set_difference_by_key.cu b/testing/set_difference_by_key.cu index 29dbb68fc..4de23d12d 100644 --- a/testing/set_difference_by_key.cu +++ b/testing/set_difference_by_key.cu @@ -259,7 +259,7 @@ void TestSetDifferenceByKeyMultiset(const size_t n) { int temp = static_cast(*i); temp %= 13; - *i = temp; + *i = static_cast(temp); } thrust::host_vector h_a_key(vec.begin(), vec.begin() + n); diff --git a/testing/set_intersection_by_key.cu b/testing/set_intersection_by_key.cu index d82ee04ad..1d8e3bb23 100644 --- a/testing/set_intersection_by_key.cu +++ b/testing/set_intersection_by_key.cu @@ -243,7 +243,7 @@ void TestSetIntersectionByKeyMultiset(const size_t n) { int temp = static_cast(*i); temp %= 13; - *i = temp; + *i = static_cast(temp); } thrust::host_vector h_a_key(vec.begin(), vec.begin() + n); diff --git a/testing/set_symmetric_difference.cu b/testing/set_symmetric_difference.cu index dde145fec..b600271f0 100644 --- a/testing/set_symmetric_difference.cu +++ b/testing/set_symmetric_difference.cu @@ -177,7 +177,7 @@ void TestSetSymmetricDifferenceMultiset(const size_t n) { int temp = static_cast(*i); temp %= 13; - *i = temp; + *i = static_cast(temp); } thrust::host_vector h_a(vec.begin(), vec.begin() + n); diff --git a/testing/set_symmetric_difference_by_key.cu b/testing/set_symmetric_difference_by_key.cu index 98e416af8..1facd2bfd 100644 --- a/testing/set_symmetric_difference_by_key.cu +++ b/testing/set_symmetric_difference_by_key.cu @@ -263,7 +263,7 @@ void TestSetSymmetricDifferenceByKeyMultiset(const size_t n) { int temp = static_cast(*i); temp %= 13; - *i = temp; + *i = static_cast(temp); } thrust::host_vector h_a_key(vec.begin(), vec.begin() + n); diff --git a/testing/set_union_by_key.cu b/testing/set_union_by_key.cu index 7d58ebf4f..3c458a563 100644 --- a/testing/set_union_by_key.cu +++ b/testing/set_union_by_key.cu @@ -263,7 +263,7 @@ void TestSetUnionByKeyMultiset(const size_t n) { int temp = static_cast(*i); temp %= 13; - *i = temp; + *i = static_cast(temp); } thrust::host_vector h_a_key(vec.begin(), vec.begin() + n); diff --git a/testing/shuffle.cu b/testing/shuffle.cu index 77e660c00..813680a2c 100644 --- a/testing/shuffle.cu +++ b/testing/shuffle.cu @@ -448,7 +448,8 @@ void TestShuffleKeyPosition() { double expected_average_position = static_cast(m - 1) / 2; double chi_squared = 0.0; for (auto j = 0ull; j < m; j++) { - double average_position = static_cast(index_sum[j]) / num_samples; + double average_position = static_cast(index_sum[j]) / + static_cast(num_samples); chi_squared += std::pow(expected_average_position - average_position, 2) / expected_average_position; } @@ -495,9 +496,11 @@ void TestShuffleUniformPermutation() { ASSERT_EQUAL(permutation_counts.size(), total_permutations); double chi_squared = 0.0; - double expected_count = static_cast(num_samples) / total_permutations; + double expected_count = static_cast(num_samples) / + static_cast(total_permutations); for (auto kv : permutation_counts) { - chi_squared += std::pow(expected_count - kv.second, 2) / expected_count; + chi_squared += std::pow(expected_count - static_cast(kv.second), 2)/ + expected_count; } double p_score = CephesFunctions::cephes_igamc( (double)(total_permutations - 1) / 2.0, chi_squared / 2.0); @@ -576,7 +579,8 @@ void TestShuffleEvenDistribution() { } } - const double expected_occurances = (double)num_samples / shuffle_size; + const double expected_occurances = static_cast(num_samples) / + static_cast(shuffle_size); for (uint64_t i = 0; i < shuffle_size; i++) { double chi_squared_pos = 0.0; double chi_squared_num = 0.0; diff --git a/testing/sort_by_key_variable_bits.cu b/testing/sort_by_key_variable_bits.cu index 379160860..f6f32b50e 100644 --- a/testing/sort_by_key_variable_bits.cu +++ b/testing/sort_by_key_variable_bits.cu @@ -24,7 +24,7 @@ struct TestSortByKeyVariableBits { thrust::host_vector h_keys = unittest::random_integers(n); - const T mask = (1 << num_bits) - 1; + const T mask = static_cast((1 << num_bits) - 1); for(size_t i = 0; i < n; i++) h_keys[i] &= mask; diff --git a/testing/sort_variable_bits.cu b/testing/sort_variable_bits.cu index 4192e3da6..953e53659 100644 --- a/testing/sort_variable_bits.cu +++ b/testing/sort_variable_bits.cu @@ -25,7 +25,8 @@ struct TestSortVariableBits size_t mask = (1 << num_bits) - 1; for(size_t i = 0; i < n; i++) - h_keys[i] &= mask; + // mstack adding static_cast + h_keys[i] &= static_cast(mask); thrust::host_vector reference = h_keys; thrust::device_vector d_keys = h_keys; diff --git a/testing/transform_output_iterator.cu b/testing/transform_output_iterator.cu index 403862256..a4756e071 100644 --- a/testing/transform_output_iterator.cu +++ b/testing/transform_output_iterator.cu @@ -48,7 +48,8 @@ void TestMakeTransformOutputIterator(void) Vector output(4); // initialize input - thrust::sequence(input.begin(), input.end(), 1); + // mstack adding static_cast + thrust::sequence(input.begin(), input.end(), static_cast(1)); thrust::copy(input.begin(), input.end(), thrust::make_transform_output_iterator(output.begin(), UnaryFunction())); diff --git a/testing/transform_reduce.cu b/testing/transform_reduce.cu index 3ff3159d6..9e30bf0f0 100644 --- a/testing/transform_reduce.cu +++ b/testing/transform_reduce.cu @@ -120,7 +120,9 @@ void TestTransformReduceCountingIterator(void) thrust::counting_iterator first(1); - T result = thrust::transform_reduce(first, first + 3, thrust::negate(), 0, thrust::plus()); + // mstack adding static_cast + //T result = thrust::transform_reduce(first, first + 3, thrust::negate(), 0, thrust::plus()); + T result = static_cast(thrust::transform_reduce(first, first + 3, thrust::negate(), 0, thrust::plus())); ASSERT_EQUAL(result, -6); } diff --git a/testing/unittest/assertions.h b/testing/unittest/assertions.h index 855d705a4..3511f90dc 100644 --- a/testing/unittest/assertions.h +++ b/testing/unittest/assertions.h @@ -118,6 +118,8 @@ template void assert_equal(T1 a, T2 b, const std::string& filename = "unknown", int lineno = -1) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" if(!(a == b)){ unittest::UnitTestFailure f; f << "[" << filename << ":" << lineno << "] "; @@ -125,6 +127,7 @@ void assert_equal(T1 a, T2 b, f << " [type='" << type_name() << "']"; throw f; } +#pragma GCC diagnostic pop } void assert_equal(char a, char b, @@ -144,6 +147,8 @@ template void assert_equal_quiet(const T1& a, const T2& b, const std::string& filename = "unknown", int lineno = -1) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" if(!(a == b)){ unittest::UnitTestFailure f; f << "[" << filename << ":" << lineno << "] "; @@ -151,6 +156,7 @@ void assert_equal_quiet(const T1& a, const T2& b, f << " [type='" << type_name() << "']"; throw f; } +#pragma GCC diagnostic pop } //// diff --git a/thrust/detail/allocator/allocator_traits.inl b/thrust/detail/allocator/allocator_traits.inl index 275330094..70108f513 100644 --- a/thrust/detail/allocator/allocator_traits.inl +++ b/thrust/detail/allocator/allocator_traits.inl @@ -225,7 +225,7 @@ template >::type construct(Alloc &, T *p, const Arg1 &arg1) { - ::new(static_cast(p)) T(arg1); + ::new(static_cast(p)) T(static_cast(arg1)); } #if THRUST_CPP_DIALECT >= 2011 @@ -256,7 +256,7 @@ template >::type construct(Alloc &, T* p, Args&&... args) { - ::new(static_cast(p)) T(THRUST_FWD(args)...); + ::new(static_cast(p)) T(THRUST_FWD(static_cast(args))...); } #endif diff --git a/thrust/detail/function.h b/thrust/detail/function.h index 66e6d4e4e..29eb7344e 100644 --- a/thrust/detail/function.h +++ b/thrust/detail/function.h @@ -19,6 +19,9 @@ #include #include +// mstack adding type_traits +#include + THRUST_NAMESPACE_BEGIN namespace detail @@ -88,8 +91,16 @@ struct wrapped_function inline __host__ __device__ Result operator()(Argument1& x, const Argument2& y) const { + // mstack adding change +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" return static_cast(m_f(thrust::raw_reference_cast(x), thrust::raw_reference_cast(y))); +#pragma GCC diagnostic pop + //using f_type = std::invoke_result_t; + //using f_type = std::result_of::type; + //return static_cast(m_f(static_cast(thrust::raw_reference_cast(x)), + // static_cast(thrust::raw_reference_cast(y)))); } }; // end wrapped_function diff --git a/thrust/detail/internal_functional.h b/thrust/detail/internal_functional.h index a0c4056fe..87998df9d 100644 --- a/thrust/detail/internal_functional.h +++ b/thrust/detail/internal_functional.h @@ -201,6 +201,8 @@ template T &lvalue = const_cast(x); // this assigns correctly whether x is a true reference or proxy + // mstack problem area + // lvalue = static_cast(gen()); lvalue = gen(); } @@ -321,7 +323,14 @@ template >::type operator()(Tuple t) { + typedef typename thrust::tuple_element<1,decltype(t)>::type this_type; + // mstack adding static_cast + //thrust::get<1>(t) = static_cast(f(thrust::get<0>(t))); + //thrust::get<1>(t) = f(static_cast(thrust::get<0>(t))); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" thrust::get<1>(t) = f(thrust::get<0>(t)); +#pragma GCC diagnostic pop } }; diff --git a/thrust/detail/tuple.inl b/thrust/detail/tuple.inl index f4930bf4b..a1656ff87 100644 --- a/thrust/detail/tuple.inl +++ b/thrust/detail/tuple.inl @@ -351,7 +351,8 @@ template template inline __host__ __device__ - cons( const cons& u ) : head(u.head), tail(u.tail) {} + cons( const cons& u ) : head(static_cast(u.head)), tail(u.tail) {} + //cons( const cons& u ) : head(u.head), tail(u.tail) {} #if THRUST_CPP_DIALECT >= 2011 cons(const cons &) = default; @@ -361,7 +362,10 @@ template template inline __host__ __device__ cons& operator=( const cons& u ) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" head=u.head; tail=u.tail; return *this; +#pragma GCC diagnostic pop } // must define assignment operator explicitly, implicit version is @@ -458,7 +462,8 @@ template template inline __host__ __device__ - cons( const cons& u ) : head(u.head) {} + cons( const cons& u ) : head(static_cast(u.head)) {} + //cons( const cons& u ) : head(u.head) {} #if THRUST_CPP_DIALECT >= 2011 cons(const cons &) = default; @@ -469,7 +474,12 @@ template inline __host__ __device__ cons& operator=(const cons& u ) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" head = u.head; +#pragma GCC diagnostic pop + //head = static_cast(u.head); + //head = static_cast(u.head); return *this; } diff --git a/thrust/detail/vector_base.inl b/thrust/detail/vector_base.inl index ab94429a8..30584e4a2 100644 --- a/thrust/detail/vector_base.inl +++ b/thrust/detail/vector_base.inl @@ -202,7 +202,7 @@ template IteratorOrIntegralType value, true_type) { - fill_init(n,value); + fill_init(n,static_cast(value)); } // end vector_base::init_dispatch() template diff --git a/thrust/iterator/iterator_adaptor.h b/thrust/iterator/iterator_adaptor.h index 67d4866b9..505be86d8 100644 --- a/thrust/iterator/iterator_adaptor.h +++ b/thrust/iterator/iterator_adaptor.h @@ -204,6 +204,7 @@ template(m_iterator + n); + //m_iterator = m_iterator + static_cast(n); } __thrust_exec_check_disable__ diff --git a/thrust/iterator/transform_iterator.h b/thrust/iterator/transform_iterator.h index 5afb5f37b..b44782820 100644 --- a/thrust/iterator/transform_iterator.h +++ b/thrust/iterator/transform_iterator.h @@ -312,6 +312,7 @@ template ::type const& x = *this->base(); + // The issue is that x needs to be the type specified in m_f, but that is unknown return m_f(x); } diff --git a/thrust/random/detail/normal_distribution_base.h b/thrust/random/detail/normal_distribution_base.h index a42e80014..fa015c455 100644 --- a/thrust/random/detail/normal_distribution_base.h +++ b/thrust/random/detail/normal_distribution_base.h @@ -65,7 +65,7 @@ template } // Convert to floating point in [0,0.5) - RealType p = u*S1 + S2; + RealType p = static_cast(u*S1 + S2); // Apply inverse error function return mean + stddev * S3 * erfcinv(2 * p); diff --git a/thrust/random/detail/subtract_with_carry_engine.inl b/thrust/random/detail/subtract_with_carry_engine.inl index 21c22fe77..f19c5869e 100644 --- a/thrust/random/detail/subtract_with_carry_engine.inl +++ b/thrust/random/detail/subtract_with_carry_engine.inl @@ -65,7 +65,7 @@ template { // XXX we probably need to cache these m_x[m_k] in a register // maybe we need to cache the use of all member variables - int short_index = m_k - short_lag; + int short_index = m_k - static_cast(short_lag); if(short_index < 0) short_index += long_lag; result_type xi; diff --git a/thrust/random/detail/xor_combine_engine_max.h b/thrust/random/detail/xor_combine_engine_max.h index 0756ff9e0..b16158b70 100644 --- a/thrust/random/detail/xor_combine_engine_max.h +++ b/thrust/random/detail/xor_combine_engine_max.h @@ -287,14 +287,14 @@ template::value - 1 + two_to_the_power(w-s1)>::value - 1 >::value; static const result_type m2 = math::min< result_type, result_type(Engine2::max - Engine2::min), - two_to_the_power::value - 1 + two_to_the_power(w-s2)>::value - 1 >::value; static const result_type s = s1 - s2; diff --git a/thrust/random/linear_feedback_shift_engine.h b/thrust/random/linear_feedback_shift_engine.h index a46c6d8ab..9019f591f 100644 --- a/thrust/random/linear_feedback_shift_engine.h +++ b/thrust/random/linear_feedback_shift_engine.h @@ -93,7 +93,7 @@ template static const result_type wordmask = detail::linear_feedback_shift_engine_wordmask< result_type, - w + static_cast(w) >::value; /*! \endcond */ diff --git a/thrust/system/cuda/detail/async/reduce.h b/thrust/system/cuda/detail/async/reduce.h index 5096dcc35..3c9899a92 100644 --- a/thrust/system/cuda/detail/async/reduce.h +++ b/thrust/system/cuda/detail/async/reduce.h @@ -195,9 +195,10 @@ auto async_reduce( , T init , BinaryOp op ) +// mstack adding static_cast THRUST_RETURNS( thrust::system::cuda::detail::async_reduce_n( - policy, first, distance(first, last), init, op + policy, first, static_cast(distance(first, last)), init, op ) ) @@ -331,9 +332,10 @@ auto async_reduce_into( , T init , BinaryOp op ) +// mstack adding static_cast THRUST_RETURNS( thrust::system::cuda::detail::async_reduce_into_n( - policy, first, distance(first, last), output, init, op + policy, first, static_cast(distance(first, last)), output, init, op ) ) diff --git a/thrust/system/cuda/detail/async/sort.h b/thrust/system/cuda/detail/async/sort.h index e8f92d7f7..f6e1bee07 100644 --- a/thrust/system/cuda/detail/async/sort.h +++ b/thrust/system/cuda/detail/async/sort.h @@ -302,7 +302,7 @@ invoke_radix_sort( tmp_ptr , tmp_size , keys - , n + , static_cast(n) , 0 , sizeof(T) * 8 , stream @@ -328,7 +328,7 @@ invoke_radix_sort( tmp_ptr , tmp_size , keys - , n + , static_cast(n) , 0 , sizeof(T) * 8 , stream diff --git a/thrust/system/cuda/detail/reduce.h b/thrust/system/cuda/detail/reduce.h index ffb9c53dc..d3e5bf574 100644 --- a/thrust/system/cuda/detail/reduce.h +++ b/thrust/system/cuda/detail/reduce.h @@ -950,7 +950,7 @@ T reduce_n_impl(execution_policy& policy, >::Dispatch), num_items, (NULL, tmp_size, first, reinterpret_cast(NULL), - num_items_fixed, binary_op, init, stream, + static_cast(num_items_fixed), binary_op, init, stream, THRUST_DEBUG_SYNC_FLAG)); cuda_cub::throw_on_error(status, "after reduction step 1"); @@ -978,7 +978,7 @@ T reduce_n_impl(execution_policy& policy, >::Dispatch), num_items, (tmp_ptr, tmp_size, first, ret_ptr, - num_items_fixed, binary_op, init, stream, + static_cast(num_items_fixed), binary_op, init, stream, THRUST_DEBUG_SYNC_FLAG)); cuda_cub::throw_on_error(status, "after reduction step 2"); diff --git a/thrust/system/detail/generic/sequence.inl b/thrust/system/detail/generic/sequence.inl index 0e11dd75d..593445bb3 100644 --- a/thrust/system/detail/generic/sequence.inl +++ b/thrust/system/detail/generic/sequence.inl @@ -77,7 +77,7 @@ struct compute_sequence_value:: __host__ __device__ T operator()(std::size_t i) const { - return init + step * static_cast(i); + return static_cast(init + step * static_cast(i)); } }; } diff --git a/thrust/system/detail/generic/shuffle.inl b/thrust/system/detail/generic/shuffle.inl index baece51be..7e338c150 100644 --- a/thrust/system/detail/generic/shuffle.inl +++ b/thrust/system/detail/generic/shuffle.inl @@ -94,6 +94,7 @@ class feistel_bijection { } static constexpr std::uint32_t num_rounds = 24; + std::uint64_t right_side_bits; std::uint64_t left_side_bits; std::uint64_t right_side_mask; diff --git a/thrust/system/detail/sequential/general_copy.h b/thrust/system/detail/sequential/general_copy.h index 6ea87bbac..2a5f49bee 100644 --- a/thrust/system/detail/sequential/general_copy.h +++ b/thrust/system/detail/sequential/general_copy.h @@ -72,6 +72,9 @@ typename thrust::detail::enable_if< >::type iter_assign(OutputIterator dst, InputIterator src) { + using OutputType = typename thrust::iterator_traits::value_type; + + //*dst = static_cast(*src); *dst = *src; } @@ -84,9 +87,11 @@ typename thrust::detail::disable_if< >::type iter_assign(OutputIterator dst, InputIterator src) { + //using OutputType = typename thrust::iterator_traits::value_type; typedef typename thrust::iterator_value::type value_type; // insert a temporary and hope for the best + //*dst = static_cast(*src); *dst = static_cast(*src); } diff --git a/thrust/system/detail/sequential/scan.h b/thrust/system/detail/sequential/scan.h index c5fce2475..290544044 100644 --- a/thrust/system/detail/sequential/scan.h +++ b/thrust/system/detail/sequential/scan.h @@ -54,6 +54,8 @@ __host__ __device__ // Use the input iterator's value type per https://wg21.link/P0571 using ValueType = typename thrust::iterator_value::type; + // Use for explicit type conversion + using OutputType = typename thrust::iterator_value::type; // wrap binary_op thrust::detail::wrapped_function< @@ -65,10 +67,13 @@ __host__ __device__ { ValueType sum = *first; + *result = static_cast(*first); *result = *first; for(++first, ++result; first != last; ++first, ++result) *result = sum = wrapped_binary_op(sum,*first); + //*result = wrapped_binary_op(sum,*first); + //sum = wrapped_binary_op(sum,*first); } return result; @@ -93,20 +98,24 @@ __host__ __device__ // Use the initial value type per https://wg21.link/P0571 using ValueType = InitialValueType; + // Use for explicit type conversion + using InputType = typename thrust::iterator_value::type; + // Use for explicit type conversion + using OutputType = typename thrust::iterator_value::type; if(first != last) { - ValueType tmp = *first; // temporary value allows in-situ scan + ValueType tmp = static_cast(*first); // temporary value allows in-situ scan ValueType sum = init; *result = sum; - sum = binary_op(sum, tmp); + sum = static_cast(binary_op(sum, tmp)); for(++first, ++result; first != last; ++first, ++result) { - tmp = *first; + tmp = static_cast(*first); *result = sum; - sum = binary_op(sum, tmp); + sum = static_cast(binary_op(sum, tmp)); } } diff --git a/thrust/system/detail/sequential/scan_by_key.h b/thrust/system/detail/sequential/scan_by_key.h index c428c1050..270e01484 100644 --- a/thrust/system/detail/sequential/scan_by_key.h +++ b/thrust/system/detail/sequential/scan_by_key.h @@ -53,6 +53,7 @@ __host__ __device__ { using KeyType = typename thrust::iterator_traits::value_type; using ValueType = typename thrust::iterator_traits::value_type; + using OutputType = typename thrust::iterator_traits::value_type; // wrap binary_op thrust::detail::wrapped_function< @@ -65,7 +66,7 @@ __host__ __device__ KeyType prev_key = *first1; ValueType prev_value = *first2; - *result = prev_value; + *result = static_cast(prev_value); for(++first1, ++first2, ++result; first1 != last1; @@ -73,11 +74,18 @@ __host__ __device__ { KeyType key = *first1; - if(binary_pred(prev_key, key)) - *result = prev_value = wrapped_binary_op(prev_value,*first2); - else - *result = prev_value = *first2; - + if(binary_pred(prev_key, key)) { + //*result = static_cast(prev_value) = wrapped_binary_op(prev_value,*first2); + //*result = prev_value = wrapped_binary_op(prev_value,*first2); + *result = static_cast(wrapped_binary_op(prev_value,*first2)); + prev_value = static_cast(wrapped_binary_op(prev_value,*first2)); + } + else { + //*result = static_cast(prev_value) = *first2; + //*result = prev_value = *first2; + *result = static_cast(*first2); + prev_value = static_cast(*first2); + } prev_key = key; } } @@ -117,7 +125,7 @@ __host__ __device__ // first one is init *result = next; - next = binary_op(next, temp_value); + next = static_cast(binary_op(next, temp_value)); for(++first1, ++first2, ++result; first1 != last1; @@ -132,7 +140,7 @@ __host__ __device__ next = init; // reset sum *result = next; - next = binary_op(next, temp_value); + next = static_cast(binary_op(next, temp_value)); temp_key = key; } diff --git a/thrust/system/detail/sequential/stable_radix_sort.inl b/thrust/system/detail/sequential/stable_radix_sort.inl index 83d95ebfd..bbc62dc74 100644 --- a/thrust/system/detail/sequential/stable_radix_sort.inl +++ b/thrust/system/detail/sequential/stable_radix_sort.inl @@ -163,7 +163,7 @@ template inline __host__ __device__ size_t operator()(KeyType key) { - const EncodedType x = encode(key); + const EncodedType x = static_cast(encode(key)); // note that we mutate the histogram here return histogram[(x >> bit_shift) & BitMask]++; @@ -261,7 +261,7 @@ void radix_sort(sequential::execution_policy &exec, // compute histograms for(size_t i = 0; i < N; i++) { - const EncodedType x = encode(keys1[i]); + const EncodedType x = static_cast(encode(keys1[i])); for(unsigned int j = 0; j < NumHistograms; j++) {