From cadf0e53ab68f0a2d6470596aa51c8ca188d9fb9 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Tue, 26 Jan 2016 16:23:00 -0700 Subject: [PATCH 1/3] Fix MSVC warnings Fix your typical batch of MSVC warnings including picky type conversions and using "unsafe" std functions on pointers for iterators. --- vtkm/Types.h | 14 ++++++++++---- vtkm/cont/DataSetBuilderRectilinear.h | 18 ++++++++---------- vtkm/io/reader/VTKPolyDataReader.h | 10 ++++++---- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/vtkm/Types.h b/vtkm/Types.h index 708becf6d..e6c0fd42e 100644 --- a/vtkm/Types.h +++ b/vtkm/Types.h @@ -653,10 +653,13 @@ struct BindLeftBinaryOp VTKM_EXEC_CONT_EXPORT BindLeftBinaryOp(const T &leftValue, BinaryOpType binaryOp = BinaryOpType()) : LeftValue(leftValue), BinaryOp(binaryOp) { } + + template VTKM_EXEC_CONT_EXPORT - ReturnT operator()(const T &rightValue) const + ReturnT operator()(const RightT &rightValue) const { - return static_cast(this->BinaryOp(this->LeftValue, rightValue)); + return static_cast(this->BinaryOp(this->LeftValue, + static_cast(rightValue))); } }; @@ -669,10 +672,13 @@ struct BindRightBinaryOp VTKM_EXEC_CONT_EXPORT BindRightBinaryOp(const T &rightValue, BinaryOpType binaryOp = BinaryOpType()) : RightValue(rightValue), BinaryOp(binaryOp) { } + + template VTKM_EXEC_CONT_EXPORT - ReturnT operator()(const T &leftValue) const + ReturnT operator()(const LeftT &leftValue) const { - return static_cast(this->BinaryOp(leftValue, this->RightValue)); + return static_cast(this->BinaryOp(static_cast(leftValue), + this->RightValue)); } }; diff --git a/vtkm/cont/DataSetBuilderRectilinear.h b/vtkm/cont/DataSetBuilderRectilinear.h index a12a75a56..040ac329b 100644 --- a/vtkm/cont/DataSetBuilderRectilinear.h +++ b/vtkm/cont/DataSetBuilderRectilinear.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace vtkm { namespace cont { @@ -37,9 +38,8 @@ class DataSetBuilderRectilinear void CopyInto(const std::vector& input, vtkm::cont::ArrayHandle& output ) { - output.Allocate( static_cast(input.size()) ); - std::copy( input.begin(), input.end(), - ArrayPortalToIteratorBegin(output.GetPortalControl()) ); + DataSetBuilderRectilinear::CopyInto( + vtkm::cont::make_ArrayHandle(input), output); } template @@ -48,10 +48,9 @@ class DataSetBuilderRectilinear void CopyInto(const vtkm::cont::ArrayHandle& input, vtkm::cont::ArrayHandle& output ) { - output.Allocate( input.GetNumberOfValues() ); - std::copy( ArrayPortalToIteratorBegin(input.GetPortalConstControl()), - ArrayPortalToIteratorEnd(input.GetPortalConstControl()), - ArrayPortalToIteratorBegin(output.GetPortalControl()) ); + typedef vtkm::cont::DeviceAdapterAlgorithm + Algorithm; + Algorithm::Copy(input, output); } template @@ -60,9 +59,8 @@ class DataSetBuilderRectilinear void CopyInto(const T* input, vtkm::Id len, vtkm::cont::ArrayHandle& output ) { - output.Allocate( len ); - std::copy( input, input+len, - output.GetPortalControl().GetIteratorBegin() ); + DataSetBuilderRectilinear::CopyInto( + vtkm::cont::make_ArrayHandle(input, len), output); } public: VTKM_CONT_EXPORT diff --git a/vtkm/io/reader/VTKPolyDataReader.h b/vtkm/io/reader/VTKPolyDataReader.h index b0d25ab6f..5cb1d183d 100644 --- a/vtkm/io/reader/VTKPolyDataReader.h +++ b/vtkm/io/reader/VTKPolyDataReader.h @@ -43,15 +43,17 @@ inline vtkm::cont::ArrayHandle ConcatinateArrayHandles( vtkm::cont::ArrayHandle out; out.Allocate(size); - typename vtkm::cont::ArrayPortalToIterators< - typename vtkm::cont::ArrayHandle::PortalControl>::IteratorType outp = - vtkm::cont::ArrayPortalToIteratorBegin(out.GetPortalControl()); + typedef typename vtkm::cont::ArrayPortalToIterators< + typename vtkm::cont::ArrayHandle::PortalControl>::IteratorType + IteratorType; + IteratorType outp = + vtkm::cont::ArrayPortalToIteratorBegin(out.GetPortalControl()); for (std::size_t i = 0; i < arrays.size(); ++i) { std::copy(vtkm::cont::ArrayPortalToIteratorBegin(arrays[i].GetPortalConstControl()), vtkm::cont::ArrayPortalToIteratorEnd(arrays[i].GetPortalConstControl()), outp); - outp += arrays[i].GetNumberOfValues(); + std::advance(outp, static_cast(arrays[i].GetNumberOfValues())); } return out; From 0731bd4a538a17ecaaa603e1ed346b317ecff093 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Tue, 26 Jan 2016 17:09:10 -0700 Subject: [PATCH 2/3] Fix compiler error about difference_type Whoops. Pointers are not classes and do not have a difference_type member. You have to get that from iterator_traits. I'm not sure why this succeeded on MSVC, but it was clearly wrong. --- vtkm/io/reader/VTKPolyDataReader.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vtkm/io/reader/VTKPolyDataReader.h b/vtkm/io/reader/VTKPolyDataReader.h index 5cb1d183d..618fc8f7d 100644 --- a/vtkm/io/reader/VTKPolyDataReader.h +++ b/vtkm/io/reader/VTKPolyDataReader.h @@ -24,6 +24,8 @@ #include +#include "iterator" + namespace vtkm { namespace io { namespace reader { @@ -53,7 +55,10 @@ inline vtkm::cont::ArrayHandle ConcatinateArrayHandles( std::copy(vtkm::cont::ArrayPortalToIteratorBegin(arrays[i].GetPortalConstControl()), vtkm::cont::ArrayPortalToIteratorEnd(arrays[i].GetPortalConstControl()), outp); - std::advance(outp, static_cast(arrays[i].GetNumberOfValues())); + typedef typename std::iterator_traits::difference_type + DifferenceType; + std::advance( + outp, static_cast(arrays[i].GetNumberOfValues())); } return out; From f4e4dc9ebe739fb2a2932f5e7eb90a909ecfcb09 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Wed, 27 Jan 2016 08:45:29 -0700 Subject: [PATCH 3/3] Use serial device for copies in DataSetBuilderRectilinear A previous change used the Copy method of DeviceAdapterAlgorithm to perform the actual copy in the CopyInto method. This works fine, except that it uses the default device adapter, and the default device adapter may need to copy the data to the device just to copy it to another array. Instead, use the serial device adapter, which is guaranteed to only perform one copy of the data. --- vtkm/cont/DataSetBuilderRectilinear.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vtkm/cont/DataSetBuilderRectilinear.h b/vtkm/cont/DataSetBuilderRectilinear.h index 040ac329b..caaa37964 100644 --- a/vtkm/cont/DataSetBuilderRectilinear.h +++ b/vtkm/cont/DataSetBuilderRectilinear.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include namespace vtkm { namespace cont { @@ -48,8 +48,8 @@ class DataSetBuilderRectilinear void CopyInto(const vtkm::cont::ArrayHandle& input, vtkm::cont::ArrayHandle& output ) { - typedef vtkm::cont::DeviceAdapterAlgorithm - Algorithm; + typedef vtkm::cont::DeviceAdapterAlgorithm< + vtkm::cont::DeviceAdapterTagSerial> Algorithm; Algorithm::Copy(input, output); }