Updates will be applied April 15th at 12pm EDT (UTC-0400). GitLab could be a little slow between 12 - 12:45pm EDT.

Commit 66aa10aa authored by Kenneth Moreland's avatar Kenneth Moreland

Fix issues with warnings about data loss from type conversion

Fix compile warnings that come up with the flags

  -Wconversion -Wno-sign-conversion

This catches several instances (mostly in the testing framework) where
types are implicitly converted. I expect these changes to fix some of
the warnings we are seeing in MSVC.

I was going to add these flags to the list of extra warning flags, but
unfortunately the Thrust library has several warnings of these types,
and I don't know a good way to turn on the warnings for our code but
turn them off for Thrust.
parent 29319d1c
......@@ -188,31 +188,30 @@ struct VecTraitsBasic {
return vtkm::Vec<ScalarType,1>(vector);
}
};
}
} // namespace internal
} // anonymous namespace
#define VTKM_BASIC_TYPE_VECTOR(type) \
template<> \
struct VecTraits<type> \
: public vtkm::internal::VecTraitsBasic<type> { }/*; \
template<> \
struct VecTraits<const type> \
: public vtkm::internal::VecTraitsBasic<type> { }*/
namespace vtkm { \
template<> \
struct VecTraits<type> \
: public vtkm::internal::VecTraitsBasic<type> { }; \
}
/// Allows you to treat basic types as if they were vectors.
VTKM_BASIC_TYPE_VECTOR(vtkm::Float32);
VTKM_BASIC_TYPE_VECTOR(vtkm::Float64);
VTKM_BASIC_TYPE_VECTOR(vtkm::Int8);
VTKM_BASIC_TYPE_VECTOR(vtkm::UInt8);
VTKM_BASIC_TYPE_VECTOR(vtkm::Int16);
VTKM_BASIC_TYPE_VECTOR(vtkm::UInt16);
VTKM_BASIC_TYPE_VECTOR(vtkm::Int32);
VTKM_BASIC_TYPE_VECTOR(vtkm::UInt32);
VTKM_BASIC_TYPE_VECTOR(vtkm::Int64);
VTKM_BASIC_TYPE_VECTOR(vtkm::UInt64);
#undef VTKM_BASIC_TYPE_VECTOR
}
VTKM_BASIC_TYPE_VECTOR(vtkm::Float32)
VTKM_BASIC_TYPE_VECTOR(vtkm::Float64)
VTKM_BASIC_TYPE_VECTOR(vtkm::Int8)
VTKM_BASIC_TYPE_VECTOR(vtkm::UInt8)
VTKM_BASIC_TYPE_VECTOR(vtkm::Int16)
VTKM_BASIC_TYPE_VECTOR(vtkm::UInt16)
VTKM_BASIC_TYPE_VECTOR(vtkm::Int32)
VTKM_BASIC_TYPE_VECTOR(vtkm::UInt32)
VTKM_BASIC_TYPE_VECTOR(vtkm::Int64)
VTKM_BASIC_TYPE_VECTOR(vtkm::UInt64)
//#undef VTKM_BASIC_TYPE_VECTOR
#endif //vtk_m_VecTraits_h
......@@ -519,7 +519,7 @@ VTKM_CONT_EXPORT
vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagBasic>
make_ArrayHandle(const std::vector<T,Allocator> &array)
{
return make_ArrayHandle(&array.front(), array.size());
return make_ArrayHandle(&array.front(), static_cast<vtkm::Id>(array.size()));
}
}
......
......@@ -23,6 +23,8 @@
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/StorageImplicit.h>
#include <vtkm/VecTraits.h>
namespace vtkm {
namespace cont {
......@@ -32,6 +34,9 @@ namespace internal {
template <class CountingValueType>
class ArrayPortalCounting
{
typedef typename vtkm::VecTraits<CountingValueType>::ComponentType
ComponentType;
public:
typedef CountingValueType ValueType;
......@@ -71,7 +76,9 @@ public:
vtkm::Id GetNumberOfValues() const { return this->NumberOfValues; }
VTKM_EXEC_CONT_EXPORT
ValueType Get(vtkm::Id index) const { return StartingValue+ValueType(index); }
ValueType Get(vtkm::Id index) const {
return StartingValue + ValueType(ComponentType(index));
}
private:
ValueType StartingValue;
......
......@@ -33,60 +33,60 @@ namespace cont {
namespace {
struct compute_info
{
compute_info(cudaDeviceProp prop, int index)
{
this->Index = index;
this->Major = prop.major;
compute_info(cudaDeviceProp prop, int index)
{
this->Index = index;
this->Major = prop.major;
this->MemorySize = prop.totalGlobalMem;
this->Performance = prop.multiProcessorCount *
prop.maxThreadsPerMultiProcessor *
(prop.clockRate / 100000.0f);
this->MemorySize = prop.totalGlobalMem;
this->Performance = prop.multiProcessorCount *
prop.maxThreadsPerMultiProcessor *
(prop.clockRate / 100000.0f);
//9999 is equal to emulation make sure it is a super bad device
if(this->Major >= 9999)
{
this->Major = -1;
this->Performance = -1;
//9999 is equal to emulation make sure it is a super bad device
if(this->Major >= 9999)
{
this->Major = -1;
this->Performance = -1;
}
}
}
//sort from fastest to slowest
bool operator<(const compute_info other) const
{
//if we are both SM2 or greater check performance
//if we both the same SM level check performance
if( (this->Major >= 2 && other.Major >= 2) ||
(this->Major == other.Major) )
//sort from fastest to slowest
bool operator<(const compute_info other) const
{
return betterPerfomance(other);
//if we are both SM2 or greater check performance
//if we both the same SM level check performance
if( (this->Major >= 2 && other.Major >= 2) ||
(this->Major == other.Major) )
{
return betterPerfomance(other);
}
//prefer the greater SM otherwise
return this->Major > other.Major;
}
//prefer the greater SM otherwise
return this->Major > other.Major;
}
bool betterPerfomance(const compute_info other) const
{
if ( this->Performance == other.Performance)
bool betterPerfomance(const compute_info other) const
{
if( this->MemorySize == other.MemorySize )
if ( this->Performance == other.Performance)
{
if( this->MemorySize == other.MemorySize )
{
//prefer first device over second device
//this will be subjective I bet
return this->Index < other.Index;
//prefer first device over second device
//this will be subjective I bet
return this->Index < other.Index;
}
return this->MemorySize > other.MemorySize;
return this->MemorySize > other.MemorySize;
}
return this->Performance > other.Performance;
}
return this->Performance > other.Performance;
}
int GetIndex() const { return Index; }
int GetIndex() const { return Index; }
private:
int Index;
int Major;
int MemorySize;
int Performance;
int Index;
int Major;
size_t MemorySize;
float Performance;
};
}
......
......@@ -35,7 +35,7 @@ struct TemplatedTests
ValueType ExpectedValue(vtkm::Id index, ComponentType value)
{
return ValueType(index + value);
return ValueType(ComponentType(index) + value);
}
template<class IteratorType>
......
......@@ -37,7 +37,7 @@ struct TemplatedTests
ValueType ExpectedValue(vtkm::Id index, ComponentType value)
{
return ValueType(index + value);
return ValueType(ComponentType(index) + value);
}
template<class IteratorType>
......
......@@ -48,13 +48,10 @@ public:
}
VTKM_EXEC_CONT_EXPORT
explicit IncrementBy2(vtkm::Id index):
Value(0) //required before we increment
{
VTKM_ASSERT_CONT(index >= 0);
for (vtkm::Id i = 0; i < index; i++)
{ this->Value++; this->Value++; }
}
explicit IncrementBy2(T value): Value(2*value) { }
VTKM_EXEC_CONT_EXPORT
operator T() const { return this->Value; }
VTKM_EXEC_CONT_EXPORT
IncrementBy2 operator+(const IncrementBy2 &rhs) const
......@@ -88,12 +85,21 @@ public:
T Value;
};
template<typename T>
IncrementBy2<T> TestValue(vtkm::Id index, IncrementBy2<T>)
{
return IncrementBy2<T>(::TestValue(index, T()));
}
template<typename ValueType>
struct IndexSquared
{
VTKM_EXEC_CONT_EXPORT
ValueType operator()(vtkm::Id i) const
{ return ValueType( vtkm::dot(i,i) ); }
ValueType operator()(vtkm::Id index) const
{
typedef typename vtkm::VecTraits<ValueType>::ComponentType ComponentType;
return ValueType( static_cast<ComponentType>(index*index) );
}
};
template<typename ValueType>
......@@ -171,6 +177,8 @@ private:
void operator()(vtkm::Pair<KeyType,ValueType> vtkmNotUsed(pair)) const
{
typedef vtkm::Pair< KeyType, ValueType > PairType;
typedef typename vtkm::VecTraits<KeyType>::ComponentType KeyComponentType;
typedef typename vtkm::VecTraits<ValueType>::ComponentType ValueComponentType;
KeyType testKeys[ARRAY_SIZE];
......@@ -178,8 +186,8 @@ private:
for(vtkm::Id i=0; i < ARRAY_SIZE; ++i)
{
testKeys[i] = KeyType(ARRAY_SIZE - i);
testValues[i] = ValueType(i);
testKeys[i] = KeyType(static_cast<KeyComponentType>(ARRAY_SIZE - i));
testValues[i] = ValueType(static_cast<ValueComponentType>(i));
}
vtkm::cont::ArrayHandle< KeyType > keys =
vtkm::cont::make_ArrayHandle(testKeys, ARRAY_SIZE);
......@@ -200,8 +208,11 @@ private:
for(int i=0; i < ARRAY_SIZE; ++i)
{
const PairType result_v = result.GetPortalConstControl().Get(i);
const PairType correct_value( KeyType(ARRAY_SIZE - i), ValueType(i) );
VTKM_TEST_ASSERT(result_v == correct_value, "ArrayHandleZip Failed as input");
const PairType correct_value(
KeyType(static_cast<KeyComponentType>(ARRAY_SIZE - i)),
ValueType(static_cast<ValueComponentType>(i)));
VTKM_TEST_ASSERT(test_equal(result_v, correct_value),
"ArrayHandleZip Failed as input");
}
}
......@@ -214,11 +225,15 @@ private:
void operator()(vtkm::Pair<KeyType,ValueType> vtkmNotUsed(pair)) const
{
typedef vtkm::Pair< KeyType, ValueType > PairType;
typedef typename vtkm::VecTraits<KeyType>::ComponentType KeyComponentType;
typedef typename vtkm::VecTraits<ValueType>::ComponentType ValueComponentType;
PairType testKeysAndValues[ARRAY_SIZE];
for(vtkm::Id i=0; i < ARRAY_SIZE; ++i)
{
testKeysAndValues[i] = PairType(KeyType(ARRAY_SIZE - i), ValueType(i) );
testKeysAndValues[i] =
PairType(KeyType(static_cast<KeyComponentType>(ARRAY_SIZE - i)),
ValueType(static_cast<ValueComponentType>(i)) );
}
vtkm::cont::ArrayHandle< PairType > input =
vtkm::cont::make_ArrayHandle(testKeysAndValues, ARRAY_SIZE);
......@@ -239,8 +254,12 @@ private:
const KeyType result_key = result_keys.GetPortalConstControl().Get(i);
const ValueType result_value = result_values.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(result_key == KeyType(ARRAY_SIZE - i), "ArrayHandleZip Failed as input");
VTKM_TEST_ASSERT(result_value == ValueType(i), "ArrayHandleZip Failed as input");
VTKM_TEST_ASSERT(
test_equal(result_key, KeyType(static_cast<KeyComponentType>(ARRAY_SIZE - i))),
"ArrayHandleZip Failed as input for key");
VTKM_TEST_ASSERT(
test_equal(result_value, ValueType(static_cast<ValueComponentType>(i))),
"ArrayHandleZip Failed as input for value");
}
}
};
......@@ -250,12 +269,14 @@ private:
template< typename ValueType >
VTKM_CONT_EXPORT void operator()(const ValueType vtkmNotUsed(v)) const
{
typedef typename vtkm::VecTraits<ValueType>::ComponentType ComponentType;
const vtkm::Id length = ARRAY_SIZE;
//need to initialize the start value or else vectors will have
//random values to start
vtkm::Id initial_value(0);
const ValueType start = ValueType(initial_value);
ComponentType component_value(0);
const ValueType start = ValueType(component_value);
vtkm::cont::ArrayHandleCounting< ValueType > counting =
vtkm::cont::make_ArrayHandleCounting(start, length);
......@@ -268,10 +289,13 @@ private:
for(vtkm::Id i=0; i < length; ++i)
{
const ValueType result_v = result.GetPortalConstControl().Get(i);
const ValueType correct_value = ValueType(initial_value + i);
const ValueType correct_value = ValueType(component_value);
const ValueType control_value = counting.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(result_v == correct_value, "Counting Handle Failed");
VTKM_TEST_ASSERT(result_v == control_value, "Counting Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, correct_value),
"Counting Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, control_value),
"Counting Handle Control Failed");
component_value = component_value + ComponentType(1);
}
}
};
......@@ -299,8 +323,10 @@ private:
const ValueType result_v = result.GetPortalConstControl().Get(i);
const ValueType correct_value = functor( i );
const ValueType control_value = implicit.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(result_v == correct_value, "Implicit Handle Failed");
VTKM_TEST_ASSERT(result_v == control_value, "Implicit Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, correct_value),
"Implicit Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, control_value)
, "Implicit Handle Failed");
}
}
};
......@@ -352,8 +378,10 @@ private:
const ValueType result_v = result.GetPortalConstControl().Get( value_index );
const ValueType correct_value = implicit.GetPortalConstControl().Get( key_index );
const ValueType control_value = permutation.GetPortalConstControl().Get( value_index );
VTKM_TEST_ASSERT(result_v == correct_value, "Implicit Handle Failed");
VTKM_TEST_ASSERT(result_v == control_value, "Implicit Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, correct_value),
"Implicit Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, control_value),
"Implicit Handle Failed");
}
}
}
......@@ -381,10 +409,9 @@ private:
typedef typename vtkm::cont::ArrayHandle<ValueType>::PortalControl Portal;
input.Allocate(length);
Portal portal = input.GetPortalControl();
vtkm::Id initial_value(length);
for(vtkm::Id i=0; i < length; ++i)
{
portal.Set(i, ValueType(initial_value - i) );
portal.Set(i, TestValue(i, ValueType()) );
}
vtkm::cont::ArrayHandle< OutputValueType > result;
......@@ -396,8 +423,13 @@ private:
for(vtkm::Id i=0; i < length; ++i)
{
const OutputValueType result_v = result.GetPortalConstControl().Get(i);
const OutputValueType correct_value = transformed.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(result_v == correct_value, "Transform Handle Failed");
const OutputValueType correct_value = functor(TestValue(i, ValueType()));
const OutputValueType control_value =
transformed.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(test_equal(result_v, correct_value),
"Transform Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, control_value),
"Transform Handle Control Failed");
}
}
};
......@@ -407,7 +439,8 @@ private:
template< typename ValueType>
VTKM_CONT_EXPORT void operator()(const ValueType vtkmNotUsed(v)) const
{
typedef typename vtkm::VecTraits<ValueType>::ComponentType OutputValueType;
typedef typename vtkm::VecTraits<ValueType>::ComponentType ComponentType;
typedef ComponentType OutputValueType;
typedef fancy_array_detail::ValueSquared<OutputValueType> FunctorType;
vtkm::Id length = ARRAY_SIZE;
......@@ -415,8 +448,8 @@ private:
//need to initialize the start value or else vectors will have
//random values to start
vtkm::Id initial_value(0);
const ValueType start = ValueType(initial_value);
ComponentType component_value(0);
const ValueType start = ValueType(component_value);
vtkm::cont::ArrayHandleCounting< ValueType > counting =
vtkm::cont::make_ArrayHandleCounting(start,
......@@ -439,8 +472,15 @@ private:
for(vtkm::Id i=0; i < length; ++i)
{
const OutputValueType result_v = result.GetPortalConstControl().Get(i);
const OutputValueType correct_value = countingTransformed.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(result_v == correct_value, "Transform Counting Handle Failed");
const OutputValueType correct_value =
functor(ValueType(component_value));
const OutputValueType control_value =
countingTransformed.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(test_equal(result_v, correct_value),
"Transform Counting Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, control_value),
"Transform Counting Handle Control Failed");
component_value = component_value + ComponentType(1);
}
}
};
......
......@@ -47,6 +47,8 @@ public:
}
}
operator vtkm::Id() const { return vtkm::Id(this->Value.size()); }
StringInt operator+(const StringInt &rhs) const
{
return StringInt(this->Value + rhs.Value);
......@@ -69,6 +71,11 @@ private:
std::string Value;
};
} // anonymous namespace
VTKM_BASIC_TYPE_VECTOR(StringInt)
namespace {
template< typename ValueType>
struct TemplatedTests
......
......@@ -36,7 +36,7 @@ struct TemplatedTests
static ValueType ExpectedValue(vtkm::Id index, ComponentType value)
{
return ValueType(index + value);
return ValueType(static_cast<ComponentType>(index) + value);
}
class ReadOnlyArrayPortal
......
......@@ -273,18 +273,18 @@ bool test_equal(VectorType1 vector1,
VectorType2 vector2,
vtkm::Float64 tolerance = 0.0001)
{
typedef typename vtkm::VecTraits<VectorType1> Traits;
BOOST_STATIC_ASSERT(
Traits::NUM_COMPONENTS == vtkm::VecTraits<VectorType2>::NUM_COMPONENTS);
typedef typename vtkm::VecTraits<VectorType1> Traits1;
typedef typename vtkm::VecTraits<VectorType2> Traits2;
BOOST_STATIC_ASSERT(Traits1::NUM_COMPONENTS == Traits2::NUM_COMPONENTS);
for (vtkm::IdComponent component = 0;
component < Traits::NUM_COMPONENTS;
component < Traits1::NUM_COMPONENTS;
component++)
{
vtkm::Float64 value1 =
vtkm::Float64(Traits::GetComponent(vector1, component));
vtkm::Float64(Traits1::GetComponent(vector1, component));
vtkm::Float64 value2 =
vtkm::Float64(Traits::GetComponent(vector2, component));
vtkm::Float64(Traits2::GetComponent(vector2, component));
if ((fabs(value1) < 2*tolerance) && (fabs(value2) < 2*tolerance))
{
continue;
......@@ -315,6 +315,19 @@ bool test_equal(const std::string &string1, const std::string &string2)
return string1 == string2;
}
/// Special implementation of test_equal for Pairs, which are a bit different
/// than a vector of numbers of the same type.
///
template<typename T1, typename T2, typename T3, typename T4>
VTKM_CONT_EXPORT
bool test_equal(const vtkm::Pair<T1,T2> &pair1,
const vtkm::Pair<T3,T4> &pair2,
vtkm::Float64 tolerance = 0.0001)
{
return test_equal(pair1.first, pair2.first, tolerance)
&& test_equal(pair1.second, pair2.second, tolerance);
}
/// Helper function for printing out vectors during testing.
///
template<typename T, vtkm::IdComponent Size>
......@@ -362,7 +375,7 @@ vtkm::Vec<T,N> TestValue(vtkm::Id index, vtkm::Vec<T,N>) {
vtkm::Vec<T,N> value;
for (vtkm::IdComponent i = 0; i < N; i++)
{
value[i] = TestValue(index, T()) + (i + 1);
value[i] = TestValue(index, T()) + T(i + 1);
}
return value;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment