From a3d7f9475b4c213417a00469e934e2b5c931ffc3 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Tue, 3 Jan 2023 13:56:29 -0700 Subject: [PATCH] Force functions passed as templates to be functors There are some special functions/methods that take as an argument a function-like object and then call that function with some arguments. There are some instances where a templated function was passed given the appropriate template. Even though there is a specific function, this gets passed as a function pointer and calling a function pointer on some devices is a no-no. Replace these function arguments with lambdas, which are constructed as unnamed functor objects. --- vtkm/cont/ArrayHandleCompositeVector.h | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/vtkm/cont/ArrayHandleCompositeVector.h b/vtkm/cont/ArrayHandleCompositeVector.h index 57ba4d2ba..02bbf59e7 100644 --- a/vtkm/cont/ArrayHandleCompositeVector.h +++ b/vtkm/cont/ArrayHandleCompositeVector.h @@ -66,18 +66,6 @@ struct GetValueType using ValueType = typename ArrayType::ValueType; }; -// GetFromPortals: ------------------------------------------------------------- -// Given a set of array portals as arguments, returns a Vec comprising the values -// at the provided index. -VTKM_SUPPRESS_EXEC_WARNINGS -template -VTKM_EXEC_CONT typename GetValueType::ValueType GetFromPortals( - vtkm::Id index, - const Portals&... portals) -{ - return { portals.Get(index)... }; -} - // SetToPortals: --------------------------------------------------------------- // Given a Vec-like object, and index, and a set of array portals, sets each of // the portals to the respective component of the Vec. @@ -137,14 +125,23 @@ public: VTKM_EXEC_CONT ValueType Get(vtkm::Id index) const { - return this->Portals.Apply(compvec::GetFromPortals, index); + auto getFromPortals = [index](const auto&... portals) { + return ValueType{ portals.Get(index)... }; + }; + return this->Portals.Apply(getFromPortals); } template ::type> VTKM_EXEC_CONT void Set(vtkm::Id index, const ValueType& value) const { - this->Portals.Apply(compvec::SetToPortals, index, value); + // Note that we are using a lambda function here to implicitly construct a + // functor to pass to Apply. Some device compilers will not allow passing a + // function or function pointer to Tuple::Apply. + auto setToPortal = [index, &value](const auto&... portals) { + compvec::SetToPortals(index, value, portals...); + }; + this->Portals.Apply(setToPortal); } };