Merge branch 'master' into StreamingArray

This commit is contained in:
Christopher Sewell 2016-09-15 17:54:59 -06:00
commit d92f39df12
304 changed files with 24963 additions and 17229 deletions

@ -1,142 +0,0 @@
# - Check which parts of the C++11 standard the compiler supports
#
# When found it will set the following variables
#
# CXX11_COMPILER_FLAGS - the compiler flags needed to get C++11 features
#
# HAS_CXX11_AUTO - auto keyword
# HAS_CXX11_AUTO_RET_TYPE - function declaration with deduced return types
# HAS_CXX11_CLASS_OVERRIDE - override and final keywords for classes and methods
# HAS_CXX11_CONSTEXPR - constexpr keyword
# HAS_CXX11_CSTDINT_H - cstdint header
# HAS_CXX11_DECLTYPE - decltype keyword
# HAS_CXX11_FUNC - __func__ preprocessor constant
# HAS_CXX11_INITIALIZER_LIST - initializer list
# HAS_CXX11_LAMBDA - lambdas
# HAS_CXX11_LIB_REGEX - regex library
# HAS_CXX11_LONG_LONG - long long signed & unsigned types
# HAS_CXX11_NULLPTR - nullptr
# HAS_CXX11_RVALUE_REFERENCES - rvalue references
# HAS_CXX11_SIZEOF_MEMBER - sizeof() non-static members
# HAS_CXX11_STATIC_ASSERT - static_assert()
# HAS_CXX11_VARIADIC_TEMPLATES - variadic templates
#=============================================================================
# Copyright 2011,2012 Rolf Eike Beer <eike@sf-mail.de>
# Copyright 2012 Andreas Weis
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
#
# Each feature may have up to 3 checks, every one of them in it's own file
# FEATURE.cpp - example that must build and return 0 when run
# FEATURE_fail.cpp - example that must build, but may not return 0 when run
# FEATURE_fail_compile.cpp - example that must fail compilation
#
# The first one is mandatory, the latter 2 are optional and do not depend on
# each other (i.e. only one may be present).
#
if (NOT CMAKE_CXX_COMPILER_LOADED)
message(FATAL_ERROR "CheckCXX11Features modules only works if language CXX is enabled")
endif ()
cmake_minimum_required(VERSION 2.8.3)
#
### Check for needed compiler flags
#
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++11" _HAS_CXX11_FLAG)
if (NOT _HAS_CXX11_FLAG)
check_cxx_compiler_flag("-std=c++0x" _HAS_CXX0X_FLAG)
endif ()
if (_HAS_CXX11_FLAG)
set(CXX11_COMPILER_FLAGS "-std=c++11")
elseif (_HAS_CXX0X_FLAG)
set(CXX11_COMPILER_FLAGS "-std=c++0x")
endif ()
function(cxx11_check_feature FEATURE_NAME RESULT_VAR)
if (NOT DEFINED ${RESULT_VAR})
set(_bindir "${CMAKE_CURRENT_BINARY_DIR}/cxx11_${FEATURE_NAME}")
set(_SRCFILE_BASE ${CMAKE_CURRENT_LIST_DIR}/CheckCXX11Features/cxx11-test-${FEATURE_NAME})
set(_LOG_NAME "\"${FEATURE_NAME}\"")
message(STATUS "Checking C++11 support for ${_LOG_NAME}")
set(_SRCFILE "${_SRCFILE_BASE}.cpp")
set(_SRCFILE_FAIL "${_SRCFILE_BASE}_fail.cpp")
set(_SRCFILE_FAIL_COMPILE "${_SRCFILE_BASE}_fail_compile.cpp")
if (CROSS_COMPILING)
try_compile(${RESULT_VAR} "${_bindir}" "${_SRCFILE}"
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
try_compile(${RESULT_VAR} "${_bindir}_fail" "${_SRCFILE_FAIL}"
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
else (CROSS_COMPILING)
try_run(_RUN_RESULT_VAR _COMPILE_RESULT_VAR
"${_bindir}" "${_SRCFILE}"
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
if (_COMPILE_RESULT_VAR AND NOT _RUN_RESULT_VAR)
set(${RESULT_VAR} TRUE)
else (_COMPILE_RESULT_VAR AND NOT _RUN_RESULT_VAR)
set(${RESULT_VAR} FALSE)
endif (_COMPILE_RESULT_VAR AND NOT _RUN_RESULT_VAR)
if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
try_run(_RUN_RESULT_VAR _COMPILE_RESULT_VAR
"${_bindir}_fail" "${_SRCFILE_FAIL}"
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
if (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR)
set(${RESULT_VAR} TRUE)
else (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR)
set(${RESULT_VAR} FALSE)
endif (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR)
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
endif (CROSS_COMPILING)
if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE})
try_compile(_TMP_RESULT "${_bindir}_fail_compile" "${_SRCFILE_FAIL_COMPILE}"
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
if (_TMP_RESULT)
set(${RESULT_VAR} FALSE)
else (_TMP_RESULT)
set(${RESULT_VAR} TRUE)
endif (_TMP_RESULT)
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE})
if (${RESULT_VAR})
message(STATUS "Checking C++11 support for ${_LOG_NAME}: works")
else (${RESULT_VAR})
message(STATUS "Checking C++11 support for ${_LOG_NAME}: not supported")
endif (${RESULT_VAR})
set(${RESULT_VAR} ${${RESULT_VAR}} CACHE INTERNAL "C++11 support for ${_LOG_NAME}")
endif (NOT DEFINED ${RESULT_VAR})
endfunction(cxx11_check_feature)
cxx11_check_feature("__func__" HAS_CXX11_FUNC)
cxx11_check_feature("auto" HAS_CXX11_AUTO)
cxx11_check_feature("auto_ret_type" HAS_CXX11_AUTO_RET_TYPE)
cxx11_check_feature("class_override_final" HAS_CXX11_CLASS_OVERRIDE)
cxx11_check_feature("constexpr" HAS_CXX11_CONSTEXPR)
cxx11_check_feature("cstdint" HAS_CXX11_CSTDINT_H)
cxx11_check_feature("decltype" HAS_CXX11_DECLTYPE)
cxx11_check_feature("initializer_list" HAS_CXX11_INITIALIZER_LIST)
cxx11_check_feature("lambda" HAS_CXX11_LAMBDA)
cxx11_check_feature("long_long" HAS_CXX11_LONG_LONG)
cxx11_check_feature("nullptr" HAS_CXX11_NULLPTR)
cxx11_check_feature("regex" HAS_CXX11_LIB_REGEX)
cxx11_check_feature("rvalue-references" HAS_CXX11_RVALUE_REFERENCES)
cxx11_check_feature("sizeof_member" HAS_CXX11_SIZEOF_MEMBER)
cxx11_check_feature("static_assert" HAS_CXX11_STATIC_ASSERT)
cxx11_check_feature("variadic_templates" HAS_CXX11_VARIADIC_TEMPLATES)

@ -1,8 +0,0 @@
int main(void)
{
if (!__func__)
return 1;
if (!(*__func__))
return 1;
return 0;
}

@ -1,12 +0,0 @@
int main()
{
auto i = 5;
auto f = 3.14159f;
auto d = 3.14159;
bool ret = (
(sizeof(f) < sizeof(d)) &&
(sizeof(i) == sizeof(int))
);
return ret ? 0 : 1;
}

@ -1,7 +0,0 @@
int main(void)
{
// must fail because there is no initializer
auto i;
return 0;
}

@ -1,8 +0,0 @@
auto foo(int i) -> int {
return i - 1;
}
int main()
{
return foo(1);
}

@ -1,21 +0,0 @@
class base {
public:
virtual int foo(int a)
{ return 4 + a; }
int bar(int a) final
{ return a - 2; }
};
class sub final : public base {
public:
virtual int foo(int a) override
{ return 8 + 2 * a; };
};
int main(void)
{
base b;
sub s;
return (b.foo(2) * 2 == s.foo(2)) ? 0 : 1;
}

@ -1,25 +0,0 @@
class base {
public:
virtual int foo(int a)
{ return 4 + a; }
virtual int bar(int a) final
{ return a - 2; }
};
class sub final : public base {
public:
virtual int foo(int a) override
{ return 8 + 2 * a; };
virtual int bar(int a)
{ return a; }
};
class impossible : public sub { };
int main(void)
{
base b;
sub s;
return 1;
}

@ -1,19 +0,0 @@
constexpr int square(int x)
{
return x*x;
}
constexpr int the_answer()
{
return 42;
}
int main()
{
int test_arr[square(3)];
bool ret = (
(square(the_answer()) == 1764) &&
(sizeof(test_arr)/sizeof(test_arr[0]) == 9)
);
return ret ? 0 : 1;
}

@ -1,11 +0,0 @@
#include <cstdint>
int main()
{
bool test =
(sizeof(int8_t) == 1) &&
(sizeof(int16_t) == 2) &&
(sizeof(int32_t) == 4) &&
(sizeof(int64_t) == 8);
return test ? 0 : 1;
}

@ -1,10 +0,0 @@
bool check_size(int i)
{
return sizeof(int) == sizeof(decltype(i));
}
int main()
{
bool ret = check_size(42);
return ret ? 0 : 1;
}

@ -1,27 +0,0 @@
#include <vector>
class seq {
public:
seq(std::initializer_list<int> list);
int length() const;
private:
std::vector<int> m_v;
};
seq::seq(std::initializer_list<int> list)
: m_v(list)
{
}
int seq::length() const
{
return m_v.size();
}
int main(void)
{
seq a = {18, 20, 2, 0, 4, 7};
return (a.length() == 6) ? 0 : 1;
}

@ -1,5 +0,0 @@
int main()
{
int ret = 0;
return ([&ret]() -> int { return ret; })();
}

@ -1,7 +0,0 @@
int main(void)
{
long long l;
unsigned long long ul;
return ((sizeof(l) >= 8) && (sizeof(ul) >= 8)) ? 0 : 1;
}

@ -1,6 +0,0 @@
int main(void)
{
void *v = nullptr;
return v ? 1 : 0;
}

@ -1,6 +0,0 @@
int main(void)
{
int i = nullptr;
return 1;
}

@ -1,26 +0,0 @@
#include <algorithm>
#include <regex>
int parse_line(std::string const& line)
{
std::string tmp;
if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+//(-)?(\\d)+(\\s)+"))) {
tmp = std::regex_replace(line, std::regex("(-)?(\\d)+//(-)?(\\d)+"), std::string("V"));
} else if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+/(-)?(\\d)+(\\s)+"))) {
tmp = std::regex_replace(line, std::regex("(-)?(\\d)+/(-)?(\\d)+"), std::string("V"));
} else if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+/(-)?(\\d)+/(-)?(\\d)+(\\s)+"))) {
tmp = std::regex_replace(line, std::regex("(-)?(\\d)+/(-)?(\\d)+/(-)?(\\d)+"), std::string("V"));
} else {
tmp = std::regex_replace(line, std::regex("(-)?(\\d)+"), std::string("V"));
}
return static_cast<int>(std::count(tmp.begin(), tmp.end(), 'V'));
}
int main()
{
bool test = (parse_line("f 7/7/7 -3/3/-3 2/-2/2") == 3) &&
(parse_line("f 7//7 3//-3 -2//2") == 3) &&
(parse_line("f 7/7 3/-3 -2/2") == 3) &&
(parse_line("f 7 3 -2") == 3);
return test ? 0 : 1;
}

@ -1,57 +0,0 @@
#include <cassert>
class rvmove {
public:
void *ptr;
char *array;
rvmove()
: ptr(0),
array(new char[10])
{
ptr = this;
}
rvmove(rvmove &&other)
: ptr(other.ptr),
array(other.array)
{
other.array = 0;
other.ptr = 0;
}
~rvmove()
{
assert(((ptr != 0) && (array != 0)) || ((ptr == 0) && (array == 0)));
delete[] array;
}
rvmove &operator=(rvmove &&other)
{
delete[] array;
ptr = other.ptr;
array = other.array;
other.array = 0;
other.ptr = 0;
return *this;
}
static rvmove create()
{
return rvmove();
}
private:
rvmove(const rvmove &);
rvmove &operator=(const rvmove &);
};
int main()
{
rvmove mine;
if (mine.ptr != &mine)
return 1;
mine = rvmove::create();
if (mine.ptr == &mine)
return 1;
return 0;
}

@ -1,14 +0,0 @@
struct foo {
char bar;
int baz;
};
int main(void)
{
bool ret = (
(sizeof(foo::bar) == 1) &&
(sizeof(foo::baz) >= sizeof(foo::bar)) &&
(sizeof(foo) >= sizeof(foo::bar) + sizeof(foo::baz))
);
return ret ? 0 : 1;
}

@ -1,9 +0,0 @@
struct foo {
int baz;
double bar;
};
int main(void)
{
return (sizeof(foo::bar) == 4) ? 0 : 1;
}

@ -1,5 +0,0 @@
int main(void)
{
static_assert(0 < 1, "your ordering of integers is screwed");
return 0;
}

@ -1,5 +0,0 @@
int main(void)
{
static_assert(1 < 0, "your ordering of integers is screwed");
return 0;
}

@ -1,23 +0,0 @@
int Accumulate()
{
return 0;
}
template<typename T, typename... Ts>
int Accumulate(T v, Ts... vs)
{
return v + Accumulate(vs...);
}
template<int... Is>
int CountElements()
{
return sizeof...(Is);
}
int main()
{
int acc = Accumulate(1, 2, 3, 4, -5);
int count = CountElements<1,2,3,4,5>();
return ((acc == 5) && (count == 5)) ? 0 : 1;
}

102
CMake/FindGLFW.cmake Normal file

@ -0,0 +1,102 @@
##=============================================================================
##
## Copyright (c) Kitware, Inc.
## All rights reserved.
## See LICENSE.txt for details.
##
## This software is distributed WITHOUT ANY WARRANTY; without even
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
## PURPOSE. See the above copyright notice for more information.
##
## Copyright 2016 Sandia Corporation.
## Copyright 2016 UT-Battelle, LLC.
## Copyright 2016 Los Alamos National Security.
##
## Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
## the U.S. Government retains certain rights in this software.
## Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
## Laboratory (LANL), the U.S. Government retains certain rights in
## this software.
##
##=============================================================================
# Try to find EGL library and include dir.
# Once done this will define
#
# GLFW_FOUND
# GLFW_INCLUDE_DIR
# GLFW_LIBRARY
#
include(FindPackageHandleStandardArgs)
if (WIN32)
find_path( GLFW_INCLUDE_DIR
NAMES
GLFW/glfw3.h
PATHS
${PROJECT_SOURCE_DIR}/shared_external/glfw/include
${PROJECT_SOURCE_DIR}/../shared_external/glfw/include
${GLFW_LOCATION}/include
$ENV{GLFW_LOCATION}/include
$ENV{PROGRAMFILES}/GLFW/include
${GLFW_LOCATION}
$ENV{GLFW_LOCATION}
DOC "The directory where GLFW/glfw3.h resides" )
if(ARCH STREQUAL "x86")
find_library( GLFW_LIBRARY
NAMES
glfw3
PATHS
${GLFW_LOCATION}/lib
$ENV{GLFW_LOCATION}/lib
$ENV{PROGRAMFILES}/GLFW/lib
DOC "The GLFW library")
else()
find_library( GLFW_LIBRARY
NAMES
glfw3
PATHS
${GLFW_LOCATION}/lib
$ENV{GLFW_LOCATION}/lib
$ENV{PROGRAMFILES}/GLFW/lib
DOC "The GLFW library")
endif()
endif ()
if (${CMAKE_HOST_UNIX})
find_path( GLFW_INCLUDE_DIR
NAMES
GLFW/glfw3.h
PATHS
${GLFW_LOCATION}/include
$ENV{GLFW_LOCATION}/include
/usr/include
/usr/local/include
/sw/include
/opt/local/include
NO_DEFAULT_PATH
DOC "The directory where GLFW/glfw3.h resides"
)
find_library( GLFW_LIBRARY
NAMES
glfw3 glfw
PATHS
${GLFW_LOCATION}/lib
$ENV{GLFW_LOCATION}/lib
/usr/lib64
/usr/lib
/usr/local/lib64
/usr/local/lib
/sw/lib
/opt/local/lib
/usr/lib/x86_64-linux-gnu
NO_DEFAULT_PATH
DOC "The GLFW library")
endif ()
find_package_handle_standard_args(GLFW DEFAULT_MSG
GLFW_INCLUDE_DIR
GLFW_LIBRARY
)
mark_as_advanced( GLFW_INCLUDE_DIR GLFW_LIBRARY )

@ -72,6 +72,12 @@ foreach (index RANGE ${begin_index} ${end_index})
list(GET license_lines ${index} tpl_file)
set(EXCEPTIONS ${EXCEPTIONS} ${tpl_file})
endforeach(index)
# if the build directory is in the source directory, exclude generated build
# files
find_path(BUILD_DIR CMakeCache.txt .)
get_filename_component(abs_build_dir ${BUILD_DIR} ABSOLUTE)
get_filename_component(build_dir_name ${abs_build_dir} NAME)
set(EXCEPTIONS ${EXCEPTIONS} ${build_dir_name}/*)
message("${EXCEPTIONS}")
# Gets the current year (if possible).

@ -43,11 +43,13 @@ if (NOT VTKm_SOURCE_DIR)
message(SEND_ERROR "VTKm_SOURCE_DIR not defined.")
endif (NOT VTKm_SOURCE_DIR)
function(check_directory directory)
function(check_directory directory parent_CMakeLists_contents)
message("Checking directory ${directory}...")
get_filename_component(directory_name "${directory}" NAME)
if(EXISTS "${directory}/CMakeLists.txt")
file(READ "${directory}/CMakeLists.txt" CMakeListsContents)
file(READ "${directory}/CMakeLists.txt" CMakeLists_contents)
endif()
foreach (glob_expression ${FILES_TO_CHECK})
@ -70,14 +72,23 @@ function(check_directory directory)
# Remove .in suffix. These are generally configured files that generate
# new files that are actually used in the build.
string(REGEX REPLACE ".in$" "" file_check "${file}")
string(FIND "${CMakeListsContents}" "${file_check}" position)
string(FIND "${CMakeLists_contents}" "${file_check}" position)
if(${position} LESS 0)
message(SEND_ERROR
"****************************************************************
# Check the CMakeLists.txt of the parent directory. Some sources of
# internal directories are packaged into libraries in the parent
# directory.
string(FIND "${parent_CMakeLists_contents}"
"${directory_name}/${file_check}"
position
)
if(${position} LESS 0)
message(SEND_ERROR
"****************************************************************
${file_check} is not found in ${directory}/CMakeLists.txt
This indicates that the file is not part of the build system. Thus it might be missing build targets. All such files should be explicitly handled by CMake.")
endif()
endif()
endif() # Not in parent's CMakeLists.txt
endif() # Not in CMakeLists.txt
endif() # Not skipped
endforeach (file)
endforeach(glob_expression)
@ -86,10 +97,10 @@ This indicates that the file is not part of the build system. Thus it might be m
"${directory}/*")
foreach(file ${file_list})
if(IS_DIRECTORY "${file}")
check_directory("${file}")
check_directory("${file}" "${CMakeLists_contents}")
endif()
endforeach(file)
endfunction(check_directory)
check_directory("${VTKm_SOURCE_DIR}/vtkm")
check_directory("${VTKm_SOURCE_DIR}/examples")
check_directory("${VTKm_SOURCE_DIR}/vtkm" "")
check_directory("${VTKm_SOURCE_DIR}/examples" "")

@ -34,6 +34,10 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
set(CMAKE_COMPILER_IS_ICCXX 1)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_COMPILER_IS_MSVCXX 1)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
include(CheckCXXCompilerFlag)
@ -47,9 +51,6 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
# Additional warnings for GCC/Clang
set(CMAKE_CXX_FLAGS_WARN_EXTRA "-Wno-long-long -Wcast-align -Wconversion -Wchar-subscripts -Wextra -Wpointer-arith -Wformat -Wformat-security -Wshadow -Wunused-parameter -fno-common")
if (VTKm_FORCE_ANSI)
set(CMAKE_CXX_FLAGS_WARN_EXTRA "-ansi ${CMAKE_CXX_FLAGS_WARN_EXTRA}")
endif()
# Additional warnings just for Clang 3.5+, and AppleClang 7+ we specify
# for all build types, since these failures to vectorize are not limited
@ -90,5 +91,7 @@ elseif(CMAKE_COMPILER_IS_ICCXX)
# to loops, the #pragma warning(disable seems to not work so we add a
# a compile define.
add_definitions("-wd13379")
elseif (CMAKE_COMPILER_IS_MSVCXX)
#enable large object support so we can have 2^32 addressable sections
list(APPEND VTKm_COMPILE_OPTIONS "/bigobj")
endif()

@ -148,6 +148,9 @@ set_vectorization_flags_properties(vec_levels)
#
set(VTKm_Vectorization "none" CACHE STRING "Level of compiler vectorization support")
set_property(CACHE VTKm_Vectorization PROPERTY STRINGS ${vec_levels})
if (NOT ${VTKm_Vectorization} STREQUAL "none")
set(VTKM_VECTORIZATION_ENABLED "ON")
endif()
#
# Now that we have set up the options, lets setup the compile flags that

@ -60,11 +60,21 @@ else()
set_and_check(VTKm_CMAKE_MODULE_PATH "@VTKm_SOURCE_DIR@/CMake")
endif()
set(VTKm_BUILD_SHARED_LIBS "@BUILD_SHARED_LIBS@")
set(VTKm_ENABLE_CUDA "@VTKm_ENABLE_CUDA@")
set(VTKm_ENABLE_TBB "@VTKm_ENABLE_TBB@")
set(VTKm_ENABLE_OPENGL_INTEROP "@VTKm_ENABLE_OPENGL_INTEROP@")
set(VTKm_BUILD_RENDERING "@VTKm_BUILD_RENDERING@")
# Load the library exports, but only if not compiling VTK-m itself
set_and_check(VTKm_CONFIG_DIR "@PACKAGE_VTKm_INSTALL_CONFIG_DIR@")
if(NOT "${CMAKE_BINARY_DIR}" STREQUAL "@VTKm_BINARY_DIR@")
include(${VTKm_CONFIG_DIR}/VTKmTargets.cmake)
endif()
# Clear out the libraries. We will add more when loading components.
set(VTKm_LIBRARIES)
# The VTKm variables used to configure components and packages silently.
set(VTKm_CONFIGURE_QUIET "${VTKm_FIND_QUIETLY}")
set(VTKm_FIND_PACKAGE_QUIETLY "")
@ -84,6 +94,12 @@ include(VTKmMacros)
# that uses VTK-m.
set(VTKm_COMPILE_OPTIONS "@VTKm_COMPILE_OPTIONS@")
# All projects using VTK-m should include the "Base" configuration (otherwise
# nothing may compile). Make sure the Base configuration is added to
# VTKm_FIND_COMPONENTS and the component is required.
set(VTKm_FIND_COMPONENTS "Base" ${VTKm_FIND_COMPONENTS})
set(VTKm_FIND_REQUIRED_Base TRUE)
# Load the selected components
@VTKm_LOAD_COMPONENTS_COMMANDS@

@ -39,11 +39,30 @@ set(VTKm_AVAILABLE_COMPONENTS
OpenGL
OSMesa
EGL
GLFW
Interop
Rendering
TBB
CUDA
)
#-----------------------------------------------------------------------------
# Support function for giving status messages on component configurations
#-----------------------------------------------------------------------------
set(VTKm_CONFIGURE_COMPONENT_MESSAGES "" CACHE INTERNAL "" FORCE)
function(vtkm_configure_component_message message_text)
if(NOT VTKm_CONFIGURE_QUIET)
list(FIND VTKm_CONFIGURE_COMPONENT_MESSAGES "${message_text}" in_list)
if(in_list EQUAL -1)
message(STATUS "${message_text}")
set(VTKm_CONFIGURE_COMPONENT_MESSAGES
${VTKm_CONFIGURE_COMPONENT_MESSAGES}
${message_text}
CACHE INTERNAL "" FORCE)
endif()
endif()
endfunction(vtkm_configure_component_message)
#-----------------------------------------------------------------------------
# Support function for making vtkm_configure_component<name> functions.
#-----------------------------------------------------------------------------
@ -60,9 +79,8 @@ macro(vtkm_finish_configure_component component)
foreach(var ${VTKm_FCC_DEPENDENT_VARIABLES})
if(NOT ${var})
set(VTKm_${component}_FOUND)
if(NOT VTKm_CONFIGURE_QUIET)
message(STATUS "Failed to configure VTK-m component ${component}: !${var}")
endif()
vtkm_configure_component_message(
"Failed to configure VTK-m component ${component}: !${var}")
break()
endif()
endforeach(var)
@ -84,6 +102,11 @@ macro(vtkm_configure_component_Base)
find_package(BoostHeaders ${VTKm_FIND_PACKAGE_QUIETLY} ${VTKm_REQUIRED_BOOST_VERSION})
endif()
# Set up the compiler flag optimizations
if (NOT VTKm_Vectorization_flags_added)
include(VTKmCompilerOptimizations)
endif()
vtkm_finish_configure_component(Base
DEPENDENT_VARIABLES Boost_FOUND
ADD_INCLUDES ${Boost_INCLUDE_DIRS}
@ -99,7 +122,13 @@ macro(vtkm_configure_component_Serial)
endmacro(vtkm_configure_component_Serial)
macro(vtkm_configure_component_OpenGL)
vtkm_configure_component_Base()
# OpenGL configuration "depends" on OSMesa because if OSMesa is used, then it
# (sometimes) requires its own version of OpenGL. The find_package for OpenGL
# is smart enough to configure this correctly if OSMesa is found first. Thus,
# we ensure that OSMesa is configured before OpenGL (assuming you are using
# the VTK-m configuration). However, the OpenGL configuration can still
# succeed even if the OSMesa configuration fails.
vtkm_configure_component_OSMesa()
find_package(OpenGL ${VTKm_FIND_PACKAGE_QUIETLY})
@ -111,18 +140,18 @@ macro(vtkm_configure_component_OpenGL)
endmacro(vtkm_configure_component_OpenGL)
macro(vtkm_configure_component_OSMesa)
vtkm_configure_component_OpenGL()
vtkm_configure_component_Base()
if (UNIX AND NOT APPLE)
find_package(MESA ${VTKm_FIND_PACKAGE_QUIETLY})
vtkm_finish_configure_component(OSMesa
DEPENDENT_VARIABLES VTKm_OpenGL_FOUND OSMESA_FOUND
DEPENDENT_VARIABLES OSMESA_FOUND
ADD_INCLUDES ${OSMESA_INCLUDE_DIR}
ADD_LIBRARIES ${OSMESA_LIBRARY}
)
elseif(NOT VTKm_CONFIGURE_QUIET)
message(STATUS "OSMesa not supported on this platform.")
else()
vtkm_configure_component_message("OSMesa not supported on this platform.")
endif()
endmacro(vtkm_configure_component_OSMesa)
@ -138,6 +167,18 @@ macro(vtkm_configure_component_EGL)
)
endmacro(vtkm_configure_component_EGL)
macro(vtkm_configure_component_GLFW)
vtkm_configure_component_OpenGL()
find_package(GLFW ${VTKm_FIND_PACKAGE_QUIETLY})
vtkm_finish_configure_component(GLFW
DEPENDENT_VARIABLES VTKm_OpenGL_FOUND GLFW_FOUND
ADD_INCLUDES ${GLFW_INCLUDE_DIR}
ADD_LIBRARIES ${GLFW_LIBRARY}
)
endmacro(vtkm_configure_component_GLFW)
macro(vtkm_configure_component_Interop)
vtkm_configure_component_OpenGL()
@ -150,7 +191,7 @@ macro(vtkm_configure_component_Interop)
)
#on unix/linux Glew uses pthreads, so we need to find that, and link to it
#explicitly or else in release mode we get sigsegv on launch
if (VTKm_Interop_FOUND AND UNIX)
if (VTKm_ENABLE_OPENGL_INTEROP AND UNIX)
find_package(Threads ${VTKm_FIND_PACKAGE_QUIETLY})
set(vtkm_interop_dependent_vars ${vtkm_interop_dependent_vars} CMAKE_USE_PTHREADS_INIT)
endif()
@ -158,10 +199,23 @@ macro(vtkm_configure_component_Interop)
vtkm_finish_configure_component(Interop
DEPENDENT_VARIABLES ${vtkm_interop_dependent_vars}
ADD_INCLUDES ${GLEW_INCLUDE_DIRS}
ADD_LIBRARIES ${GLEW_LIBRARIES}
ADD_LIBRARIES ${GLEW_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
)
endmacro(vtkm_configure_component_Interop)
macro(vtkm_configure_component_Rendering)
if(VTKm_BUILD_RENDERING)
vtkm_configure_component_OpenGL()
vtkm_configure_component_EGL()
vtkm_configure_component_OSMesa()
endif()
vtkm_finish_configure_component(Rendering
DEPENDENT_VARIABLES VTKm_BUILD_RENDERING VTKm_Base_FOUND
ADD_LIBRARIES vtkm_rendering
)
endmacro(vtkm_configure_component_Rendering)
macro(vtkm_configure_component_TBB)
if(VTKm_ENABLE_TBB)
vtkm_configure_component_Base()
@ -205,7 +259,12 @@ macro(vtkm_configure_component_CUDA)
if(VTKm_CUDA_FOUND)
#---------------------------------------------------------------------------
# Setup build flags for CUDA
# Setup build flags for CUDA to have C++11 support
#---------------------------------------------------------------------------
if(NOT MSVC)
list(APPEND CUDA_NVCC_FLAGS --std c++11)
endif()
#---------------------------------------------------------------------------
# Populates CUDA_NVCC_FLAGS with the best set of flags to compile for a
# given GPU architecture. The majority of developers should leave the
@ -242,27 +301,34 @@ macro(vtkm_configure_component_CUDA)
#detect what the propery is set too
if(VTKm_CUDA_Architecture STREQUAL "native")
#run execute_process to do auto_detection
set(command ${CUDA_NVCC_EXECUTABLE})
set(args "-ccbin" "${CMAKE_CXX_COMPILER}" "--run" "${VTKm_CMAKE_MODULE_PATH}/VTKmDetectCUDAVersion.cxx")
execute_process(
COMMAND ${command} ${args}
RESULT_VARIABLE ran_properly
OUTPUT_VARIABLE run_output
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
if(NOT VTKM_CUDA_NATIVE_EXE_PROCESS_RAN)
if(ran_properly EQUAL 0)
#find the position of the "--generate-code" output. With some compilers such as
#msvc we get compile output plus run output. So we need to strip out just the
#run output
string(FIND "${run_output}" "--generate-code" position)
string(SUBSTRING "${run_output}" ${position} -1 run_output)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ${run_output}")
else()
set(VTKm_CUDA_Architecture "fermi")
if(NOT VTKm_CONFIGURE_QUIET)
message(STATUS "Unable to run \"${CUDA_NVCC_EXECUTABLE}\" to autodetect GPU architecture."
"Falling back to fermi, please manually specify if you want something else.")
#run execute_process to do auto_detection
if(CMAKE_GENERATOR MATCHES "Visual Studio")
set(args "-ccbin" "${CMAKE_CXX_COMPILER}" "--run" "${VTKm_CMAKE_MODULE_PATH}/VTKmDetectCUDAVersion.cxx")
else()
set(args "-ccbin" "${CUDA_HOST_COMPILER}" "--run" "${VTKm_CMAKE_MODULE_PATH}/VTKmDetectCUDAVersion.cxx")
endif()
execute_process(
COMMAND ${CUDA_NVCC_EXECUTABLE} ${args}
RESULT_VARIABLE ran_properly
OUTPUT_VARIABLE run_output
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
if(ran_properly EQUAL 0)
#find the position of the "--generate-code" output. With some compilers such as
#msvc we get compile output plus run output. So we need to strip out just the
#run output
string(FIND "${run_output}" "--generate-code" position)
string(SUBSTRING "${run_output}" ${position} -1 run_output)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ${run_output}")
set(VTKM_CUDA_NATIVE_EXE_PROCESS_RAN TRUE CACHE INTERNAL
"We have correctly detected the device type(s) for cuda[native]")
else()
set(VTKm_CUDA_Architecture "fermi")
vtkm_configure_component_message(
"Unable to run \"${CUDA_NVCC_EXECUTABLE}\" to autodetect GPU architecture.
Falling back to fermi, please manually specify if you want something else.")
endif()
endif()
endif()

@ -19,6 +19,7 @@
##============================================================================
include(CMakeParseArguments)
include(GenerateExportHeader)
# Utility to build a kit name from the current directory.
function(vtkm_get_kit_name kitvar)
@ -73,17 +74,9 @@ endfunction(vtkm_setup_nvcc_flags)
function(vtkm_setup_msvc_properties target )
#disable MSVC CRT and SCL warnings as they recommend using non standard
#c++ extensions
set_property(TARGET ${target}
APPEND PROPERTY COMPILE_DEFINITIONS
"_SCL_SECURE_NO_WARNINGS"
"_CRT_SECURE_NO_WARNINGS"
)
target_compile_definitions(${target} PRIVATE "_SCL_SECURE_NO_WARNINGS"
"_CRT_SECURE_NO_WARNINGS")
#enable large object support so we can have 2^32 addressable sections
set_property(TARGET ${target}
APPEND PROPERTY COMPILE_FLAGS
"/bigobj"
)
endfunction(vtkm_setup_msvc_properties)
# Builds a source file and an executable that does nothing other than
@ -120,21 +113,22 @@ function(vtkm_add_header_build_test name dir_prefix use_cuda)
list(APPEND CUDA_NVCC_INCLUDE_ARGS_USER -isystem ${dir})
endforeach()
cuda_add_library(TestBuild_${name} ${cxxfiles} ${hfiles})
cuda_add_library(TestBuild_${name} STATIC ${cxxfiles} ${hfiles})
elseif (${cxxfiles_len} GREATER 0)
add_library(TestBuild_${name} ${cxxfiles} ${hfiles})
if(VTKm_EXTRA_COMPILER_WARNINGS)
set_property(TARGET ${test_prog}
APPEND PROPERTY COMPILE_FLAGS
${CMAKE_CXX_FLAGS_WARN_EXTRA}
)
endif(VTKm_EXTRA_COMPILER_WARNINGS)
add_library(TestBuild_${name} STATIC ${cxxfiles} ${hfiles})
target_include_directories(TestBuild_${name} PRIVATE ${VTKm_INCLUDE_DIRS})
endif ()
target_link_libraries(TestBuild_${name} ${VTKm_LIBRARIES})
set_source_files_properties(${hfiles}
PROPERTIES HEADER_FILE_ONLY TRUE
)
# Send the libraries created for test builds to their own directory so as to
# not polute the directory with useful libraries.
set_target_properties(TestBuild_${name} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}/testbuilds
LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}/testbuilds
RUNTIME_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}/testbuilds
)
endfunction(vtkm_add_header_build_test)
function(vtkm_install_headers dir_prefix)
@ -241,11 +235,12 @@ endfunction(vtkm_pyexpander_generated_file)
# vtkm_unit_tests(
# SOURCES <source_list>
# LIBRARIES <dependent_library_list>
# TEST_ARGS <argument_list>
# )
function(vtkm_unit_tests)
set(options CUDA)
set(oneValueArgs)
set(multiValueArgs SOURCES LIBRARIES)
set(multiValueArgs SOURCES LIBRARIES TEST_ARGS)
cmake_parse_arguments(VTKm_UT
"${options}" "${oneValueArgs}" "${multiValueArgs}"
${ARGN}
@ -286,8 +281,7 @@ function(vtkm_unit_tests)
#do it as a property value so we don't pollute the include_directories
#for any other targets
set_property(TARGET ${test_prog} APPEND PROPERTY
INCLUDE_DIRECTORIES ${VTKm_INCLUDE_DIRS} )
target_include_directories(${test_prog} PRIVATE ${VTKm_INCLUDE_DIRS})
target_link_libraries(${test_prog} ${VTKm_LIBRARIES})
@ -297,17 +291,10 @@ function(vtkm_unit_tests)
vtkm_setup_msvc_properties(${test_prog})
endif()
if(VTKm_EXTRA_COMPILER_WARNINGS)
set_property(TARGET ${test_prog}
APPEND PROPERTY COMPILE_FLAGS
${CMAKE_CXX_FLAGS_WARN_EXTRA}
)
endif(VTKm_EXTRA_COMPILER_WARNINGS)
foreach (test ${VTKm_UT_SOURCES})
get_filename_component(tname ${test} NAME_WE)
add_test(NAME ${tname}
COMMAND ${test_prog} ${tname}
COMMAND ${test_prog} ${tname} ${VTKm_UT_TEST_ARGS}
)
set_tests_properties("${tname}" PROPERTIES TIMEOUT ${timeout})
endforeach (test)
@ -422,9 +409,7 @@ function(vtkm_worklet_unit_tests device_adapter)
else()
add_executable(${test_prog} ${unit_test_drivers} ${unit_test_srcs})
endif()
set_property(TARGET ${test_prog} APPEND PROPERTY
INCLUDE_DIRECTORIES ${VTKm_INCLUDE_DIRS}
)
target_include_directories(${test_prog} PRIVATE ${VTKm_INCLUDE_DIRS})
target_link_libraries(${test_prog} ${VTKm_LIBRARIES})
#add the specific compile options for this executable
@ -446,18 +431,8 @@ function(vtkm_worklet_unit_tests device_adapter)
vtkm_setup_msvc_properties(${test_prog})
endif()
#increase warning level if needed, we are going to skip cuda here
#to remove all the false positive unused function warnings that cuda
#generates
if(VTKm_EXTRA_COMPILER_WARNINGS)
set_property(TARGET ${test_prog}
APPEND PROPERTY COMPILE_FLAGS ${CMAKE_CXX_FLAGS_WARN_EXTRA} )
endif()
#set the device adapter on the executable
set_property(TARGET ${test_prog}
APPEND
PROPERTY COMPILE_DEFINITIONS "VTKM_DEVICE_ADAPTER=${device_adapter}" )
target_compile_definitions(${test_prog} PRIVATE "VTKM_DEVICE_ADAPTER=${device_adapter}")
endif()
endfunction(vtkm_worklet_unit_tests)
@ -562,8 +537,7 @@ function(vtkm_benchmarks device_adapter)
set_source_files_properties(${benchmark_headers}
PROPERTIES HEADER_FILE_ONLY TRUE)
set_property(TARGET ${benchmark_prog} APPEND PROPERTY
INCLUDE_DIRECTORIES ${VTKm_INCLUDE_DIRS} )
target_include_directories(${benchmark_prog} PRIVATE ${VTKm_INCLUDE_DIRS})
target_link_libraries(${benchmark_prog} ${VTKm_LIBRARIES})
if(MSVC)
@ -573,19 +547,8 @@ function(vtkm_benchmarks device_adapter)
#add the specific compile options for this executable
target_compile_options(${benchmark_prog} PRIVATE ${VTKm_COMPILE_OPTIONS})
#increase warning level if needed, we are going to skip cuda here
#to remove all the false positive unused function warnings that cuda
#generates
if(VTKm_EXTRA_COMPILER_WARNINGS)
set_property(TARGET ${benchmark_prog}
APPEND PROPERTY COMPILE_FLAGS ${CMAKE_CXX_FLAGS_WARN_EXTRA} )
endif()
#set the device adapter on the executable
set_property(TARGET ${benchmark_prog}
APPEND
PROPERTY COMPILE_DEFINITIONS "VTKM_DEVICE_ADAPTER=${device_adapter}" )
target_compile_definitions(${benchmark_prog} PRIVATE "VTKM_DEVICE_ADAPTER=${device_adapter}")
endforeach()
@ -597,6 +560,125 @@ function(vtkm_benchmarks device_adapter)
endfunction(vtkm_benchmarks)
# Given a list of *.cxx source files that during configure time are deterimined
# to have CUDA code, wrap the sources in *.cu files so that they get compiled
# with nvcc.
function(vtkm_wrap_sources_for_cuda cuda_source_list_var)
set(original_sources ${ARGN})
set(cuda_sources)
foreach(source_file ${original_sources})
get_filename_component(source_name ${source_file} NAME_WE)
get_filename_component(source_file_path ${source_file} ABSOLUTE)
set(wrapped_file ${CMAKE_CURRENT_BINARY_DIR}/${source_name}.cu)
configure_file(
${VTKm_SOURCE_DIR}/CMake/WrapCUDASource.cu.in
${wrapped_file}
@ONLY)
list(APPEND cuda_sources ${wrapped_file})
endforeach(source_file)
set_source_files_properties(${original_sources}
PROPERTIES HEADER_FILE_ONLY TRUE
)
set(${cuda_source_list_var} ${cuda_sources} PARENT_SCOPE)
endfunction(vtkm_wrap_sources_for_cuda)
set(VTKM_HAS_AT_LEAST_ONE_LIBRARY FALSE CACHE INTERNAL "" FORCE)
# Add a VTK-m library. The name of the library will match the "kit" name
# (e.g. vtkm_rendering) unless the NAME argument is given.
#
# vtkm_library(
# [NAME <name>]
# SOURCES <source_list>
# [CUDA]
# [WRAP_FOR_CUDA <source_list>]
# )
function(vtkm_library)
set(options CUDA)
set(oneValueArgs NAME)
set(multiValueArgs SOURCES WRAP_FOR_CUDA)
cmake_parse_arguments(VTKm_LIB
"${options}" "${oneValueArgs}" "${multiValueArgs}"
${ARGN}
)
vtkm_get_kit_name(kit dir_prefix)
if(VTKm_LIB_NAME)
set(lib_name ${VTKm_LIB_NAME})
else()
set(lib_name ${kit})
endif()
if(VTKm_LIB_CUDA)
vtkm_setup_nvcc_flags(old_nvcc_flags old_cxx_flags)
vtkm_wrap_sources_for_cuda(cuda_sources ${VTKm_LIB_WRAP_FOR_CUDA})
# Cuda compiles do not respect target_include_directories
cuda_include_directories(${VTKm_INCLUDE_DIRS})
cuda_add_library(${lib_name} ${VTKm_LIB_SOURCES} ${cuda_sources})
set(CUDA_NVCC_FLAGS ${old_nvcc_flags})
set(CMAKE_CXX_FLAGS ${old_cxx_flags})
else()
add_library(${lib_name} ${VTKm_LIB_SOURCES})
endif()
#do it as a property value so we don't pollute the include_directories
#for any other targets
set_property(TARGET ${lib_name} APPEND PROPERTY
INCLUDE_DIRECTORIES ${VTKm_INCLUDE_DIRS} )
target_link_libraries(${lib_name} ${VTKm_LIBRARIES})
set(cxx_args ${VTKm_COMPILE_OPTIONS})
separate_arguments(cxx_args)
target_compile_options(${lib_name} PRIVATE ${cxx_args})
# Make sure libraries go to lib directory and dll go to bin directory.
# Mostly important on Windows.
set_target_properties(${lib_name} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
)
if(MSVC)
vtkm_setup_msvc_properties(${lib_name})
endif()
if(VTKm_EXTRA_COMPILER_WARNINGS)
set(cxx_args ${CMAKE_CXX_FLAGS_WARN_EXTRA})
separate_arguments(cxx_args)
target_compile_options(${lib_name}
PRIVATE ${cxx_args}
)
endif(VTKm_EXTRA_COMPILER_WARNINGS)
generate_export_header(${lib_name})
#generate_export_header creates the header in CMAKE_CURRENT_BINARY_DIR.
#The build expects it in the install directory.
file(COPY
${CMAKE_CURRENT_BINARY_DIR}/${lib_name}_export.h
DESTINATION
${CMAKE_BINARY_DIR}/${VTKm_INSTALL_INCLUDE_DIR}/${dir_prefix}
)
install(TARGETS ${lib_name}
EXPORT ${VTKm_EXPORT_NAME}
ARCHIVE DESTINATION ${VTKm_INSTALL_LIB_DIR}
LIBRARY DESTINATION ${VTKm_INSTALL_LIB_DIR}
RUNTIME DESTINATION ${VTKm_INSTALL_BIN_DIR}
)
vtkm_install_headers("${dir_prefix}"
${CMAKE_BINARY_DIR}/${VTKm_INSTALL_INCLUDE_DIR}/${dir_prefix}/${lib_name}_export.h
)
set(VTKM_HAS_AT_LEAST_ONE_LIBRARY TRUE CACHE INTERNAL "" FORCE)
endfunction(vtkm_library)
# The Thrust project is not as careful as the VTKm project in avoiding warnings
# on shadow variables and unused arguments. With a real GCC compiler, you
# can disable these warnings inline, but with something like nvcc, those

@ -0,0 +1 @@
#include "@source_file_path@"

82
CMakeLists.txt Executable file → Normal file

@ -34,6 +34,7 @@ endif()
#setup policy rules for CMake 3.3 while we have a minimum required of 2.8.X
if(POLICY CMP0063)
cmake_policy(SET CMP0058 NEW)#All dependencies on built targets are declared
cmake_policy(SET CMP0063 NEW)#Honor visibility properties for all targets
endif()
@ -45,9 +46,13 @@ set(VTKm_PATCH_VERSION 0)
set(VTKm_VERSION "${VTKm_MAJOR_VERSION}.${VTKm_MINOR_VERSION}.${VTKm_PATCH_VERSION}")
set(VTKm_INSTALL_INCLUDE_DIR "include")
set(VTKm_INSTALL_CONFIG_DIR "include")
set(VTKm_INSTALL_CONFIG_DIR "lib")
set(VTKm_INSTALL_LIB_DIR "lib")
set(VTKm_INSTALL_BIN_DIR "bin")
set(VTKm_INSTALL_CMAKE_MODULE_DIR "share/vtkm/cmake")
set(VTKm_EXPORT_NAME "VTKmTargets")
set(VTKm_REQUIRED_BOOST_VERSION "1.48")
set(VTKm_CMAKE_MODULE_PATH ${VTKm_SOURCE_DIR}/CMake)
@ -69,14 +74,18 @@ if(NOT VTKm_Base_FOUND)
endif()
#-----------------------------------------------------------------------------
# Check for Cxx11 support.
option(VTKm_FORCE_ANSI
"Turn off compiling any features not compatible with ISO-C++98 (ANSI)." OFF)
if (NOT VTKm_FORCE_ANSI)
include(CMake/CheckCXX11Features.cmake)
else (NOT VTKm_FORCE_ANSI)
set(VTKm_NO_VARIADIC_TEMPLATE TRUE)
endif ()
# Add flag to enable C++11 support.
if (NOT CMAKE_VERSION VERSION_LESS "3.1")
option(VTKm_ENABLE_CXX11 "Build VTKm using C++11" ON)
else()
set(VTKm_ENABLE_CXX11 OFF)
endif()
# If the user has requested C++11, propagate that information to CMake
if (VTKm_ENABLE_CXX11)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS False)
endif()
#-----------------------------------------------------------------------------
# Add supplemental compiler warnings, and GCC visibility support.
@ -107,6 +116,9 @@ option(VTKm_USE_DOUBLE_PRECISION
)
option(VTKm_USE_64BIT_IDS "Use 64-bit indices." ON)
option(BUILD_SHARED_LIBS "Build VTK-m with shared libraries" ON)
set(VTKm_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
if (VTKm_ENABLE_TESTING)
enable_testing()
include(CTest)
@ -129,7 +141,7 @@ endif (VTKm_ENABLE_TBB)
if (VTKm_ENABLE_CUDA)
vtkm_configure_component_CUDA()
if(NOT VTKm_CUDA_FOUND)
message(SEND_ERROR "Could not load CUDA configuration. If CUDA is not available, turn off VTKm_ENABLE_TBB.")
message(SEND_ERROR "Could not load CUDA configuration. If CUDA is not available, turn off VTKm_ENABLE_CUDA.")
endif()
endif (VTKm_ENABLE_CUDA)
@ -144,7 +156,7 @@ set( EXECUTABLE_OUTPUT_PATH
## Set the directory where the libraries will be stored
set( LIBRARY_OUTPUT_PATH
${PROJECT_BINARY_DIR}/libs
${PROJECT_BINARY_DIR}/lib
CACHE PATH
"Directory where all the libraries will be stored"
)
@ -225,12 +237,6 @@ if (VTKm_BUILD_DOCUMENTATION)
vtkm_build_documentation()
endif()
#-----------------------------------------------------------------------------
# Build examples
if(VTKm_BUILD_EXAMPLES)
add_subdirectory(examples)
endif(VTKm_BUILD_EXAMPLES)
#-----------------------------------------------------------------------------
# Ready files for find_package
include(CMakePackageConfigHelpers)
@ -239,7 +245,16 @@ string(REPLACE ";" " " VTKm_AVAILABLE_COMPONENTS_LIST
"${VTKm_AVAILABLE_COMPONENTS}"
)
set(VTKm_LOAD_COMPONENTS_COMMANDS "
set(VTKm_LOAD_COMPONENTS_COMMANDS "# Clear out old FOUND flags")
foreach(component ${VTKm_AVAILABLE_COMPONENTS})
set(VTKm_LOAD_COMPONENTS_COMMANDS "${VTKm_LOAD_COMPONENTS_COMMANDS}
set(VTKm_${component}_FOUND)"
)
endforeach(component)
set(VTKm_LOAD_COMPONENTS_COMMANDS "${VTKm_LOAD_COMPONENTS_COMMANDS}
# Load each component selected in find_package
foreach(comp \${VTKm_FIND_COMPONENTS})")
foreach(component ${VTKm_AVAILABLE_COMPONENTS})
@ -270,7 +285,12 @@ configure_package_config_file(
${VTKm_SOURCE_DIR}/CMake/VTKmConfig.cmake.in
${VTKm_BINARY_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmConfig.cmake
INSTALL_DESTINATION ${VTKm_INSTALL_CONFIG_DIR}
PATH_VARS VTKm_INSTALL_INCLUDE_DIR VTKm_INSTALL_CMAKE_MODULE_DIR
PATH_VARS
VTKm_INSTALL_INCLUDE_DIR
VTKm_INSTALL_CONFIG_DIR
VTKm_INSTALL_LIB_DIR
VTKm_INSTALL_BIN_DIR
VTKm_INSTALL_CMAKE_MODULE_DIR
)
write_basic_package_version_file(
@ -314,7 +334,23 @@ install(
DESTINATION ${VTKm_INSTALL_CMAKE_MODULE_DIR}
)
# Create and install exports for external projects
if(${VTKM_HAS_AT_LEAST_ONE_LIBRARY})
export(EXPORT ${VTKm_EXPORT_NAME}
FILE ${CMAKE_BINARY_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmTargets.cmake
)
install(EXPORT ${VTKm_EXPORT_NAME}
DESTINATION ${VTKm_INSTALL_LIB_DIR}
FILE VTKmTargets.cmake
)
else() # No libraries built
file(WRITE ${CMAKE_BINARY_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmTargets.cmake
"# This build of VTK-m has no libraries to export targets for"
)
install(FILES ${CMAKE_BINARY_DIR}/${VTKm_INSTALL_CONFIG_DIR}/VTKmTargets.cmake
DESTINATION ${VTKm_INSTALL_LIB_DIR}
)
endif()
# Enable CPack packaging
set(CPACK_PACKAGE_DESCRIPTION_FILE ${VTKm_SOURCE_DIR}/README.md)
@ -327,3 +363,9 @@ set(CPACK_PACKAGE_FILE_NAME "VTKm-${VTKm_VERSION}")
set(CPACK_RESOURCE_FILE_LICENSE ${VTKm_SOURCE_DIR}/LICENSE.txt)
set(CPACK_RESOURCE_FILE_README ${VTKm_SOURCE_DIR}/README.md)
include(CPack)
#-----------------------------------------------------------------------------
# Build examples
if(VTKm_BUILD_EXAMPLES)
add_subdirectory(examples)
endif(VTKm_BUILD_EXAMPLES)

@ -110,7 +110,7 @@ a tab stop is, so it is better to not use them at all.
+ Namespaces should not be brought into global scope or the scope of any VTK-M package names- pace with the “using” keyword. It should also be avoided in class, method, and function scopes (fully qualified namespace references are preferred).
+ All code must be valid by the C++03 and C++11 specifications. It must also compile on older compilers that support C++98. Code that uses language features not available in C++98 must have a second implementation that works around the limitations of C++98. The VTKM_FORCE_ANSI turns on a compiler check for ANSI compatibility in gcc and clang compilers.
+ All code must be valid by the C++03 and C++11 specifications. It must also compile on older compilers that support C++98. Code that uses language features not available in C++11 must have a second implementation that works for C++98. The VTKm_ENABLE_CXX11 turns on C++11 compiler flags for gcc, clang, intel and MSVC compilers.
+ Limit all lines to 80 characters whenever possible.

@ -1,31 +0,0 @@
### Design Decisions ###
A quick list of what the final design of vtkm should look like:
Code Layout:
```
vtkm/
cont/
- vtkm::cont::ArrayHandle
- vtkm::cont::CellSet
- vtkm::cont::DataSet
interop/
- OpenGL interop classes
- VTK interop classes
cuda/
filters/
- vtkm::filter::ThresholdFilter
- vtkm::filter::ContourFilter
- Mutators?
exec/
cuda/
worklets/
- vtkm::worklet::WorkletMapField
- vtkm::worklet::WorkletMapCell
```

@ -19,8 +19,9 @@
## this software.
##
##=============================================================================
#specify that all examples should be quiet in the detection of components
set(VTKm_CONFIGURE_QUIET TRUE)
#add the directory that contains the VTK-m config file to the cmake
#path so that our examples can find VTK-m
set(CMAKE_PREFIX_PATH ${VTKm_BINARY_DIR}/${VTKm_INSTALL_CONFIG_DIR})
add_subdirectory(clipping)
add_subdirectory(demo)

@ -19,20 +19,17 @@
## this software.
##
##=============================================================================
vtkm_configure_component_Serial()
vtkm_configure_component_CUDA()
vtkm_configure_component_TBB()
#Find the VTK-m package
find_package(VTKm REQUIRED QUIET
OPTIONAL_COMPONENTS Serial CUDA TBB
)
add_executable(Clipping_SERIAL Clipping.cxx)
target_include_directories(Clipping_SERIAL PRIVATE ${VTKm_INCLUDE_DIRS})
target_link_libraries(Clipping_SERIAL ${VTKm_LIBRARIES})
target_compile_options(Clipping_SERIAL PRIVATE ${VTKm_COMPILE_OPTIONS})
set_property(
TARGET Clipping_SERIAL
APPEND
PROPERTY COMPILE_DEFINITIONS "VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_SERIAL")
target_compile_definitions(Clipping_SERIAL PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_SERIAL")
if(VTKm_CUDA_FOUND)
set (cudaSource "${CMAKE_CURRENT_BINARY_DIR}/Clipping.cu")
@ -61,8 +58,6 @@ if(VTKm_TBB_FOUND)
target_include_directories(Clipping_TBB PRIVATE ${VTKm_INCLUDE_DIRS})
target_link_libraries(Clipping_TBB ${VTKm_LIBRARIES})
target_compile_options(Clipping_TBB PRIVATE PRIVATE ${VTKm_COMPILE_OPTIONS})
set_property(
TARGET Clipping_TBB
APPEND
PROPERTY COMPILE_DEFINITIONS "VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_TBB")
target_compile_definitions(Clipping_TBB PRIVATE
"VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_TBB")
endif()

@ -63,14 +63,15 @@ int main(int argc, char *argv[])
input.GetField(0);
vtkm::Float32 clipValue = boost::lexical_cast<vtkm::Float32>(argv[argc - 2]);
vtkm::worklet::Clip<DeviceAdapter> clip;
vtkm::worklet::Clip clip;
vtkm::cont::Timer<DeviceAdapter> total;
vtkm::cont::Timer<DeviceAdapter> timer;
vtkm::cont::CellSetExplicit<> outputCellSet =
clip.Run(input.GetCellSet(0),
scalarField.GetData().ResetTypeList(vtkm::TypeListTagScalarAll()),
clipValue);
clipValue,
DeviceAdapter());
vtkm::Float64 clipTime = timer.GetElapsedTime();
vtkm::cont::DataSet output;
@ -78,7 +79,7 @@ int main(int argc, char *argv[])
timer.Reset();
vtkm::cont::DynamicArrayHandle coords =
clip.ProcessField(input.GetCoordinateSystem(0).GetData());
clip.ProcessField(input.GetCoordinateSystem(0), DeviceAdapter());
vtkm::Float64 processCoordinatesTime = timer.GetElapsedTime();
output.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", coords));
@ -91,7 +92,8 @@ int main(int argc, char *argv[])
continue; // clip only supports point fields for now.
}
vtkm::cont::DynamicArrayHandle data =
clip.ProcessField(inField.GetData().ResetTypeList(vtkm::TypeListTagAll()));
clip.ProcessField(inField.GetData().ResetTypeList(vtkm::TypeListTagAll()),
DeviceAdapter());
output.AddField(vtkm::cont::Field(inField.GetName(),
vtkm::cont::Field::ASSOC_POINTS, data));
}

@ -19,9 +19,14 @@
## this software.
##
##=============================================================================
vtkm_configure_component_OSMESA()
if(VTKm_OSMESA_FOUND)
#Find the VTK-m package
find_package(VTKm QUIET REQUIRED
OPTIONAL_COMPONENTS Serial CUDA TBB OSMesa Rendering
)
if(VTKm_OSMesa_FOUND AND VTKm_Rendering_FOUND)
if(VTKm_CUDA_FOUND)
# Cuda compiles do not respect target_include_directories
cuda_include_directories(${VTKm_INCLUDE_DIRS})
@ -30,8 +35,17 @@ if(VTKm_OSMESA_FOUND)
add_executable(Demo Demo.cxx)
endif()
#need to setup the default device adapter.
target_include_directories(Demo PRIVATE ${VTKm_INCLUDE_DIRS})
target_link_libraries(Demo ${VTKm_LIBRARIES})
target_compile_options(Demo PRIVATE ${VTKm_COMPILE_OPTIONS})
#when we are using TBB pass in the default device adapter as
#a compile definition to make sure we build with TBB selected
if(VTKm_TBB_FOUND)
target_compile_definitions(Demo
PRIVATE "VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_TBB")
endif()
endif()

@ -18,4 +18,7 @@
// this software.
//============================================================================
//Define the CUDA device adapter as being the default
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_CUDA
#include "Demo.cxx"

@ -20,10 +20,10 @@
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/rendering/Actor.h>
#include <vtkm/rendering/CanvasOSMesa.h>
#include <vtkm/rendering/MapperGL.h>
#include <vtkm/rendering/CanvasRayTracer.h>
#include <vtkm/rendering/MapperRayTracer.h>
#include <vtkm/rendering/Scene.h>
#include <vtkm/rendering/View.h>
#include <vtkm/rendering/View3D.h>
#include <vtkm/cont/DeviceAdapter.h>
#include <vtkm/cont/testing/Testing.h>
@ -34,6 +34,19 @@
#include <iostream>
void makeScene(const vtkm::cont::DataSet &inputData,
const vtkm::rendering::ColorTable &colorTable,
const std::string &fieldName,
vtkm::rendering::Scene &scene)
{
scene.AddActor(vtkm::rendering::Actor(inputData.GetCellSet(),
inputData.GetCoordinateSystem(),
inputData.GetField(fieldName),
colorTable));
}
// This example reads an input vtk file specified on the command-line (or generates a default
// input data set if none is provided), uses VTK-m's rendering engine to render it to an
// output file using OS Mesa, instantiates an isosurface filter using VTK-m's filter
@ -65,71 +78,67 @@ int main(int argc, char* argv[])
fieldName = "SCALARS:pointvar";
}
typedef vtkm::rendering::MapperGL< > Mapper;
typedef vtkm::rendering::CanvasOSMesa Canvas;
typedef vtkm::rendering::MapperRayTracer<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> Mapper;
typedef vtkm::rendering::CanvasRayTracer Canvas;
// Set up a camera for rendering the input data
const vtkm::cont::CoordinateSystem coords = inputData.GetCoordinateSystem();
Mapper mapper;
vtkm::rendering::Camera3D &camera = mapper.GetCamera();
vtkm::Float64 coordsBounds[6];
coords.GetBounds(coordsBounds,VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
vtkm::rendering::Camera camera = vtkm::rendering::Camera();
//Set3DView
vtkm::Bounds coordsBounds = coords.GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
camera.ResetToBounds(coordsBounds);
vtkm::Vec<vtkm::Float32,3> totalExtent;
totalExtent[0] = vtkm::Float32(coordsBounds[1] - coordsBounds[0]);
totalExtent[1] = vtkm::Float32(coordsBounds[3] - coordsBounds[2]);
totalExtent[2] = vtkm::Float32(coordsBounds[5] - coordsBounds[4]);
totalExtent[0] = vtkm::Float32(coordsBounds.X.Max - coordsBounds.X.Min);
totalExtent[1] = vtkm::Float32(coordsBounds.Y.Max - coordsBounds.Y.Min);
totalExtent[2] = vtkm::Float32(coordsBounds.Z.Max - coordsBounds.Z.Min);
vtkm::Float32 mag = vtkm::Magnitude(totalExtent);
vtkm::Normalize(totalExtent);
camera.LookAt = totalExtent * (mag * .5f);
camera.Up = vtkm::make_Vec(0.f, 1.f, 0.f);
camera.NearPlane = 1.f;
camera.FarPlane = 100.f;
camera.FieldOfView = 60.f;
camera.Height = 512;
camera.Width = 512;
camera.Position = totalExtent * (mag * 2.f);
camera.SetLookAt(totalExtent * (mag * .5f));
camera.SetViewUp(vtkm::make_Vec(0.f, 1.f, 0.f));
camera.SetClippingRange(1.f, 100.f);
camera.SetFieldOfView(60.f);
camera.SetPosition(totalExtent * (mag * 2.f));
vtkm::rendering::ColorTable colorTable("thermal");
mapper.SetActiveColorTable(colorTable);
mapper.SetCamera(camera);
// Create a scene for rendering the input data
vtkm::rendering::Scene3D scene;
vtkm::rendering::Scene scene;
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
vtkm::rendering::CanvasOSMesa surface(512,512,bg);
scene.Actors.push_back(vtkm::rendering::Actor(inputData.GetCellSet(),
inputData.GetCoordinateSystem(),
inputData.GetField(fieldName),
colorTable));
Canvas canvas(512,512);
makeScene(inputData, colorTable, fieldName, scene);
// Create a view and use it to render the input data using OS Mesa
vtkm::rendering::View3D<Mapper, Canvas> view1(scene,
vtkm::rendering::View3D view(scene,
mapper,
surface,
canvas,
camera,
bg);
view1.Initialize();
view1.Paint();
view1.SaveAs("demo_input.pnm");
view.Initialize();
view.Paint();
view.SaveAs("demo_input.pnm");
// Create an isosurface filter
vtkm::filter::MarchingCubes filter;
filter.SetGenerateNormals(false);
filter.SetMergeDuplicatePoints(false);
filter.SetIsoValue(isovalue);
vtkm::filter::DataSetResult result = filter.Execute( inputData,
vtkm::filter::ResultDataSet result = filter.Execute( inputData,
inputData.GetField(fieldName) );
filter.MapFieldOntoOutput(result, inputData.GetField(fieldName));
vtkm::cont::DataSet& outputData = result.GetDataSet();
// Render a separate image with the output isosurface
std::cout << "about to render the results of the MarchingCubes filter" << std::endl;
scene.Actors.clear();
scene.Actors.push_back(vtkm::rendering::Actor(outputData.GetCellSet(),
outputData.GetCoordinateSystem(),
outputData.GetField(fieldName),
colorTable));
vtkm::rendering::Scene scene2;
makeScene(outputData, colorTable, fieldName, scene2);
vtkm::rendering::View3D< Mapper, Canvas> view2(scene,
vtkm::rendering::View3D view2(scene2,
mapper,
surface,
canvas,
camera,
bg);
view2.Initialize();
view2.Paint();

@ -24,3 +24,4 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_executable(DynamicDispatcherExample main.cxx)
target_include_directories(DynamicDispatcherExample PRIVATE ${VTKm_INCLUDE_DIRS})
target_link_libraries(DynamicDispatcherExample ${VTKm_LIBRARIES})
target_compile_options(DynamicDispatcherExample PRIVATE ${VTKm_COMPILE_OPTIONS})

@ -20,13 +20,12 @@
##
##=============================================================================
find_package(GLUT)
#Find the VTK-m package
find_package(VTKm REQUIRED QUIET
OPTIONAL_COMPONENTS Serial CUDA TBB OpenGL Interop
)
vtkm_configure_component_OpenGL()
vtkm_configure_component_Interop()
vtkm_configure_component_Serial()
vtkm_configure_component_CUDA()
vtkm_configure_component_TBB()
find_package(GLUT)
if(VTKm_Interop_FOUND AND VTKm_OpenGL_FOUND AND GLUT_FOUND)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

@ -180,7 +180,7 @@ struct HelloVTKMInterop
//global static so that glut callback can access it
typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter;
HelloVTKMInterop< DeviceAdapter, vtkm::Float32 >* helloWorld = NULL;
HelloVTKMInterop< DeviceAdapter, vtkm::Float32 >* helloWorld = nullptr;
// Render the output using simple OpenGL
void run()

@ -20,12 +20,12 @@
##
##=============================================================================
find_package(GLUT)
#Find the VTK-m package
find_package(VTKm REQUIRED QUIET
OPTIONAL_COMPONENTS Serial CUDA TBB OpenGL
)
vtkm_configure_component_OpenGL()
vtkm_configure_component_Serial()
vtkm_configure_component_CUDA()
vtkm_configure_component_TBB()
find_package(GLUT)
if(VTKm_OpenGL_FOUND AND GLUT_FOUND)
add_executable(IsosurfaceUniformGrid_SERIAL IsosurfaceUniformGrid.cxx quaternion.h)

@ -66,11 +66,11 @@ public:
typedef _1 InputDomain;
const vtkm::Id xdim, ydim, zdim;
const vtkm::FloatDefault xmin, ymin, zmin, xmax, ymax, zmax;
const vtkm::Float32 xmin, ymin, zmin, xmax, ymax, zmax;
const vtkm::Id cellsPerLayer;
VTKM_CONT_EXPORT
TangleField(const vtkm::Id3 dims, const vtkm::FloatDefault mins[3], const vtkm::FloatDefault maxs[3]) : xdim(dims[0]), ydim(dims[1]), zdim(dims[2]),
TangleField(const vtkm::Id3 dims, const vtkm::Float32 mins[3], const vtkm::Float32 maxs[3]) : xdim(dims[0]), ydim(dims[1]), zdim(dims[2]),
xmin(mins[0]), ymin(mins[1]), zmin(mins[2]), xmax(maxs[0]), ymax(maxs[1]), zmax(maxs[2]), cellsPerLayer((xdim) * (ydim)) { };
VTKM_EXEC_EXPORT
@ -80,9 +80,9 @@ public:
const vtkm::Id y = (vertexId / (xdim)) % (ydim);
const vtkm::Id z = vertexId / cellsPerLayer;
const vtkm::FloatDefault fx = static_cast<vtkm::FloatDefault>(x) / static_cast<vtkm::FloatDefault>(xdim-1);
const vtkm::FloatDefault fy = static_cast<vtkm::FloatDefault>(y) / static_cast<vtkm::FloatDefault>(xdim-1);
const vtkm::FloatDefault fz = static_cast<vtkm::FloatDefault>(z) / static_cast<vtkm::FloatDefault>(xdim-1);
const vtkm::Float32 fx = static_cast<vtkm::Float32>(x) / static_cast<vtkm::Float32>(xdim-1);
const vtkm::Float32 fy = static_cast<vtkm::Float32>(y) / static_cast<vtkm::Float32>(xdim-1);
const vtkm::Float32 fz = static_cast<vtkm::Float32>(z) / static_cast<vtkm::Float32>(xdim-1);
const vtkm::Float32 xx = 3.0f*(xmin+(xmax-xmin)*(fx));
const vtkm::Float32 yy = 3.0f*(ymin+(ymax-ymin)*(fy));
@ -100,8 +100,8 @@ vtkm::cont::DataSet MakeIsosurfaceTestDataSet(vtkm::Id3 dims)
const vtkm::Id3 vdims(dims[0] + 1, dims[1] + 1, dims[2] + 1);
vtkm::FloatDefault mins[3] = {-1.0f, -1.0f, -1.0f};
vtkm::FloatDefault maxs[3] = {1.0f, 1.0f, 1.0f};
vtkm::Float32 mins[3] = {-1.0f, -1.0f, -1.0f};
vtkm::Float32 maxs[3] = {1.0f, 1.0f, 1.0f};
vtkm::cont::ArrayHandle<vtkm::Float32> fieldArray;
vtkm::cont::ArrayHandleCounting<vtkm::Id> vertexCountImplicitArray(0, 1, vdims[0]*vdims[1]*vdims[2]);

@ -20,11 +20,10 @@
##
##=============================================================================
find_package(GLUT)
vtkm_configure_component_Serial()
vtkm_configure_component_CUDA()
vtkm_configure_component_TBB()
#Find the VTK-m package
find_package(VTKm REQUIRED QUIET
OPTIONAL_COMPONENTS Serial CUDA TBB
)
if(VTKm_CUDA_FOUND)
# Cuda compiles do not respect target_include_directories

@ -29,6 +29,10 @@
#include <vtkm/cont/cuda/DeviceAdapterCuda.h>
#include <vtkm/cont/tbb/DeviceAdapterTBB.h>
#include <vtkm/cont/DeviceAdapterSerial.h>
#include <vtkm/cont/TryExecute.h>
typedef vtkm::Vec< vtkm::Float32, 3 > FloatVec3;
typedef vtkm::Vec< vtkm::UInt8, 4 > Uint8Vec4;
struct GenerateSurfaceWorklet : public vtkm::worklet::WorkletMapField
{
@ -55,77 +59,34 @@ struct GenerateSurfaceWorklet : public vtkm::worklet::WorkletMapField
}
};
template<bool> struct CanRun;
template<typename T, typename DeviceAdapterTag>
void run_if_valid(vtkm::cont::ArrayHandle< vtkm::Vec< T, 3 > > inHandle,
vtkm::cont::ArrayHandle< vtkm::Vec< T, 3 > > outCoords,
vtkm::cont::ArrayHandle< vtkm::Vec< vtkm::UInt8, 4 > > outColors,
DeviceAdapterTag tag)
struct RunGenerateSurfaceWorklet
{
typedef vtkm::cont::DeviceAdapterTraits<DeviceAdapterTag>
DeviceAdapterTraits;
if(DeviceAdapterTraits::Valid)
{
std::cout << "Running a worklet on device adapter: "
<< DeviceAdapterTraits::GetName() << std::endl;
}
else
{
std::cout << "Unable to run a worklet on device adapter: "
<< DeviceAdapterTraits::GetName() << std::endl;
}
CanRun<DeviceAdapterTraits::Valid>::run(inHandle,outCoords,outColors,tag);
}
//Implementation that we call on device adapters we don't have support
//enabled for
template<>
struct CanRun<false>
{
template<typename T, typename DeviceAdapterTag>
static void run(vtkm::cont::ArrayHandle< vtkm::Vec< T, 3 > > vtkmNotUsed(inHandle),
vtkm::cont::ArrayHandle< vtkm::Vec< T, 3 > > vtkmNotUsed(outCoords),
vtkm::cont::ArrayHandle< vtkm::Vec< vtkm::UInt8, 4 > > vtkmNotUsed(outColors),
DeviceAdapterTag)
template<typename DeviceAdapterTag>
bool operator()(DeviceAdapterTag ) const
{
}
};
//At this point we know we have runtime support
typedef vtkm::cont::DeviceAdapterTraits<DeviceAdapterTag> DeviceTraits;
//Implementation that we call on device adapters we do have support
//enabled for
template<>
struct CanRun<true>
{
template<typename T, typename DeviceAdapterTag>
static void run(vtkm::cont::ArrayHandle< vtkm::Vec< T, 3 > > inHandle,
vtkm::cont::ArrayHandle< vtkm::Vec< T, 3 > > outCoords,
vtkm::cont::ArrayHandle< vtkm::Vec< vtkm::UInt8, 4 > > outColors,
DeviceAdapterTag)
{
//even though we have support for this device adapter we haven't determined
//if we actually have run-time support. This is a significant issue with
//the CUDA backend
vtkm::cont::RuntimeDeviceInformation<DeviceAdapterTag> runtime;
const bool haveSupport = runtime.Exists();
if(haveSupport)
{
typedef vtkm::worklet::DispatcherMapField<GenerateSurfaceWorklet,
DeviceAdapterTag> DispatcherType;
GenerateSurfaceWorklet worklet( 0.05f );
DispatcherType(worklet).Invoke( inHandle,
outCoords,
outColors);
}
std::cout << "Running a worklet on device adapter: "
<< DeviceTraits::GetName() << std::endl;
GenerateSurfaceWorklet worklet( 0.05f );
DispatcherType(worklet).Invoke( this->In,
this->Out,
this->Color);
return true;
}
vtkm::cont::ArrayHandle< FloatVec3 > In;
vtkm::cont::ArrayHandle< FloatVec3 > Out;
vtkm::cont::ArrayHandle< Uint8Vec4 > Color;
};
template<typename T>
std::vector< vtkm::Vec<T, 3> > make_testData(int size)
{
@ -143,27 +104,39 @@ std::vector< vtkm::Vec<T, 3> > make_testData(int size)
return data;
}
//This is the list of devices to compile in support for. The order of the
//devices determines the runtime preference.
struct DevicesToTry
: vtkm::ListTagBase<
vtkm::cont::DeviceAdapterTagCuda,
vtkm::cont::DeviceAdapterTagTBB,
vtkm::cont::DeviceAdapterTagSerial> { };
int main(int, char**)
{
typedef vtkm::Vec< vtkm::Float32, 3 > FloatVec3;
typedef vtkm::Vec< vtkm::UInt8, 4 > Uint8Vec4;
std::vector< FloatVec3 > data = make_testData<vtkm::Float32>(1024);
typedef ::vtkm::cont::DeviceAdapterTagSerial SerialTag;
typedef ::vtkm::cont::DeviceAdapterTagTBB TBBTag;
typedef ::vtkm::cont::DeviceAdapterTagCuda CudaTag;
//make array handles for the data
vtkm::cont::ArrayHandle< FloatVec3 > in = vtkm::cont::make_ArrayHandle(data);
vtkm::cont::ArrayHandle< FloatVec3 > out;
vtkm::cont::ArrayHandle< Uint8Vec4 > color;
//Run the algorithm on all backends that we have compiled support for.
run_if_valid(in, out, color, CudaTag());
run_if_valid(in, out, color, TBBTag());
run_if_valid(in, out, color, SerialTag());
// TryExecutes takes a functor and a list of devices. It then tries to run
// the functor for each device (in the order given in the list) until the
// execution succeeds. This allows you to compile in support for multiple
// devices which have runtime requirements ( GPU / HW Accelerator ) and
// correctly choose the best device at runtime.
//
// The functor parentheses operator should take exactly one argument, which is
// the DeviceAdapterTag to use. The functor should return true if the execution
// succeeds.
//
// This function also optionally takes a vtkm::cont::RuntimeDeviceTracker, which
// will monitor for certain failures across calls to TryExecute and skip trying
// devices with a history of failure.
RunGenerateSurfaceWorklet task;
task.In = vtkm::cont::make_ArrayHandle(data);
vtkm::cont::TryExecute(task, DevicesToTry());
}

@ -20,32 +20,16 @@
##
##=============================================================================
vtkm_configure_component_OpenGL()
vtkm_configure_component_Serial()
#vtkm_configure_component_CUDA()
#vtkm_configure_component_TBB()
#Find the VTK-m package
find_package(VTKm REQUIRED QUIET
OPTIONAL_COMPONENTS Serial OpenGL Rendering
)
if(VTKm_OpenGL_FOUND AND GLUT_FOUND)
find_package(GLUT)
if(VTKm_OpenGL_FOUND AND VTKm_Rendering_FOUND AND GLUT_FOUND)
add_executable(Rendering_SERIAL Rendering.cxx)
target_include_directories(Rendering_SERIAL PRIVATE ${GLUT_INCLUDE_DIR} ${VTKm_INCLUDE_DIRS})
target_link_libraries(Rendering_SERIAL ${GLUT_LIBRARIES} ${VTKm_LIBRARIES})
target_compile_options(Rendering_SERIAL PRIVATE ${VTKm_COMPILE_OPTIONS})
# if(VTKm_CUDA_FOUND)
# vtkm_disable_troublesome_thrust_warnings()
# # Cuda compiles do not respect target_include_directories
# cuda_include_directories(${VTKm_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS})
# cuda_add_executable(Rendering_CUDA Rendering.cu)
# target_include_directories(Rendering_CUDA PRIVATE ${GLUT_INCLUDE_DIR} ${VTKm_INCLUDE_DIRS})
# target_link_libraries(Rendering_CUDA ${GLUT_LIBRARIES} ${VTKm_LIBRARIES})
# target_compile_options(Rendering_CUDA PRIVATE ${VTKm_COMPILE_OPTIONS})
# endif()
# if(VTKm_TBB_FOUND)
# add_executable(Rendering_TBB IsosurfaceUniformGridTBB.cxx)
# target_include_directories(Rendering_TBB PRIVATE ${GLUT_INCLUDE_DIR} ${VTKm_INCLUDE_DIRS})
# target_link_libraries(Rendering_TBB ${GLUT_LIBRARIES} ${VTKm_LIBRARIES})
# target_compile_options(Rendering_TBB PRIVATE ${VTKm_COMPILE_OPTIONS})
# endif()
endif()

@ -42,10 +42,10 @@
#include <vtkm/rendering/CanvasGL.h>
#include <vtkm/rendering/MapperGL.h>
#include <vtkm/rendering/View.h>
#include <vtkm/rendering/View3D.h>
#include <vtkm/rendering/ColorTable.h>
vtkm::rendering::View3D *view = NULL;
vtkm::rendering::View3D *view = nullptr;
const vtkm::Int32 W = 512, H = 512;
int buttonStates[3] = {GLUT_UP, GLUT_UP, GLUT_UP};
@ -138,7 +138,7 @@ main(int argc, char* argv[])
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
vtkm::rendering::CanvasGL canvas;
vtkm::rendering::MapperGL<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> mapper;
vtkm::rendering::MapperGL mapper;
vtkm::rendering::Scene scene;
scene.AddActor(vtkm::rendering::Actor(ds.GetCellSet(),

@ -20,12 +20,12 @@
##
##=============================================================================
find_package(GLUT)
#Find the VTK-m package
find_package(VTKm REQUIRED QUIET
OPTIONAL_COMPONENTS Serial CUDA TBB OpenGL
)
vtkm_configure_component_OpenGL()
vtkm_configure_component_Serial()
vtkm_configure_component_CUDA()
vtkm_configure_component_TBB()
find_package(GLUT)
if(VTKm_OpenGL_FOUND AND GLUT_FOUND)
add_executable(StreamLineUniformGrid_SERIAL StreamLineUniformGrid.cxx)

@ -148,7 +148,7 @@ void displayCall()
vtkm::cont::CellSetExplicit<> cellSet;
outDataSet.GetCellSet(0).CopyTo(cellSet);
const vtkm::cont::DynamicArrayHandleCoordinateSystem &coordArray =
outDataSet.GetCoordinateSystem(0).GetData();
outDataSet.GetCoordinateSystem().GetData();
vtkm::Id numberOfCells = cellSet.GetNumberOfCells();
vtkm::Id numberOfPoints = coordArray.GetNumberOfValues();
@ -156,7 +156,7 @@ void displayCall()
// Need the actual vertex points from a static cast of the dynamic array but can't get it right
// So use cast and call on a functor that stores that dynamic array into static array we created
vertexArray.Allocate(numberOfPoints);
coordArray.CastAndCall(GetVertexArray());
vtkm::cont::CastAndCall(coordArray, GetVertexArray());
// Each cell is a polyline
glColor3f(1.0f, 0.0f, 0.0f);
@ -237,7 +237,7 @@ int main(int argc, char* argv[])
// Read in the vector data for testing
FILE * pFile = fopen(argv[1], "rb");
if (pFile == NULL) perror ("Error opening file");
if (pFile == nullptr) perror ("Error opening file");
size_t ret_code = 0;
// Size of the dataset

@ -20,12 +20,14 @@
##
##=============================================================================
#Find the VTK-m package
find_package(VTKm REQUIRED QUIET
OPTIONAL_COMPONENTS Serial CUDA TBB OpenGL
)
find_package(GLUT)
vtkm_configure_component_OpenGL()
vtkm_configure_component_Serial()
vtkm_configure_component_CUDA()
vtkm_configure_component_TBB()
if(VTKm_OpenGL_FOUND AND GLUT_FOUND)
add_executable(TetrahedralizeExplicitGrid_SERIAL TetrahedralizeExplicitGrid.cxx)

@ -204,14 +204,10 @@ void displayCall()
outDataSet.GetCellSet(0).CopyTo(cellSet);
vtkm::Id numberOfCells = cellSet.GetNumberOfCells();
// Get the coordinate system and coordinate data
const vtkm::cont::DynamicArrayHandleCoordinateSystem coordArray =
outDataSet.GetCoordinateSystem(0).GetData();
// Need the actual vertex points from a static cast of the dynamic array but can't get it right
// So use cast and call on a functor that stores that dynamic array into static array we created
vertexArray.Allocate(numberOfInPoints);
coordArray.CastAndCall(GetVertexArray());
vtkm::cont::CastAndCall(outDataSet.GetCoordinateSystem(), GetVertexArray());
// Draw the five tetrahedra belonging to each hexadron
vtkm::Float32 color[5][3] = {

@ -170,13 +170,11 @@ void displayCall()
// Get the cell set, coordinate system and coordinate data
vtkm::cont::CellSetSingleType<> cellSet;
tetDataSet.GetCellSet(0).CopyTo(cellSet);
const vtkm::cont::DynamicArrayHandleCoordinateSystem &coordArray =
tetDataSet.GetCoordinateSystem(0).GetData();
// Need the actual vertex points from a static cast of the dynamic array but can't get it right
// So use cast and call on a functor that stores that dynamic array into static array we created
vertexArray.Allocate(numberOfInPoints);
coordArray.CastAndCall(GetVertexArray());
vtkm::cont::CastAndCall(tetDataSet.GetCoordinateSystem(), GetVertexArray());
// Draw the five tetrahedra belonging to each hexadron
vtkm::Id tetra = 0;

@ -176,14 +176,10 @@ void displayCall()
outDataSet.GetCellSet(0).CopyTo(cellSet);
vtkm::Id numberOfCells = cellSet.GetNumberOfCells();
// Get the coordinate system and coordinate data
const vtkm::cont::DynamicArrayHandleCoordinateSystem coordArray =
outDataSet.GetCoordinateSystem(0).GetData();
// Need the actual vertex points from a static cast of the dynamic array but can't get it right
// So use cast and call on a functor that stores that dynamic array into static array we created
vertexArray.Allocate(numberOfInPoints);
coordArray.CastAndCall(GetVertexArray());
vtkm::cont::CastAndCall(outDataSet.GetCoordinateSystem(), GetVertexArray());
// Draw the two triangles belonging to each quad
vtkm::Float32 color[4][3] = {

@ -132,13 +132,11 @@ void displayCall()
// Get the cellset, coordinate system and coordinate data
vtkm::cont::CellSetSingleType<> cellSet;
tetDataSet.GetCellSet(0).CopyTo(cellSet);
const vtkm::cont::DynamicArrayHandleCoordinateSystem &coordArray =
tetDataSet.GetCoordinateSystem(0).GetData();
// Need the actual vertex points from a static cast of the dynamic array but can't get it right
// So use cast and call on a functor that stores that dynamic array into static array we created
vertexArray.Allocate(numberOfInPoints);
coordArray.CastAndCall(GetVertexArray());
vtkm::cont::CastAndCall(tetDataSet.GetCoordinateSystem(), GetVertexArray());
// Draw the two triangles belonging to each quad
vtkm::Id triangle = 0;

@ -18,8 +18,6 @@
## this software.
##============================================================================
include_directories(${Boost_INCLUDE_DIRS})
set(headers
Assert.h
BinaryPredicates.h

@ -23,10 +23,6 @@
#include <vtkm/StaticAssert.h>
#include <vtkm/Types.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/type_traits/integral_constant.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
namespace vtkm {
/// CellShapeId identifies the type of each cell. Currently these are designed
@ -63,10 +59,10 @@ enum CellShapeIdEnum
namespace internal {
/// A class that can be used to determine if a class is a CellShapeTag or not.
/// The class will be either boost::true_type or boost::false_type.
/// The class will be either std::true_type or std::false_type.
///
template<typename T>
struct CellShapeTagCheck : boost::false_type { };
struct CellShapeTagCheck : std::false_type { };
} // namespace internal
@ -87,7 +83,7 @@ struct CellShapeIdToTag {
// probably means you are using an ID that does not have a defined cell
// shape.
typedef boost::false_type valid;
typedef std::false_type valid;
};
@ -100,7 +96,7 @@ struct CellShapeIdToTag {
}; \
namespace internal { \
template<> \
struct CellShapeTagCheck<vtkm::CellShapeTag ## name> : boost::true_type { }; \
struct CellShapeTagCheck<vtkm::CellShapeTag ## name> : std::true_type { }; \
} \
VTKM_EXEC_CONT_EXPORT \
const char *GetCellShapeName(vtkm::CellShapeTag ## name) { \
@ -108,7 +104,7 @@ struct CellShapeIdToTag {
} \
template<> \
struct CellShapeIdToTag<vtkm::idname> { \
typedef boost::true_type valid; \
typedef std::true_type valid; \
typedef vtkm::CellShapeTag ## name Tag; \
}

@ -25,9 +25,7 @@
#include <vtkm/StaticAssert.h>
#include <vtkm/internal/ExportMacros.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/type_traits/is_base_of.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
#include <type_traits>
namespace vtkm {
@ -36,8 +34,8 @@ namespace internal {
template<typename ListTag>
struct ListTagCheck
{
static const bool Valid =
boost::is_base_of<vtkm::detail::ListRoot,ListTag>::value;
static VTKM_CONSTEXPR bool Valid = std::is_base_of<vtkm::detail::ListRoot,
ListTag>::value;
};
} // namespace internal

File diff suppressed because it is too large Load Diff

@ -32,7 +32,7 @@ $# expander.py Math.h.in > Math.h
$#
$# Ignore the following comment. It is meant for the generated file.
// **** DO NOT EDIT THIS FILE!!! ****
// This file is automatically generated by FunctionInterfaceDetailPre.h.in
// This file is automatically generated by Math.h.in
#ifndef vtk_m_Math_h
#define vtk_m_Math_h
@ -45,52 +45,32 @@ $# Ignore the following comment. It is meant for the generated file.
#include <limits.h>
#include <math.h>
#include <stdlib.h>
// The nonfinite and sign test functions are usually defined as macros, and
// boost seems to want to undefine those macros so that it can implement the
// C99 templates and other implementations of the same name. Get around the
// problem by using the boost version when compiling for a CPU.
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/math/special_functions/fpclassify.hpp>
#include <boost/math/special_functions/sign.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
#include <cmath>
#define VTKM_USE_BOOST_CLASSIFY
#define VTKM_USE_BOOST_SIGN
#endif // !VTKM_CUDA
#if !defined(__CUDA_ARCH__)
#define VTKM_USE_STL_MIN_MAX
#define VTKM_USE_STL
#include <algorithm>
#endif
#if defined(VTKM_MSVC) && !defined(VTKM_CUDA)
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/math/special_functions/acosh.hpp>
#include <boost/math/special_functions/asinh.hpp>
#include <boost/math/special_functions/atanh.hpp>
#include <boost/math/special_functions/cbrt.hpp>
#include <boost/math/special_functions/expm1.hpp>
#include <boost/math/special_functions/log1p.hpp>
#include <boost/math/special_functions/round.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
#define VTKM_USE_BOOST_MATH
#if (_MSC_VER <= 1600) && !defined(VTKM_USE_STL_MIN_MAX)
#define VTKM_USE_STL_MIN_MAX
#include <algorithm>
#endif
#include <math.h>
#endif
#define VTKM_SYS_MATH_FUNCTION_32(func) func ## f
#define VTKM_SYS_MATH_FUNCTION_64(func) func
#define VTKM_CUDA_MATH_FUNCTION_32(func) func ## f
#define VTKM_CUDA_MATH_FUNCTION_64(func) func
$py(
def unary_function(name, type, returntype, expression):
def unary_function(name, type, returntype, cuda_expression, std_expression):
return '''VTKM_EXEC_CONT_EXPORT
{2} {0}({1} x) {{
#ifdef VTKM_CUDA
return {3};
#else
return {4};
#endif
}}
'''.format(name, type, returntype, expression)
'''.format(name, type, returntype, cuda_expression, std_expression)
def unary_Vec_function(vtkmname):
return '''template<typename T, vtkm::IdComponent N>
@ -130,11 +110,13 @@ def unary_math_function_no_vec(vtkmname, sysname, returntype = None):
return unary_function(vtkmname,
'vtkm::Float32',
'vtkm::Float32' if returntype == None else returntype,
'VTKM_SYS_MATH_FUNCTION_32(' + sysname + ')(x)') + \
'VTKM_CUDA_MATH_FUNCTION_32(' + sysname + ')(x)',
'std::' + sysname + '(x)') + \
unary_function(vtkmname,
'vtkm::Float64',
'vtkm::Float64' if returntype == None else returntype,
'VTKM_SYS_MATH_FUNCTION_64(' + sysname + ')(x)')
'VTKM_CUDA_MATH_FUNCTION_64(' + sysname + ')(x)',
'std::' + sysname + '(x)')
def unary_math_function(vtkmname, sysname):
return unary_math_function_no_vec(vtkmname, sysname) + \
@ -161,20 +143,26 @@ def unary_template_function_no_vec(vtkmname,
'vtkm::Float64' if returntype == None else returntype,
preexpression)
def binary_function(name, type, expression):
def binary_function(name, type, cuda_expression, std_expression):
return '''VTKM_EXEC_CONT_EXPORT
{1} {0}({1} x, {1} y) {{
#ifdef VTKM_CUDA
return {2};
#else
return {3};
#endif
}}
'''.format(name, type, expression)
'''.format(name, type, cuda_expression, std_expression)
def binary_math_function(vtkmname, sysname):
return binary_function(vtkmname,
'vtkm::Float32',
'VTKM_SYS_MATH_FUNCTION_32(' + sysname + ')(x,y)') + \
'VTKM_CUDA_MATH_FUNCTION_32(' + sysname + ')(x,y)',
'std::' + sysname + '(x,y)') + \
binary_function(vtkmname,
'vtkm::Float64',
'VTKM_SYS_MATH_FUNCTION_64(' + sysname + ')(x,y)')
'VTKM_CUDA_MATH_FUNCTION_64(' + sysname + ')(x,y)',
'std::' + sysname + '(x,y)')
def binary_template_function(vtkmname, expression):
return '''VTKM_EXEC_CONT_EXPORT
@ -279,35 +267,20 @@ $unary_math_function('TanH', 'tanh')\
/// Compute the hyperbolic arc sine of \p x.
///
#ifdef VTKM_USE_BOOST_MATH
$unary_template_function_no_vec('ASinH', 'boost::math::asinh(x)')\
$#
#else // !VTKM_USE_BOOST_MATH
$unary_math_function_no_vec('ASinH', 'asinh')\
$#
#endif // !VTKM_USE_BOOST_MATH
$unary_Vec_function('ASinH')\
/// Compute the hyperbolic arc cosine of \p x.
///
#ifdef VTKM_USE_BOOST_MATH
$unary_template_function_no_vec('ACosH', 'boost::math::acosh(x)')\
$#
#else // !VTKM_USE_BOOST_MATH
$unary_math_function_no_vec('ACosH', 'acosh')\
$#
#endif // !VTKM_USE_BOOST_MATH
$unary_Vec_function('ACosH')\
/// Compute the hyperbolic arc tangent of \p x.
///
#ifdef VTKM_USE_BOOST_MATH
$unary_template_function_no_vec('ATanH', 'boost::math::atanh(x)')\
$#
#else // !VTKM_USE_BOOST_MATH
$unary_math_function_no_vec('ATanH', 'atanh')\
$#
#endif // !VTKM_USE_BOOST_MATH
$unary_Vec_function('ATanH')\
//-----------------------------------------------------------------------------
@ -325,23 +298,31 @@ $unary_math_function('Sqrt', 'sqrt')\
/// should use this function whenever dividing by the square root.
///
#ifdef VTKM_CUDA
$unary_math_function_no_vec('RSqrt', 'rsqrt')\
$#
VTKM_EXEC_CONT_EXPORT
vtkm::Float32 RSqrt(vtkm::Float32 x) {
return rsqrtf(x);
}
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 RSqrt(vtkm::Float64 x) {
return rsqrt(x);
}
#else // !VTKM_CUDA
$unary_template_function_no_vec('RSqrt', '1/vtkm::Sqrt(x)')\
$#
VTKM_EXEC_CONT_EXPORT
vtkm::Float32 RSqrt(vtkm::Float32 x) {
return 1/vtkm::Sqrt(x);
}
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 RSqrt(vtkm::Float64 x) {
return 1/vtkm::Sqrt(x);
}
#endif // !VTKM_CUDA
$unary_Vec_function('RSqrt')\
/// Compute the cube root of \p x.
///
#ifdef VTKM_USE_BOOST_MATH
$unary_template_function_no_vec('Cbrt', 'boost::math::cbrt(x)')\
$#
#else // !VTKM_USE_BOOST_MATH
$unary_math_function_no_vec('Cbrt', 'cbrt')\
$#
#endif // !VTKM_USE_BOOST_MATH
$unary_Vec_function('Cbrt')\
/// Compute the reciprocal cube root of \p x. The result of this function is
@ -350,12 +331,25 @@ $unary_Vec_function('Cbrt')\
/// should use this function whenever dividing by the cube root.
///
#ifdef VTKM_CUDA
$unary_math_function_no_vec('RCbrt', 'rcbrt')\
$#
VTKM_EXEC_CONT_EXPORT
vtkm::Float32 RCbrt(vtkm::Float32 x) {
return rcbrtf(x);
}
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 RCbrt(vtkm::Float64 x) {
return rcbrt(x);
}
#else // !VTKM_CUDA
$unary_template_function_no_vec('RCbrt', '1/vtkm::Cbrt(x)')\
$#
VTKM_EXEC_CONT_EXPORT
vtkm::Float32 RCbrt(vtkm::Float32 x) {
return 1/vtkm::Cbrt(x);
}
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 RCbrt(vtkm::Float64 x) {
return 1/vtkm::Cbrt(x);
}
#endif // !VTKM_CUDA
$unary_Vec_function('RCbrt')\
/// Computes e**\p x, the base-e exponential of \p x.
@ -364,36 +358,39 @@ $unary_math_function('Exp', 'exp')\
/// Computes 2**\p x, the base-2 exponential of \p x.
///
#ifdef VTKM_MSVC
$unary_template_function_no_vec('Exp2', 'vtkm::Pow(2,x)')\
$#
#else // !VTKM_USE_BOOST_MATH
$unary_math_function_no_vec('Exp2', 'exp2')\
$#
#endif // !VTKM_USE_BOOST_MATH
$unary_Vec_function('Exp2')\
/// Computes (e**\p x) - 1, the of base-e exponental of \p x then minus 1. The
/// accuracy of this function is good even for very small values of x.
///
#ifdef VTKM_USE_BOOST_MATH
$unary_template_function_no_vec('ExpM1', 'boost::math::expm1(x)')\
$#
#else // !VTKM_USE_BOOST_MATH
$unary_math_function_no_vec('ExpM1', 'expm1')\
$#
#endif // !VTKM_USE_BOOST_MATH
$unary_Vec_function('ExpM1')\
/// Computes 10**\p x, the base-10 exponential of \p x.
///
#ifdef VTKM_CUDA
$unary_math_function_no_vec('Exp10', 'exp10')\
$#
VTKM_EXEC_CONT_EXPORT
vtkm::Float32 Exp10(vtkm::Float32 x) {
return exp10f(x);
}
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 Exp10(vtkm::Float64 x) {
return exp10(x);
}
#else // !VTKM_CUDA
$unary_template_function_no_vec('Exp10', 'vtkm::Pow(10, x);')\
$#
VTKM_EXEC_CONT_EXPORT
vtkm::Float32 Exp10(vtkm::Float32 x) {
return vtkm::Pow(10, x);;
}
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 Exp10(vtkm::Float64 x) {
return vtkm::Pow(10, x);;
}
#endif // !VTKM_CUDA
$unary_Vec_function('Exp10')\
/// Computes the natural logarithm of \p x.
@ -402,25 +399,8 @@ $unary_math_function('Log', 'log')\
/// Computes the logarithm base 2 of \p x.
///
#ifdef VTKM_MSVC
VTKM_EXEC_CONT_EXPORT
vtkm::Float32 Log2(vtkm::Float32 x) {
//windows and boost don't provide log2
//0.6931471805599453 is the constant value of log(2)
const vtkm::Float32 log2v = 0.6931471805599453f;
return vtkm::Log(x)/log2v;
}
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 Log2(vtkm::Float64 x) {
//windows and boost don't provide log2
//0.6931471805599453 is the constant value of log(2)
const vtkm::Float64 log2v = 0.6931471805599453;
return vtkm::Log(x)/log2v;
}
#else // !VTKM_USE_BOOST_MATH
$unary_math_function_no_vec('Log2', 'log2')\
$#
#endif // !VTKM_USE_BOOST_MATH
$unary_Vec_function('Log2')\
/// Computes the logarithm base 10 of \p x.
@ -429,13 +409,8 @@ $unary_math_function('Log10', 'log10')\
/// Computes the value of log(1+x) accurately for very small values of x.
///
#ifdef VTKM_USE_BOOST_MATH
$unary_template_function_no_vec('Log1P', 'boost::math::log1p(x)')\
$#
#else // !VTKM_USE_BOOST_MATH
$unary_math_function_no_vec('Log1P', 'log1p')\
$#
#endif // !VTKM_USE_BOOST_MATH
$unary_Vec_function('Log1P')\
//-----------------------------------------------------------------------------
@ -444,26 +419,26 @@ $unary_Vec_function('Log1P')\
template<typename T>
VTKM_EXEC_CONT_EXPORT
T Max(const T &x, const T &y);
#ifdef VTKM_USE_STL_MIN_MAX
#ifdef VTKM_USE_STL
$binary_template_function('Max', '(std::max)(x, y)')\
$#
#else // !VTKM_USE_STL_MIN_MAX
#else // !VTKM_USE_STL
$binary_math_function('Max', 'fmax')\
$#
#endif // !VTKM_USE_STL_MIN_MAX
#endif // !VTKM_USE_STL
/// Returns \p x or \p y, whichever is smaller.
///
template<typename T>
VTKM_EXEC_CONT_EXPORT
T Min(const T &x, const T &y);
#ifdef VTKM_USE_STL_MIN_MAX
#ifdef VTKM_USE_STL
$binary_template_function('Min', '(std::min)(x, y)')\
$#
#else // !VTKM_USE_STL_MIN_MAX
#else // !VTKM_USE_STL
$binary_math_function('Min', 'fmin')\
$#
#endif // !VTKM_USE_STL_MIN_MAX
#endif // !VTKM_USE_STL
namespace detail {
@ -754,9 +729,7 @@ template<typename T>
VTKM_EXEC_CONT_EXPORT
bool IsNan(T x)
{
#ifdef VTKM_USE_BOOST_CLASSIFY
using boost::math::isnan;
#endif
using std::isnan;
return (isnan(x) != 0);
}
@ -766,9 +739,7 @@ template<typename T>
VTKM_EXEC_CONT_EXPORT
bool IsInf(T x)
{
#ifdef VTKM_USE_BOOST_CLASSIFY
using boost::math::isinf;
#endif
using std::isinf;
return (isinf(x) != 0);
}
@ -778,9 +749,7 @@ template<typename T>
VTKM_EXEC_CONT_EXPORT
bool IsFinite(T x)
{
#ifdef VTKM_USE_BOOST_CLASSIFY
using boost::math::isfinite;
#endif
using std::isfinite;
return (isfinite(x) != 0);
}
@ -795,13 +764,8 @@ $unary_math_function('Floor', 'floor')\
/// Round \p x to the nearest integral value.
///
#ifdef VTKM_USE_BOOST_MATH
$unary_template_function_no_vec('Round', 'boost::math::round(x)')\
$#
#else // !VTKM_USE_BOOST_MATH
$unary_math_function_no_vec('Round', 'round')\
$#
#endif // !VTKM_USE_BOOST_MATH
$unary_Vec_function('Round')\
//-----------------------------------------------------------------------------
@ -841,16 +805,10 @@ vtkm::Float32 RemainderQuotient(vtkm::Float32 numerator,
vtkm::Float32 denominator,
QType &quotient)
{
#ifdef VTKM_USE_BOOST_MATH
quotient = static_cast<QType>(boost::math::round(numerator/denominator));
return vtkm::Remainder(numerator, denominator);
#else
int iQuotient;
vtkm::Float32 result =
VTKM_SYS_MATH_FUNCTION_32(remquo)(numerator, denominator, &iQuotient);
vtkm::Float32 result = std::remquo(numerator, denominator, &iQuotient);
quotient = iQuotient;
return result;
#endif
}
template<typename QType>
VTKM_EXEC_CONT_EXPORT
@ -858,16 +816,10 @@ vtkm::Float64 RemainderQuotient(vtkm::Float64 numerator,
vtkm::Float64 denominator,
QType &quotient)
{
#ifdef VTKM_USE_BOOST_MATH
quotient = static_cast<QType>(boost::math::round(numerator/denominator));
return vtkm::Remainder(numerator, denominator);
#else
int iQuotient;
vtkm::Float64 result =
VTKM_SYS_MATH_FUNCTION_64(remquo)(numerator, denominator, &iQuotient);
vtkm::Float64 result = std::remquo(numerator, denominator, &iQuotient);
quotient = iQuotient;
return result;
#endif
}
/// Gets the integral and fractional parts of \c x. The return value is the
@ -876,12 +828,12 @@ vtkm::Float64 RemainderQuotient(vtkm::Float64 numerator,
VTKM_EXEC_CONT_EXPORT
vtkm::Float32 ModF(vtkm::Float32 x, vtkm::Float32 &integral)
{
return VTKM_SYS_MATH_FUNCTION_32(modf)(x, &integral);
return std::modf(x, &integral);
}
VTKM_EXEC_CONT_EXPORT
vtkm::Float64 ModF(vtkm::Float64 x, vtkm::Float64 &integral)
{
return VTKM_SYS_MATH_FUNCTION_64(modf)(x, &integral);
return std::modf(x, &integral);
}
//-----------------------------------------------------------------------------
@ -915,9 +867,8 @@ $unary_math_function('Abs', 'fabs')\
$unary_template_function_no_vec('SignBit',
'static_cast<vtkm::Int32>(signbit(x))',
'vtkm::Int32',
'''#ifdef VTKM_USE_BOOST_SIGN
using boost::math::signbit;
#endif
'''
using std::signbit;
''')\
/// Returns true if \p x is less than zero, false otherwise.
@ -927,13 +878,9 @@ $unary_template_function_no_vec('IsNegative', '(vtkm::SignBit(x) != 0)', 'bool')
/// Copies the sign of \p y onto \p x. If \p y is positive, returns Abs(\p x).
/// If \p y is negative, returns -Abs(\p x).
///
#ifdef VTKM_USE_BOOST_SIGN
$binary_template_function('CopySign', 'boost::math::copysign(x,y)')\
$#
#else // !VTKM_USE_BOOST_SIGN
$binary_math_function('CopySign', 'copysign')\
$#
#endif // !VTKM_USE_BOOST_SIGN
template<typename T, vtkm::IdComponent N>
VTKM_EXEC_CONT_EXPORT
vtkm::Vec<T,N> CopySign(const vtkm::Vec<T,N> &x, const vtkm::Vec<T,N> &y)

@ -21,34 +21,12 @@
#define vtk_m_StaticAssert_h
#include <vtkm/internal/Configure.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/static_assert.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
// Newer versions of clang are causing the static assert to issue a warning
// about unused typedefs. In this case, we want to disable the warnings using
// pragmas. However, not all compiler support pragmas in code blocks (although
// fortunately clang does). Thus, only use these pragmas in the instance where
// we need it and know we can use it.
#if defined(VTKM_CLANG) && (__apple_build_version__ >= 7000072) && !defined(VTKM_CUDA)
#include <type_traits>
#define VTKM_STATIC_ASSERT(condition) \
VTKM_THIRDPARTY_PRE_INCLUDE \
BOOST_STATIC_ASSERT(condition) \
VTKM_THIRDPARTY_POST_INCLUDE
static_assert( (condition), __FILE__)
#define VTKM_STATIC_ASSERT_MSG(condition, message) \
VTKM_THIRDPARTY_PRE_INCLUDE \
BOOST_STATIC_ASSERT_MSG(condition, message) \
VTKM_THIRDPARTY_POST_INCLUDE
static_assert( (condition), message)
#else
#define VTKM_STATIC_ASSERT(condition) \
BOOST_STATIC_ASSERT(condition)
#define VTKM_STATIC_ASSERT_MSG(condition, message) \
BOOST_STATIC_ASSERT_MSG(condition, message)
#endif
#endif //vtk_m_StaticAssert_h

@ -22,10 +22,6 @@
#include <vtkm/Types.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/mpl/assert.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
namespace vtkm {
/// \brief A tag used to identify the cell elements in a topology.
@ -63,44 +59,41 @@ struct TopologyElementTagFace { };
namespace internal {
/// Checks to see if the given object is a topology element tag. This check is
/// compatible with the Boost meta-template programing library (MPL). It
/// contains a typedef named \c type that is either boost::mpl::true_ or
/// boost::mpl::false_. Both of these have a typedef named value with the
/// Checks to see if the given object is a topology element tag.This check is
/// compatible with C++11 type_traits.
/// It contains a typedef named \c type that is either std::true_type or
/// std::false_type. Both of these have a typedef named value with the
/// respective boolean value.
///
template<typename T>
struct TopologyElementTagCheck
struct TopologyElementTagCheck : std::false_type
{
typedef boost::mpl::false_ type;
};
template<>
struct TopologyElementTagCheck<vtkm::TopologyElementTagCell>
struct TopologyElementTagCheck<vtkm::TopologyElementTagCell> : std::true_type
{
typedef boost::mpl::true_ type;
};
template<>
struct TopologyElementTagCheck<vtkm::TopologyElementTagPoint>
struct TopologyElementTagCheck<vtkm::TopologyElementTagPoint> : std::true_type
{
typedef boost::mpl::true_ type;
};
template<>
struct TopologyElementTagCheck<vtkm::TopologyElementTagEdge>
struct TopologyElementTagCheck<vtkm::TopologyElementTagEdge> : std::true_type
{
typedef boost::mpl::true_ type;
};
template<>
struct TopologyElementTagCheck<vtkm::TopologyElementTagFace>
struct TopologyElementTagCheck<vtkm::TopologyElementTagFace> : std::true_type
{
typedef boost::mpl::true_ type;
};
#define VTKM_IS_TOPOLOGY_ELEMENT_TAG(type) \
BOOST_MPL_ASSERT(( ::vtkm::internal::TopologyElementTagCheck<type> ))
static_assert( ::vtkm::internal::TopologyElementTagCheck<type>::value, \
"Invalid Topology Element Tag being used");
} // namespace internal

@ -53,11 +53,34 @@ vtkm::Vec<T,3> Transform3DPoint(const vtkm::Matrix<T,4,4> &matrix,
vtkm::dot(vtkm::MatrixGetRow(matrix,2), homogeneousPoint));
}
/// \brief Transform a 3D point by a transformation matrix.
/// \brief Transform a 3D point by a transformation matrix with perspective.
///
/// Given a 4x4 transformation matrix and a 3D point, returns the point
/// transformed by the given matrix in homogeneous coordinates.
///
/// Unlike Transform3DPoint, this method honors the fourth component of the
/// transformed homogeneous coordiante. This makes it applicable for perspective
/// transformations, but requires some more computations.
///
template<typename T>
VTKM_EXEC_CONT_EXPORT
vtkm::Vec<T,3> Transform3DPointPerspective(const vtkm::Matrix<T,4,4> &matrix,
const vtkm::Vec<T,3> &point)
{
vtkm::Vec<T,4> homogeneousPoint(point[0], point[1], point[2], T(1));
T inverseW = 1/vtkm::dot(vtkm::MatrixGetRow(matrix,3), homogeneousPoint);
return vtkm::Vec<T,3>(
vtkm::dot(vtkm::MatrixGetRow(matrix,0), homogeneousPoint)*inverseW,
vtkm::dot(vtkm::MatrixGetRow(matrix,1), homogeneousPoint)*inverseW,
vtkm::dot(vtkm::MatrixGetRow(matrix,2), homogeneousPoint)*inverseW);
}
/// \brief Transform a 3D vector by a transformation matrix.
///
/// Given a 4x4 transformation matrix and a 3D vector, returns the vector
/// transformed by the given matrix in homogeneous coordinates. Unlike points,
/// vectors do not get translated.
///
template<typename T>
VTKM_EXEC_CONT_EXPORT
vtkm::Vec<T,3> Transform3DVector(const vtkm::Matrix<T,4,4> &matrix,

@ -20,20 +20,13 @@
#ifndef vtk_m_Types_h
#define vtk_m_Types_h
#include <vtkm/internal/Configure.h>
#include <vtkm/internal/ExportMacros.h>
#include <vtkm/Assert.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/mpl/or.hpp>
#include <boost/type_traits/is_floating_point.hpp>
#include <boost/type_traits/is_signed.hpp>
#include <boost/utility/enable_if.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
#include <iostream>
#include <type_traits>
/*!
* \namespace vtkm
@ -1237,18 +1230,48 @@ operator*(const vtkm::Vec<vtkm::Float64, Size> &vec, vtkm::Float64 scalar)
vtkm::Float64,vtkm::internal::Multiply>(scalar));
}
template<typename T, vtkm::IdComponent Size>
VTKM_EXEC_CONT_EXPORT
vtkm::Vec<T, Size> operator/(const vtkm::Vec<T, Size> &vec, T scalar)
{
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
vec,
vtkm::internal::BindRightBinaryOp<T,vtkm::internal::Divide>(scalar));
}
template<typename T, vtkm::IdComponent Size>
VTKM_EXEC_CONT_EXPORT
vtkm::Vec<T, Size>
operator/(const vtkm::Vec<T, Size> &vec, vtkm::Float64 scalar)
{
return vtkm::Vec<T, Size>(
vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
vec,
vtkm::internal::BindRightBinaryOp<
vtkm::Float64,vtkm::internal::Divide,T>(scalar)));
}
template<vtkm::IdComponent Size>
VTKM_EXEC_CONT_EXPORT
vtkm::Vec<vtkm::Float64, Size>
operator/(const vtkm::Vec<vtkm::Float64, Size> &vec, vtkm::Float64 scalar)
{
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(
vec,
vtkm::internal::BindRightBinaryOp<
vtkm::Float64,vtkm::internal::Divide>(scalar));
}
// The enable_if for this operator is effectively disabling the negate
// operator for Vec of unsigned integers. Another approach would be
// to use disable_if<is_unsigned>. That would be more inclusive but would
// to use enable_if<!is_unsigned>. That would be more inclusive but would
// also allow other types like Vec<Vec<unsigned> >. If necessary, we could
// change this implementation to be more inclusive.
template<typename T, vtkm::IdComponent Size>
VTKM_EXEC_CONT_EXPORT
typename boost::enable_if<
typename boost::mpl::or_<
typename boost::is_floating_point<T>::type,
typename boost::is_signed<T>::type>::type,
vtkm::Vec<T,Size> >::type
typename std::enable_if<
(std::is_floating_point<T>::value || std::is_signed<T>::value),
vtkm::Vec<T,Size>
>::type
operator-(const vtkm::Vec<T,Size> &x)
{
return vtkm::internal::VecComponentWiseUnaryOperation<Size>()(

@ -22,10 +22,6 @@
#include <vtkm/Types.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/type_traits/remove_const.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
namespace vtkm {
/// A tag for vectors that are "true" vectors (i.e. have more than one
@ -103,10 +99,10 @@ struct VecTraits
/// Returns the value in a given component of the vector.
///
VTKM_EXEC_CONT_EXPORT static const ComponentType &GetComponent(
const typename boost::remove_const<VecType>::type &vector,
const typename std::remove_const<VecType>::type &vector,
vtkm::IdComponent component);
VTKM_EXEC_CONT_EXPORT static ComponentType &GetComponent(
typename boost::remove_const<VecType>::type &vector,
typename std::remove_const<VecType>::type &vector,
vtkm::IdComponent component);
/// Changes the value in a given component of the vector.

@ -33,17 +33,12 @@
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/benchmarking/Benchmarker.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/random.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
#include <algorithm>
#include <cctype>
#include <cmath>
#include <ctime>
#include <iostream>
#include <utility>
#include <random>
#include <string>
#include <utility>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
@ -167,7 +162,7 @@ private:
ValueArrayHandle ValueHandle_src;
ValueArrayHandle ValueHandle_dst;
boost::mt19937 Rng;
std::mt19937 Rng;
VTKM_CONT_EXPORT
BenchCopy(){
@ -362,7 +357,7 @@ private:
typedef vtkm::cont::ArrayHandle<Value, StorageTag> ValueArrayHandle;
ValueArrayHandle ValueHandle;
boost::mt19937 Rng;
std::mt19937 Rng;
VTKM_CONT_EXPORT
BenchSort(){
@ -392,7 +387,7 @@ private:
struct BenchSortByKey {
typedef vtkm::cont::ArrayHandle<Value, StorageTag> ValueArrayHandle;
boost::mt19937 Rng;
std::mt19937 Rng;
vtkm::Id N_KEYS;
ValueArrayHandle ValueHandle;
IdArrayHandle KeyHandle;

@ -0,0 +1,575 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/Math.h>
#include <vtkm/VectorAnalysis.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/cont/Timer.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/benchmarking/Benchmarker.h>
#include <random>
#include <string>
namespace vtkm {
namespace benchmarking {
#define ARRAY_SIZE (1 << 22)
#define CUBE_SIZE 256
const static std::string DIVIDER(40, '-');
enum BenchmarkName {
BLACK_SCHOLES = 1,
MATH = 1 << 1,
FUSED_MATH = 1 << 3,
INTERPOLATE_FIELD = 1 << 4,
ALL = BLACK_SCHOLES |
MATH |
FUSED_MATH |
INTERPOLATE_FIELD
};
template<typename T>
class BlackScholes : public vtkm::worklet::WorkletMapField
{
T Riskfree;
T Volatility;
public:
typedef void ControlSignature(FieldIn<Scalar>, FieldIn<Scalar>,
FieldIn<Scalar>, FieldOut<Scalar>,
FieldOut<Scalar>);
typedef void ExecutionSignature(_1,_2,_3,_4,_5);
BlackScholes(T risk, T volatility):
Riskfree(risk),
Volatility(volatility)
{
}
VTKM_EXEC_EXPORT
T CumulativeNormalDistribution(T d) const
{
const vtkm::Float32 A1 = 0.31938153f;
const vtkm::Float32 A2 = -0.356563782f;
const vtkm::Float32 A3 = 1.781477937f;
const vtkm::Float32 A4 = -1.821255978f;
const vtkm::Float32 A5 = 1.330274429f;
const vtkm::Float32 RSQRT2PI = 0.39894228040143267793994605993438f;
const T K = T(1.0f) / ( T(1.0f) + T(0.2316419f) * vtkm::Abs(d));
T cnd = RSQRT2PI * vtkm::Exp(-0.5f * d * d) *
(K * (A1 + K * (A2 + K * (A3 + K * (A4 + K * A5)))));
if(d > 0)
{
cnd = 1.0f - cnd;
}
return cnd;
}
VTKM_EXEC_EXPORT
void operator()(const T& stockPrice, const T& optionStrike, const T& optionYears,
T& callResult, T& putResult) const
{
// Black-Scholes formula for both call and put
const T sqrtYears = vtkm::Sqrt(optionYears);
const T volMultSqY = this->Volatility * sqrtYears;
const T d1 = ( vtkm::Log(stockPrice / optionStrike) + (this->Riskfree + 0.5f * Volatility * Volatility) * optionYears) / (volMultSqY);
const T d2 = d1 - volMultSqY;
const T CNDD1 = CumulativeNormalDistribution(d1);
const T CNDD2 = CumulativeNormalDistribution(d2);
//Calculate Call and Put simultaneously
T expRT = vtkm::Exp( - this->Riskfree * optionYears);
callResult = stockPrice * CNDD1 - optionStrike * expRT * CNDD2;
putResult = optionStrike * expRT * (1.0f - CNDD2) - stockPrice * (1.0f - CNDD1);
}
};
class Mag : public vtkm::worklet::WorkletMapField
{
public:
typedef void ControlSignature(FieldIn<Vec3>, FieldOut<Scalar>);
typedef void ExecutionSignature(_1,_2);
template<typename T>
VTKM_EXEC_EXPORT
void operator()(const vtkm::Vec<T,3>& vec, T& result) const
{
result = vtkm::Magnitude(vec);
}
};
class Square : public vtkm::worklet::WorkletMapField
{
public:
typedef void ControlSignature(FieldIn<Scalar>, FieldOut<Scalar>);
typedef void ExecutionSignature(_1,_2);
template<typename T>
VTKM_EXEC_EXPORT
void operator()(T input, T& output) const
{
output = input * input;
}
};
class Sin : public vtkm::worklet::WorkletMapField
{
public:
typedef void ControlSignature(FieldIn<Scalar>, FieldOut<Scalar>);
typedef void ExecutionSignature(_1,_2);
template<typename T>
VTKM_EXEC_EXPORT
void operator()(T input, T& output) const
{
output = vtkm::Sin(input);
}
};
class Cos : public vtkm::worklet::WorkletMapField
{
public:
typedef void ControlSignature(FieldIn<Scalar>, FieldOut<Scalar>);
typedef void ExecutionSignature(_1,_2);
template<typename T>
VTKM_EXEC_EXPORT
void operator()(T input, T& output) const
{
output = vtkm::Cos(input);
}
};
class FusedMath : public vtkm::worklet::WorkletMapField
{
public:
typedef void ControlSignature(FieldIn<Vec3>, FieldOut<Scalar>);
typedef void ExecutionSignature(_1,_2);
template<typename T>
VTKM_EXEC_EXPORT
void operator()(const vtkm::Vec<T,3>& vec, T& result) const
{
const T m = vtkm::Magnitude(vec);
result = vtkm::Cos( vtkm::Sin(m) * vtkm::Sin(m) );
}
};
class GenerateEdges : public vtkm::worklet::WorkletMapPointToCell
{
public:
typedef void ControlSignature( CellSetIn cellset, WholeArrayOut< > edgeIds);
typedef void ExecutionSignature(PointIndices, ThreadIndices, _2);
typedef _1 InputDomain;
template<typename ConnectivityInVec,
typename ThreadIndicesType,
typename IdPairTableType>
VTKM_EXEC_EXPORT
void operator()(const ConnectivityInVec &connectivity,
const ThreadIndicesType threadIndices,
const IdPairTableType &edgeIds) const
{
const vtkm::Id writeOffset = (threadIndices.GetInputIndex() * 12);
const vtkm::IdComponent edgeTable[24] = { 0, 1, 1, 2, 3, 2, 0, 3,
4, 5, 5, 6, 7, 6, 4, 7,
0, 4, 1, 5, 2, 6, 3, 7 };
for(vtkm::Id i=0; i < 12; ++i)
{
const vtkm::Id offset = (i*2);
const vtkm::Id2 edge( connectivity[ edgeTable[offset] ],
connectivity[ edgeTable[offset+1] ] );
edgeIds.Set(writeOffset+i, edge);
}
}
};
class InterpolateField : public vtkm::worklet::WorkletMapField
{
public:
typedef void ControlSignature(FieldIn< Id2Type > interpolation_ids,
FieldIn< Scalar > interpolation_weights,
WholeArrayIn<> inputField,
FieldOut<> output
);
typedef void ExecutionSignature(_1, _2, _3, _4);
typedef _1 InputDomain;
template <typename WeightType, typename InFieldPortalType, typename OutFieldType>
VTKM_EXEC_EXPORT
void operator()(const vtkm::Id2& low_high,
const WeightType &weight,
const InFieldPortalType& inPortal,
OutFieldType &result) const
{
//fetch the low / high values from inPortal
result = vtkm::Lerp(inPortal.Get(low_high[0]),
inPortal.Get(low_high[1]),
weight);
}
};
/// This class runs a series of micro-benchmarks to measure
/// performance of different field operations
template<class DeviceAdapterTag>
class BenchmarkFieldAlgorithms {
typedef vtkm::cont::StorageTagBasic StorageTag;
typedef vtkm::cont::ArrayHandle<vtkm::Id, StorageTag> IdArrayHandle;
typedef vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapterTag> Algorithm;
typedef vtkm::cont::Timer<DeviceAdapterTag> Timer;
private:
template<typename Value>
struct BenchBlackScholes {
typedef vtkm::cont::ArrayHandle<Value, StorageTag> ValueArrayHandle;
ValueArrayHandle StockPrice;
ValueArrayHandle OptionStrike;
ValueArrayHandle OptionYears;
std::vector<Value> price;
std::vector<Value> strike;
std::vector<Value> years;
VTKM_CONT_EXPORT
BenchBlackScholes()
{
std::mt19937 rng;
std::uniform_real_distribution<Value> price_range(Value(5.0f),Value(30.0f));
std::uniform_real_distribution<Value> strike_range(Value(1.0f),Value(100.0f));
std::uniform_real_distribution<Value> year_range(Value(0.25f),Value(10.0f));
this->price.resize(ARRAY_SIZE);
this->strike.resize(ARRAY_SIZE);
this->years.resize(ARRAY_SIZE);
for(std::size_t i=0; i < ARRAY_SIZE; ++i )
{
this->price[i] = price_range(rng);
this->strike[i] = strike_range(rng);
this->years[i] = year_range(rng);
}
this->StockPrice = vtkm::cont::make_ArrayHandle(this->price);
this->OptionStrike = vtkm::cont::make_ArrayHandle(this->strike);
this->OptionYears = vtkm::cont::make_ArrayHandle(this->years);
}
VTKM_CONT_EXPORT
vtkm::Float64 operator()()
{
vtkm::cont::ArrayHandle<Value> callResultHandle, putResultHandle;
const Value RISKFREE = 0.02f;
const Value VOLATILITY = 0.30f;
Timer timer;
BlackScholes<Value> worklet(RISKFREE, VOLATILITY);
vtkm::worklet::DispatcherMapField< BlackScholes<Value> > dispatcher(worklet);
dispatcher.Invoke( this->StockPrice,
this->OptionStrike,
this->OptionYears,
callResultHandle,
putResultHandle
);
return timer.GetElapsedTime();
}
VTKM_CONT_EXPORT
std::string Description() const {
std::stringstream description;
description << "BlackScholes " << ARRAY_SIZE << " stocks";
return description.str();
}
};
VTKM_MAKE_BENCHMARK(BlackScholes, BenchBlackScholes);
template<typename Value>
struct BenchMath {
std::vector< vtkm::Vec<Value, 3> > input;
vtkm::cont::ArrayHandle< vtkm::Vec<Value, 3>, StorageTag> InputHandle;
VTKM_CONT_EXPORT
BenchMath()
{
std::mt19937 rng;
std::uniform_real_distribution<Value> range;
this->input.resize(ARRAY_SIZE);
for(std::size_t i=0; i < ARRAY_SIZE; ++i )
{
this->input[i] = vtkm::Vec<Value, 3>(range(rng),
range(rng),
range(rng));
}
this->InputHandle = vtkm::cont::make_ArrayHandle(this->input);
}
VTKM_CONT_EXPORT
vtkm::Float64 operator()()
{
vtkm::cont::ArrayHandle<Value> tempHandle1;
vtkm::cont::ArrayHandle<Value> tempHandle2;
Timer timer;
vtkm::worklet::DispatcherMapField< Mag >().Invoke( InputHandle, tempHandle1 );
vtkm::worklet::DispatcherMapField< Sin >().Invoke( tempHandle1, tempHandle2 );
vtkm::worklet::DispatcherMapField< Square >().Invoke( tempHandle2, tempHandle1 );
vtkm::worklet::DispatcherMapField< Cos >().Invoke( tempHandle1, tempHandle2 );
return timer.GetElapsedTime();
}
VTKM_CONT_EXPORT
std::string Description() const {
std::stringstream description;
description << "Magnitude -> Sine -> Square -> Cosine " << ARRAY_SIZE << " values";
return description.str();
}
};
VTKM_MAKE_BENCHMARK(Math, BenchMath);
template<typename Value>
struct BenchFusedMath {
std::vector< vtkm::Vec<Value, 3> > input;
vtkm::cont::ArrayHandle< vtkm::Vec<Value, 3>, StorageTag> InputHandle;
VTKM_CONT_EXPORT
BenchFusedMath()
{
std::mt19937 rng;
std::uniform_real_distribution<Value> range;
this->input.resize(ARRAY_SIZE);
for(std::size_t i=0; i < ARRAY_SIZE; ++i )
{
this->input[i] = vtkm::Vec<Value, 3>(range(rng),
range(rng),
range(rng));
}
this->InputHandle = vtkm::cont::make_ArrayHandle(this->input);
}
VTKM_CONT_EXPORT
vtkm::Float64 operator()()
{
vtkm::cont::ArrayHandle<Value> result;
Timer timer;
vtkm::worklet::DispatcherMapField< FusedMath >().Invoke( this->InputHandle, result );
return timer.GetElapsedTime();
}
VTKM_CONT_EXPORT
std::string Description() const {
std::stringstream description;
description << "Fused Magnitude -> Sine -> Square -> Cosine " << ARRAY_SIZE << " values";
return description.str();
}
};
VTKM_MAKE_BENCHMARK(FusedMath, BenchFusedMath);
template<typename Value>
struct BenchEdgeInterp {
std::vector<vtkm::Float32> weight;
std::vector<Value> field;
vtkm::cont::ArrayHandle< vtkm::Float32, StorageTag> WeightHandle;
vtkm::cont::ArrayHandle< Value, StorageTag> FieldHandle;
vtkm::cont::ArrayHandle< vtkm::Id2, StorageTag> EdgePairHandle;
VTKM_CONT_EXPORT
BenchEdgeInterp()
{
std::mt19937 rng;
std::uniform_real_distribution<vtkm::Float32> weight_range(0.0f,1.0f);
std::uniform_real_distribution<Value> field_range;
//basically the core challenge is to generate an array whose
//indexing pattern matches that of a edge based algorithm.
//
//So for this kind of problem we generate the 12 edges of each
//cell and place them into array.
//
vtkm::cont::CellSetStructured<3> cellSet;
cellSet.SetPointDimensions( vtkm::Id3(CUBE_SIZE,CUBE_SIZE,CUBE_SIZE) );
const vtkm::Id numberOfEdges = cellSet.GetNumberOfCells() * 12;
const std::size_t esize = static_cast<std::size_t>(numberOfEdges);
const std::size_t psize = static_cast<std::size_t>(cellSet.GetNumberOfPoints());
this->EdgePairHandle.Allocate( numberOfEdges );
vtkm::worklet::DispatcherMapTopology< GenerateEdges >().Invoke( cellSet,
this->EdgePairHandle );
this->weight.resize( esize );
for(std::size_t i=0; i < esize; ++i )
{
this->weight[i] = weight_range(rng);
}
this->field.resize( psize );
for(std::size_t i=0; i < psize; ++i )
{
this->field[i] = field_range(rng);
}
this->FieldHandle = vtkm::cont::make_ArrayHandle(this->field);
this->WeightHandle = vtkm::cont::make_ArrayHandle(this->weight);
}
VTKM_CONT_EXPORT
vtkm::Float64 operator()()
{
vtkm::cont::ArrayHandle<Value> result;
Timer timer;
vtkm::worklet::DispatcherMapField<
InterpolateField,
DeviceAdapterTag>().Invoke(this->EdgePairHandle,
this->WeightHandle,
this->FieldHandle,
result);
return timer.GetElapsedTime();
}
VTKM_CONT_EXPORT
std::string Description() const {
std::stringstream description;
const std::size_t size = (CUBE_SIZE-1)*(CUBE_SIZE-1)*(CUBE_SIZE-1)*12;
description << "Edge Interpolation of an array of " << size << " values";
return description.str();
}
};
VTKM_MAKE_BENCHMARK(EdgeInterp, BenchEdgeInterp);
public:
struct ValueTypes : vtkm::ListTagBase<vtkm::Float32, vtkm::Float64>{};
struct InterpValueTypes : vtkm::ListTagBase<vtkm::Float32,
vtkm::Float64,
vtkm::Vec< vtkm::Float32, 3>,
vtkm::Vec< vtkm::Float64, 3>
>{};
static VTKM_CONT_EXPORT int Run(int benchmarks){
std::cout << DIVIDER << "\nRunning Field Algorithm benchmarks\n";
if (benchmarks & BLACK_SCHOLES) {
std::cout << DIVIDER << "\nBenchmarking BlackScholes\n";
VTKM_RUN_BENCHMARK(BlackScholes, ValueTypes());
}
if (benchmarks & MATH){
std::cout << DIVIDER << "\nBenchmarking Multiple Math Worklets\n";
VTKM_RUN_BENCHMARK(Math, ValueTypes());
}
if (benchmarks & FUSED_MATH){
std::cout << DIVIDER << "\nBenchmarking Single Fused Math Worklet\n";
VTKM_RUN_BENCHMARK(FusedMath, ValueTypes());
}
if (benchmarks & INTERPOLATE_FIELD){
std::cout << DIVIDER << "\nBenchmarking Edge Based Field InterpolationWorklet\n";
VTKM_RUN_BENCHMARK(EdgeInterp, ValueTypes());
}
return 0;
}
};
#undef ARRAY_SIZE
}
} // namespace vtkm::benchmarking
int main(int argc, char *argv[])
{
int benchmarks = 0;
if (argc < 2){
benchmarks = vtkm::benchmarking::ALL;
}
else {
for (int i = 1; i < argc; ++i){
std::string arg = argv[i];
std::transform(arg.begin(), arg.end(), arg.begin(), ::tolower);
if (arg == "blackscholes")
{
benchmarks |= vtkm::benchmarking::BLACK_SCHOLES;
}
else if (arg == "math")
{
benchmarks |= vtkm::benchmarking::MATH;
}
else if (arg == "fusedmath")
{
benchmarks |= vtkm::benchmarking::FUSED_MATH;
}
else if (arg == "interpolate")
{
benchmarks |= vtkm::benchmarking::INTERPOLATE_FIELD;
}
else
{
std::cout << "Unrecognized benchmark: " << argv[i] << std::endl;
return 1;
}
}
}
//now actually execute the benchmarks
return vtkm::benchmarking::BenchmarkFieldAlgorithms
<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>::Run(benchmarks);
}

@ -0,0 +1,399 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/Math.h>
#include <vtkm/VectorAnalysis.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/cont/Timer.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/benchmarking/Benchmarker.h>
#include <random>
#include <string>
namespace vtkm {
namespace benchmarking {
#define CUBE_SIZE 256
const static std::string DIVIDER(40, '-');
enum BenchmarkName {
CELL_TO_POINT = 1 << 1,
POINT_TO_CELL = 1 << 2,
MC_CLASSIFY = 1 << 3,
ALL = CELL_TO_POINT |
POINT_TO_CELL |
MC_CLASSIFY
};
class AveragePointToCell : public vtkm::worklet::WorkletMapPointToCell
{
public:
typedef void ControlSignature(FieldInPoint<> inPoints,
CellSetIn cellset,
FieldOutCell<> outCells);
typedef void ExecutionSignature(_1, PointCount, _3);
typedef _2 InputDomain;
template<typename PointValueVecType, typename OutType>
VTKM_EXEC_EXPORT
void operator()(const PointValueVecType &pointValues,
const vtkm::IdComponent &numPoints,
OutType &average) const
{
OutType sum = static_cast<OutType>(pointValues[0]);
for (vtkm::IdComponent pointIndex = 1; pointIndex < numPoints; ++pointIndex)
{
sum = sum + static_cast<OutType>(pointValues[pointIndex]);
}
average = sum / static_cast<OutType>(numPoints);
}
};
class AverageCellToPoint : public vtkm::worklet::WorkletMapCellToPoint
{
public:
typedef void ControlSignature(FieldInCell<> inCells,
CellSetIn topology,
FieldOut<> outPoints);
typedef void ExecutionSignature(_1, _3, CellCount);
typedef _2 InputDomain;
template<typename CellVecType, typename OutType>
VTKM_EXEC_EXPORT
void operator()(const CellVecType &cellValues,
OutType &avgVal,
const vtkm::IdComponent &numCellIDs) const
{
//simple functor that returns the average cell Value.
avgVal = static_cast<OutType>(cellValues[0]);
for (vtkm::IdComponent cellIndex = 1; cellIndex < numCellIDs; ++cellIndex)
{
avgVal += static_cast<OutType>(cellValues[cellIndex]);
}
avgVal = avgVal / static_cast<OutType>(numCellIDs);
}
};
// -----------------------------------------------------------------------------
template<typename T>
class Classification : public vtkm::worklet::WorkletMapPointToCell
{
public:
typedef void ControlSignature(
FieldInPoint<> inNodes,
CellSetIn cellset,
FieldOutCell< IdComponentType > outCaseId);
typedef void ExecutionSignature(_1, _3);
typedef _2 InputDomain;
T IsoValue;
VTKM_CONT_EXPORT
Classification(T isovalue) :
IsoValue(isovalue)
{
}
template<typename FieldInType>
VTKM_EXEC_EXPORT
void operator()(const FieldInType &fieldIn,
vtkm::IdComponent &caseNumber) const
{
typedef typename vtkm::VecTraits<FieldInType>::ComponentType FieldType;
const FieldType iso = static_cast<FieldType>(this->IsoValue);
caseNumber= ((fieldIn[0] > iso) |
(fieldIn[1] > iso) << 1 |
(fieldIn[2] > iso) << 2 |
(fieldIn[3] > iso) << 3 |
(fieldIn[4] > iso) << 4 |
(fieldIn[5] > iso) << 5 |
(fieldIn[6] > iso) << 6 |
(fieldIn[7] > iso) << 7);
}
};
/// This class runs a series of micro-benchmarks to measure
/// performance of different field operations
template<class DeviceAdapterTag>
class BenchmarkTopologyAlgorithms {
typedef vtkm::cont::StorageTagBasic StorageTag;
typedef vtkm::cont::ArrayHandle<vtkm::Id, StorageTag> IdArrayHandle;
typedef vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapterTag> Algorithm;
typedef vtkm::cont::Timer<DeviceAdapterTag> Timer;
private:
template<typename T, typename Enable= void> struct NumberGenerator {};
template<typename T>
struct NumberGenerator<T,
typename std::enable_if<
std::is_floating_point<T>::value
>::type
>
{
std::mt19937 rng;
std::uniform_real_distribution<T> distribution;
NumberGenerator(T low, T high): rng(), distribution(low,high) {}
T next() { return distribution(rng); }
};
template<typename T>
struct NumberGenerator<T,
typename std::enable_if<
!std::is_floating_point<T>::value
>::type
>
{
std::mt19937 rng;
std::uniform_int_distribution<T> distribution;
NumberGenerator(T low, T high): rng(), distribution(low,high) {}
T next() { return distribution(rng); }
};
template<typename Value>
struct BenchCellToPointAvg {
std::vector< Value > input;
vtkm::cont::ArrayHandle< Value, StorageTag> InputHandle;
VTKM_CONT_EXPORT
BenchCellToPointAvg()
{
NumberGenerator<Value> generator(static_cast<Value>(1.0),
static_cast<Value>(100.0));
//cube size is points in each dim
const std::size_t csize = (CUBE_SIZE-1)*(CUBE_SIZE-1)*(CUBE_SIZE-1);
this->input.resize( csize );
for(std::size_t i=0; i < csize; ++i )
{
this->input[i] = generator.next();
}
this->InputHandle = vtkm::cont::make_ArrayHandle(this->input);
}
VTKM_CONT_EXPORT
vtkm::Float64 operator()()
{
vtkm::cont::CellSetStructured<3> cellSet;
cellSet.SetPointDimensions( vtkm::Id3(CUBE_SIZE,CUBE_SIZE,CUBE_SIZE) );
vtkm::cont::ArrayHandle<Value,StorageTag> result;
Timer timer;
vtkm::worklet::DispatcherMapTopology< AverageCellToPoint > dispatcher;
dispatcher.Invoke( this->InputHandle,
cellSet,
result);
return timer.GetElapsedTime();
}
VTKM_CONT_EXPORT
std::string Description() const {
const std::size_t csize = (CUBE_SIZE-1)*(CUBE_SIZE-1)*(CUBE_SIZE-1);
std::stringstream description;
description << "Computing Cell To Point Average for cell " << csize << " values";
return description.str();
}
};
VTKM_MAKE_BENCHMARK(CellToPointAvg, BenchCellToPointAvg);
template<typename Value>
struct BenchPointToCellAvg {
std::vector< Value > input;
vtkm::cont::ArrayHandle< Value, StorageTag> InputHandle;
VTKM_CONT_EXPORT
BenchPointToCellAvg()
{
NumberGenerator<Value> generator(static_cast<Value>(1.0),
static_cast<Value>(100.0));
const std::size_t psize = (CUBE_SIZE)*(CUBE_SIZE)*(CUBE_SIZE);
this->input.resize( psize );
for(std::size_t i=0; i < psize; ++i )
{
this->input[i] = generator.next();
}
this->InputHandle = vtkm::cont::make_ArrayHandle(this->input);
}
VTKM_CONT_EXPORT
vtkm::Float64 operator()()
{
vtkm::cont::CellSetStructured<3> cellSet;
cellSet.SetPointDimensions( vtkm::Id3(CUBE_SIZE,CUBE_SIZE,CUBE_SIZE) );
vtkm::cont::ArrayHandle<Value,StorageTag> result;
Timer timer;
vtkm::worklet::DispatcherMapTopology< AveragePointToCell > dispatcher;
dispatcher.Invoke( this->InputHandle,
cellSet,
result);
return timer.GetElapsedTime();
}
VTKM_CONT_EXPORT
std::string Description() const {
const std::size_t psize = (CUBE_SIZE)*(CUBE_SIZE)*(CUBE_SIZE);
std::stringstream description;
description << "Computing Point To Cell Average for point " << psize << " values";
return description.str();
}
};
VTKM_MAKE_BENCHMARK(PointToCellAvg, BenchPointToCellAvg);
template<typename Value>
struct BenchClassification {
std::vector< Value > input;
vtkm::cont::ArrayHandle< Value, StorageTag> InputHandle;
Value IsoValue;
VTKM_CONT_EXPORT
BenchClassification()
{
NumberGenerator<Value> generator(static_cast<Value>(1.0),
static_cast<Value>(100.0));
const std::size_t psize = (CUBE_SIZE)*(CUBE_SIZE)*(CUBE_SIZE);
this->input.resize( psize );
for(std::size_t i=0; i < psize; ++i )
{
this->input[i] = generator.next();
}
this->InputHandle = vtkm::cont::make_ArrayHandle(this->input);
this->IsoValue = generator.next();
}
VTKM_CONT_EXPORT
vtkm::Float64 operator()()
{
vtkm::cont::CellSetStructured<3> cellSet;
cellSet.SetPointDimensions( vtkm::Id3(CUBE_SIZE,CUBE_SIZE,CUBE_SIZE) );
vtkm::cont::ArrayHandle< vtkm::IdComponent, StorageTag> result;
Timer timer;
Classification<Value> worklet(this->IsoValue);
vtkm::worklet::DispatcherMapTopology< Classification<Value> > dispatcher(worklet);
dispatcher.Invoke( this->InputHandle,
cellSet,
result);
return timer.GetElapsedTime();
}
VTKM_CONT_EXPORT
std::string Description() const {
const std::size_t psize = (CUBE_SIZE)*(CUBE_SIZE)*(CUBE_SIZE);
std::stringstream description;
description << "Computing Marching Cubes Classification for point " << psize << " values";
return description.str();
}
};
VTKM_MAKE_BENCHMARK(Classification, BenchClassification);
public:
struct ValueTypes : vtkm::ListTagBase<vtkm::UInt32, vtkm::Int32, vtkm::Int64,
vtkm::Float32, vtkm::Float64 >{};
static VTKM_CONT_EXPORT int Run(int benchmarks){
std::cout << DIVIDER << "\nRunning Topology Algorithm benchmarks\n";
if (benchmarks & CELL_TO_POINT) {
std::cout << DIVIDER << "\nBenchmarking Cell To Point Average\n";
VTKM_RUN_BENCHMARK(CellToPointAvg, ValueTypes());
}
if (benchmarks & POINT_TO_CELL){
std::cout << DIVIDER << "\nBenchmarking Point to Cell Average\n";
VTKM_RUN_BENCHMARK(PointToCellAvg, ValueTypes());
}
if (benchmarks & MC_CLASSIFY){
std::cout << DIVIDER << "\nBenchmarking Hex/Voxel MC Classification\n";
VTKM_RUN_BENCHMARK(Classification, ValueTypes());
}
return 0;
}
};
#undef ARRAY_SIZE
}
} // namespace vtkm::benchmarking
int main(int argc, char *argv[])
{
int benchmarks = 0;
if (argc < 2){
benchmarks = vtkm::benchmarking::ALL;
}
else {
for (int i = 1; i < argc; ++i){
std::string arg = argv[i];
std::transform(arg.begin(), arg.end(), arg.begin(), ::tolower);
if (arg == "celltopoint")
{
benchmarks |= vtkm::benchmarking::CELL_TO_POINT;
}
else if (arg == "pointtocell")
{
benchmarks |= vtkm::benchmarking::POINT_TO_CELL;
}
else if (arg == "classify")
{
benchmarks |= vtkm::benchmarking::MC_CLASSIFY;
}
else {
std::cout << "Unrecognized benchmark: " << argv[i] << std::endl;
return 1;
}
}
}
//now actually execute the benchmarks
return vtkm::benchmarking::BenchmarkTopologyAlgorithms
<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>::Run(benchmarks);
}

@ -20,6 +20,8 @@
set(benchmark_srcs
BenchmarkDeviceAdapter.cxx
BenchmarkFieldAlgorithms.cxx
BenchmarkTopologyAlgorithms.cxx
)
set(benchmark_headers

@ -32,15 +32,10 @@
#include <vtkm/cont/internal/ArrayHandleExecutionManager.h>
#include <vtkm/cont/internal/DeviceAdapterTag.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/concept_check.hpp>
#include <boost/mpl/not.hpp>
#include <boost/smart_ptr/scoped_ptr.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/type_traits/is_base_of.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
#include <memory>
#include <vector>
#include <iterator>
namespace vtkm {
namespace cont {
@ -56,48 +51,48 @@ namespace internal {
class ArrayHandleBase { };
/// Checks to see if the given type and storage can form a valid array handle
/// (some storage objects cannot support all types). This check is compatable
/// with the Boost meta-template programming library (MPL). It contains a
/// typedef named type that is either boost::mpl::true_ or boost::mpl::false_.
/// (some storage objects cannot support all types). This check is compatible
/// with C++11 type_traits. It contains a
/// typedef named type that is either std::true_type or std::false_type.
/// Both of these have a typedef named value with the respective boolean value.
///
template<typename T, typename StorageTag>
struct IsValidArrayHandle {
typedef typename boost::mpl::not_<
typename boost::is_base_of<
vtkm::cont::internal::UndefinedStorage,
vtkm::cont::internal::Storage<T,StorageTag>
>::type
>::type type;
//need to add the not
using type = std::integral_constant<bool,
!( std::is_base_of<
vtkm::cont::internal::UndefinedStorage,
vtkm::cont::internal::Storage<T,StorageTag>
>::value)>;
};
/// Checks to see if the ArrayHandle for the given DeviceAdatper allows
/// writing, as some ArrayHandles (Implicit) don't support writing.
/// This check is compatable with the Boost meta-template programming
/// library (MPL). It contains a typedef named type that is either
// boost::mpl::true_ or boost::mpl::false_.
/// This check is compatible with the C++11 type_traits.
/// It contains a typedef named type that is either
/// std::true_type or std::false_type.
/// Both of these have a typedef named value with the respective boolean value.
///
template<typename ArrayHandle, typename DeviceAdapterTag>
struct IsWriteableArrayHandle {
private:
typedef typename ArrayHandle:: template ExecutionTypes<
DeviceAdapterTag > ExecutionTypes;
typedef typename ExecutionTypes::Portal::ValueType ValueType;
template<typename T>
using ExecutionTypes = typename ArrayHandle::template ExecutionTypes<T>;
using ValueType = typename ExecutionTypes<DeviceAdapterTag>::Portal::ValueType;
//All ArrayHandles that use ImplicitStorage as the final writable location
//will have a value type of void*, which is what we are trying to detect
typedef typename boost::remove_pointer<ValueType>::type RawValueType;
typedef boost::is_void<RawValueType> IsVoidType;
using RawValueType = typename std::remove_pointer<ValueType>::type;
using IsVoidType = std::is_void<RawValueType>;
public:
typedef typename boost::mpl::not_<IsVoidType>::type type;
using type = std::integral_constant<bool, !IsVoidType::value>;
};
/// Checks to see if the given object is an array handle. This check is
/// compatible with the Boost meta-template programming library (MPL). It
/// contains a typedef named \c type that is either boost::mpl::true_ or
/// boost::mpl::false_. Both of these have a typedef named value with the
/// respective boolean value.
/// compatible with C++11 type_traits. It a typedef named \c type that is
/// either std::true_type or std::false_type. Both of these have a typedef
/// named value with the respective boolean value.
///
/// Unlike \c IsValidArrayHandle, if an \c ArrayHandle is used with this
/// class, then it must be created by the compiler and therefore must already
@ -109,8 +104,8 @@ public:
template<typename T>
struct ArrayHandleCheck
{
typedef typename boost::is_base_of<
::vtkm::cont::internal::ArrayHandleBase, T>::type type;
using type = typename std::is_base_of<
::vtkm::cont::internal::ArrayHandleBase, T>::type;
};
#define VTKM_IS_ARRAY_HANDLE(T) \
@ -232,10 +227,10 @@ template<
class ArrayHandle : public internal::ArrayHandleBase
{
private:
typedef vtkm::cont::internal::Storage<T,StorageTag_> StorageType;
typedef vtkm::cont::internal::ArrayHandleExecutionManagerBase<T,StorageTag_>
ExecutionManagerType;
public:
typedef vtkm::cont::internal::Storage<T,StorageTag_> StorageType;
typedef T ValueType;
typedef StorageTag_ StorageTag;
typedef typename StorageType::PortalType PortalControl;
@ -289,7 +284,6 @@ public:
/// with CUDA), then the automatically generated destructor could be
/// created for all devices, and it would not be valid for all devices.
///
VTKM_CONT_EXPORT
virtual ~ArrayHandle() { }
/// \brief Copies an ArrayHandle
@ -302,6 +296,38 @@ public:
return *this;
}
/// Get the storage.
///
VTKM_CONT_EXPORT StorageType& GetStorage()
{
this->SyncControlArray();
if (this->Internals->ControlArrayValid)
{
return this->Internals->ControlArray;
}
else
{
throw vtkm::cont::ErrorControlInternal(
"ArrayHandle::SyncControlArray did not make control array valid.");
}
}
/// Get the storage.
///
VTKM_CONT_EXPORT const StorageType& GetStorage() const
{
this->SyncControlArray();
if (this->Internals->ControlArrayValid)
{
return this->Internals->ControlArray;
}
else
{
throw vtkm::cont::ErrorControlInternal(
"ArrayHandle::SyncControlArray did not make control array valid.");
}
}
/// Get the array portal of the control array.
///
VTKM_CONT_EXPORT PortalControl GetPortalControl()
@ -359,11 +385,14 @@ public:
/// Copies data into the given iterator for the control environment. This
/// method can skip copying into an internally managed control array.
///
template <class IteratorType, class DeviceAdapterTag>
template<typename IteratorType, typename DeviceAdapterTag>
VTKM_CONT_EXPORT void CopyInto(IteratorType dest, DeviceAdapterTag) const
{
BOOST_CONCEPT_ASSERT((boost::OutputIterator<IteratorType, ValueType>));
BOOST_CONCEPT_ASSERT((boost::ForwardIterator<IteratorType>));
using pointer_type = typename std::iterator_traits<IteratorType>::pointer;
using value_type = typename std::remove_pointer<pointer_type>::type;
static_assert( !std::is_const<value_type>::value,
"CopyInto requires a non const iterator." );
VTKM_IS_DEVICE_ADAPTER_TAG(DeviceAdapterTag);
@ -597,14 +626,14 @@ public:
StorageType ControlArray;
bool ControlArrayValid;
boost::scoped_ptr<
std::unique_ptr<
vtkm::cont::internal::ArrayHandleExecutionManagerBase<
ValueType,StorageTag> > ExecutionArray;
bool ExecutionArrayValid;
};
VTKM_CONT_EXPORT
ArrayHandle(const boost::shared_ptr<InternalStruct>& i)
ArrayHandle(const std::shared_ptr<InternalStruct>& i)
: Internals(i)
{ }
@ -617,7 +646,7 @@ public:
VTKM_CONT_EXPORT
void PrepareForDevice(DeviceAdapterTag) const
{
if (this->Internals->ExecutionArray != NULL)
if (this->Internals->ExecutionArray != nullptr)
{
if (this->Internals->ExecutionArray->IsDeviceAdapter(DeviceAdapterTag()))
{
@ -642,7 +671,7 @@ public:
}
}
VTKM_ASSERT(this->Internals->ExecutionArray == NULL);
VTKM_ASSERT(this->Internals->ExecutionArray == nullptr);
VTKM_ASSERT(!this->Internals->ExecutionArrayValid);
// Need to change some state that does not change the logical state from
// an external point of view.
@ -693,7 +722,7 @@ public:
}
}
boost::shared_ptr<InternalStruct> Internals;
std::shared_ptr<InternalStruct> Internals;
};
/// A convenience function for creating an ArrayHandle from a standard C array.

@ -26,6 +26,7 @@
#include <vtkm/cont/ErrorControlBadAllocation.h>
namespace vtkm {
namespace exec {
namespace internal {
/// \brief An array portal that acts as a 3D cartesian product of 3 arrays.
@ -140,7 +141,8 @@ private:
};
}
} // namespace vtkm::internal
}
} // namespace vtkm::exec::internal
namespace vtkm {
@ -180,11 +182,11 @@ class Storage<T, StorageTagCartesianProduct<FirstHandleType, SecondHandleType, T
public:
typedef T ValueType;
typedef vtkm::internal::ArrayPortalCartesianProduct< ValueType,
typedef vtkm::exec::internal::ArrayPortalCartesianProduct< ValueType,
typename FirstHandleType::PortalControl,
typename SecondHandleType::PortalControl,
typename ThirdHandleType::PortalControl> PortalType;
typedef vtkm::internal::ArrayPortalCartesianProduct< ValueType,
typedef vtkm::exec::internal::ArrayPortalCartesianProduct< ValueType,
typename FirstHandleType::PortalConstControl,
typename SecondHandleType::PortalConstControl,
typename ThirdHandleType::PortalConstControl>
@ -284,14 +286,14 @@ public:
typedef typename StorageType::PortalType PortalControl;
typedef typename StorageType::PortalConstType PortalConstControl;
typedef vtkm::internal::ArrayPortalCartesianProduct<
typedef vtkm::exec::internal::ArrayPortalCartesianProduct<
ValueType,
typename FirstHandleType::template ExecutionTypes<Device>::Portal,
typename SecondHandleType::template ExecutionTypes<Device>::Portal,
typename ThirdHandleType::template ExecutionTypes<Device>::Portal
> PortalExecution;
typedef vtkm::internal::ArrayPortalCartesianProduct<
typedef vtkm::exec::internal::ArrayPortalCartesianProduct<
ValueType,
typename FirstHandleType::template ExecutionTypes<Device>::PortalConst,
typename SecondHandleType::template ExecutionTypes<Device>::PortalConst,

@ -0,0 +1,326 @@
//=============================================================================
//
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2015 Sandia Corporation.
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//
//=============================================================================
#ifndef vtk_m_ArrayHandleConcatenate_h
#define vtk_m_ArrayHandleConcatenate_h
#include <vtkm/cont/ArrayHandle.h>
namespace vtkm {
namespace cont {
namespace internal {
template< typename PortalType1, typename PortalType2 >
class ArrayPortalConcatenate
{
public:
typedef typename PortalType1::ValueType ValueType;
VTKM_EXEC_CONT_EXPORT
ArrayPortalConcatenate() : portal1(), portal2() {}
VTKM_EXEC_CONT_EXPORT
ArrayPortalConcatenate( const PortalType1 &p1, const PortalType2 &p2 )
: portal1( p1 ), portal2( p2 ) {}
// Copy constructor
template< typename OtherP1, typename OtherP2 >
VTKM_EXEC_CONT_EXPORT
ArrayPortalConcatenate( const ArrayPortalConcatenate< OtherP1, OtherP2 > &src )
: portal1( src.GetPortal1() ), portal2( src.GetPortal2() ) {}
VTKM_EXEC_CONT_EXPORT
vtkm::Id GetNumberOfValues() const
{
return this->portal1.GetNumberOfValues() +
this->portal2.GetNumberOfValues() ;
}
VTKM_EXEC_CONT_EXPORT
ValueType Get( vtkm::Id index) const
{
if( index < this->portal1.GetNumberOfValues() )
return this->portal1.Get( index );
else
return this->portal2.Get( index - this->portal1.GetNumberOfValues() );
}
VTKM_EXEC_CONT_EXPORT
void Set( vtkm::Id index, const ValueType &value ) const
{
if( index < this->portal1.GetNumberOfValues() )
this->portal1.Set( index, value );
else
this->portal2.Set( index - this->portal1.GetNumberOfValues(), value );
}
VTKM_EXEC_CONT_EXPORT
const PortalType1 &GetPortal1() const
{
return this->portal1;
}
VTKM_EXEC_CONT_EXPORT
const PortalType2 &GetPortal2() const
{
return this->portal2;
}
private:
PortalType1 portal1;
PortalType2 portal2;
}; // class ArrayPortalConcatenate
} // namespace internal
template< typename ArrayHandleType1, typename ArrayHandleType2 >
class StorageTagConcatenate {};
namespace internal {
template< typename ArrayHandleType1, typename ArrayHandleType2 >
class Storage< typename ArrayHandleType1::ValueType,
StorageTagConcatenate< ArrayHandleType1, ArrayHandleType2> >
{
public:
typedef typename ArrayHandleType1::ValueType ValueType;
typedef ArrayPortalConcatenate< typename ArrayHandleType1::PortalControl,
typename ArrayHandleType2::PortalControl > PortalType;
typedef ArrayPortalConcatenate<
typename ArrayHandleType1::PortalConstControl,
typename ArrayHandleType2::PortalConstControl > PortalConstType;
VTKM_CONT_EXPORT
Storage() : valid( false ) { }
VTKM_CONT_EXPORT
Storage( const ArrayHandleType1 &a1, const ArrayHandleType2 &a2 )
: array1( a1 ), array2( a2 ), valid( true ) {};
VTKM_CONT_EXPORT
PortalConstType GetPortalConst() const
{
VTKM_ASSERT( this->valid );
return PortalConstType( this->array1.GetPortalConstControl(),
this->array2.GetPortalConstControl() );
}
VTKM_CONT_EXPORT
PortalType GetPortal()
{
VTKM_ASSERT( this->valid );
return PortalType( this->array1.GetPortalControl(),
this->array2.GetPortalControl() );
}
VTKM_CONT_EXPORT
vtkm::Id GetNumberOfValues() const
{
VTKM_ASSERT( this->valid );
return this->array1.GetNumberOfValues() + this->array2.GetNumberOfValues();
}
VTKM_CONT_EXPORT
void Allocate( vtkm::Id numberOfValues )
{
numberOfValues++; // dummy statement to avoid a warning
throw vtkm::cont::ErrorControlInternal(
"ArrayHandleConcatenate should not be allocated explicitly. " );
}
VTKM_CONT_EXPORT
void Shrink( vtkm::Id numberOfValues )
{
VTKM_ASSERT( this->valid );
if( numberOfValues < this->array1.GetNumberOfValues() )
{
this->array1.Shrink( numberOfValues );
this->array2.Shrink( 0 );
}
else
this->array2.Shrink( numberOfValues - this->array1.GetNumberOfValues() );
}
VTKM_CONT_EXPORT
void ReleaseResources( )
{
VTKM_ASSERT( this->valid );
this->array1.ReleaseResources();
this->array2.ReleaseResources();
}
VTKM_CONT_EXPORT
const ArrayHandleType1 &GetArray1() const
{
VTKM_ASSERT( this->valid );
return this->array1;
}
VTKM_CONT_EXPORT
const ArrayHandleType2 &GetArray2() const
{
VTKM_ASSERT( this->valid );
return this->array2;
}
private:
ArrayHandleType1 array1;
ArrayHandleType2 array2;
bool valid;
}; // class Storage
template< typename ArrayHandleType1, typename ArrayHandleType2, typename Device >
class ArrayTransfer< typename ArrayHandleType1::ValueType,
StorageTagConcatenate< ArrayHandleType1, ArrayHandleType2>,
Device >
{
public:
typedef typename ArrayHandleType1::ValueType ValueType;
private:
typedef StorageTagConcatenate< ArrayHandleType1, ArrayHandleType2 > StorageTag;
typedef vtkm::cont::internal::Storage< ValueType, StorageTag> StorageType;
public:
typedef typename StorageType::PortalType PortalControl;
typedef typename StorageType::PortalConstType PortalConstControl;
typedef ArrayPortalConcatenate<
typename ArrayHandleType1::template ExecutionTypes< Device >::Portal,
typename ArrayHandleType2::template ExecutionTypes< Device >::Portal >
PortalExecution;
typedef ArrayPortalConcatenate<
typename ArrayHandleType1::template ExecutionTypes< Device >::PortalConst,
typename ArrayHandleType2::template ExecutionTypes< Device >::PortalConst >
PortalConstExecution;
VTKM_CONT_EXPORT
ArrayTransfer( StorageType* storage )
: array1( storage->GetArray1() ), array2( storage->GetArray2() ) {}
VTKM_CONT_EXPORT
vtkm::Id GetNumberOfValues() const
{
return this->array1.GetNumberOfValues() + this->array2.GetNumberOfValues() ;
}
VTKM_CONT_EXPORT
PortalConstExecution PrepareForInput( bool vtkmNotUsed( updateData ) )
{
return PortalConstExecution( this->array1.PrepareForInput( Device() ),
this->array2.PrepareForInput( Device() ));
}
VTKM_CONT_EXPORT
PortalExecution PrepareForInPlace( bool vtkmNotUsed( updateData ) )
{
return PortalExecution( this->array1.PrepareForInPlace( Device() ),
this->array2.PrepareForInPlace( Device() ));
}
VTKM_CONT_EXPORT
PortalExecution PrepareForOutput( vtkm::Id numberOfValues )
{
numberOfValues++; // dummy statement to avoid a warning
throw vtkm::cont::ErrorControlInternal(
"ArrayHandleConcatenate is derived and read-only. " );
}
VTKM_CONT_EXPORT
void RetrieveOutputData( StorageType* vtkmNotUsed(storage) ) const
{
// not need to implement
}
VTKM_CONT_EXPORT
void Shrink( vtkm::Id numberOfValues )
{
if( numberOfValues < this->array1.GetNumberOfValues() )
{
this->array1.Shrink( numberOfValues );
this->array2.Shrink( 0 );
}
else
this->array2.Shrink( numberOfValues - this->array1.GetNumberOfValues() );
}
VTKM_CONT_EXPORT
void ReleaseResources()
{
this->array1.ReleaseResourcesExecution();
this->array2.ReleaseResourcesExecution();
}
private:
ArrayHandleType1 array1;
ArrayHandleType2 array2;
};
}
}
} // namespace vtkm::cont::internal
namespace vtkm {
namespace cont {
template< typename ArrayHandleType1, typename ArrayHandleType2 >
class ArrayHandleConcatenate
: public vtkm::cont::ArrayHandle< typename ArrayHandleType1::ValueType,
StorageTagConcatenate< ArrayHandleType1, ArrayHandleType2> >
{
public:
VTKM_ARRAY_HANDLE_SUBCLASS( ArrayHandleConcatenate,
( ArrayHandleConcatenate< ArrayHandleType1, ArrayHandleType2> ),
( vtkm::cont::ArrayHandle< typename ArrayHandleType1::ValueType,
StorageTagConcatenate< ArrayHandleType1, ArrayHandleType2 > > ));
private:
typedef vtkm::cont::internal::Storage< ValueType, StorageTag > StorageType;
public:
VTKM_CONT_EXPORT
ArrayHandleConcatenate( const ArrayHandleType1 &array1,
const ArrayHandleType2 &array2 )
: Superclass( StorageType( array1, array2 ) )
{}
};
template< typename ArrayHandleType1, typename ArrayHandleType2 >
VTKM_CONT_EXPORT
ArrayHandleConcatenate< ArrayHandleType1, ArrayHandleType2 >
make_ArrayHandleConcatenate( const ArrayHandleType1 &array1,
const ArrayHandleType2 &array2 )
{
return ArrayHandleConcatenate< ArrayHandleType1, ArrayHandleType2 >( array1, array2 );
}
}
} // namespace vtkm::cont
#endif //vtk_m_ArrayHandleConcatenate_h

@ -24,12 +24,8 @@
#include <vtkm/cont/ArrayPortal.h>
#include <vtkm/cont/ErrorControlBadValue.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/type_traits/remove_const.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
namespace vtkm {
namespace cont {
namespace exec {
namespace internal {
@ -41,7 +37,7 @@ public:
typedef _SourcePortalType SourcePortalType;
typedef typename
boost::remove_const<typename SourcePortalType::ValueType>::type
std::remove_const<typename SourcePortalType::ValueType>::type
ComponentType;
typedef vtkm::Vec<ComponentType, NUM_COMPONENTS> ValueType;
@ -109,6 +105,15 @@ private:
SourcePortalType SourcePortal;
};
}
}
} // namespace vtkm::exec::internal
namespace vtkm {
namespace cont {
namespace internal {
template<typename SourceArrayHandleType, vtkm::IdComponent NUM_COMPONENTS>
struct StorageTagGroupVec { };
@ -124,10 +129,10 @@ class Storage<
public:
typedef vtkm::Vec<ComponentType,NUM_COMPONENTS> ValueType;
typedef vtkm::cont::internal::ArrayPortalGroupVec<
typedef vtkm::exec::internal::ArrayPortalGroupVec<
typename SourceArrayHandleType::PortalControl,
NUM_COMPONENTS> PortalType;
typedef vtkm::cont::internal::ArrayPortalGroupVec<
typedef vtkm::exec::internal::ArrayPortalGroupVec<
typename SourceArrayHandleType::PortalConstControl,
NUM_COMPONENTS> PortalConstType;
@ -223,11 +228,11 @@ public:
typedef typename StorageType::PortalType PortalControl;
typedef typename StorageType::PortalConstType PortalConstControl;
typedef vtkm::cont::internal::ArrayPortalGroupVec<
typedef vtkm::exec::internal::ArrayPortalGroupVec<
typename SourceArrayHandleType::template ExecutionTypes<Device>::Portal,
NUM_COMPONENTS>
PortalExecution;
typedef vtkm::cont::internal::ArrayPortalGroupVec<
typedef vtkm::exec::internal::ArrayPortalGroupVec<
typename SourceArrayHandleType::template ExecutionTypes<Device>::PortalConst,
NUM_COMPONENTS>
PortalConstExecution;

@ -31,18 +31,19 @@ namespace exec {
namespace internal {
template<typename IndexPortalType, typename ValuePortalType>
class ArrayPortalPermutationExec
class ArrayPortalPermutation
{
public:
typedef typename ValuePortalType::ValueType ValueType;
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
ArrayPortalPermutationExec( )
ArrayPortalPermutation( )
: IndexPortal(), ValuePortal() { }
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
ArrayPortalPermutationExec(
ArrayPortalPermutation(
const IndexPortalType &indexPortal,
const ValuePortalType &valuePortal)
: IndexPortal(indexPortal), ValuePortal(valuePortal) { }
@ -53,12 +54,14 @@ public:
/// const cast).
///
template<typename OtherIP, typename OtherVP>
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
ArrayPortalPermutationExec(
const ArrayPortalPermutationExec<OtherIP,OtherVP> &src)
ArrayPortalPermutation(
const ArrayPortalPermutation<OtherIP,OtherVP> &src)
: IndexPortal(src.GetIndexPortal()), ValuePortal(src.GetValuePortal())
{ }
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
vtkm::Id GetNumberOfValues() const {
return this->IndexPortal.GetNumberOfValues();
@ -78,9 +81,11 @@ public:
this->ValuePortal.Set(permutedIndex, value);
}
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
const IndexPortalType &GetIndexPortal() const { return this->IndexPortal; }
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
const ValuePortalType &GetValuePortal() const { return this->ValuePortal; }
@ -98,66 +103,6 @@ namespace cont {
namespace internal {
template<typename IndexPortalType, typename ValuePortalType>
class ArrayPortalPermutationCont
{
public:
typedef typename ValuePortalType::ValueType ValueType;
VTKM_CONT_EXPORT
ArrayPortalPermutationCont( )
: IndexPortal(), ValuePortal() { }
VTKM_CONT_EXPORT
ArrayPortalPermutationCont(
const IndexPortalType &indexPortal,
const ValuePortalType &valuePortal)
: IndexPortal(indexPortal), ValuePortal(valuePortal) { }
/// Copy constructor for any other ArrayPortalPermutation with delegate
/// portal types that can be copied to these portal types. This allows us to
/// do any type casting that the delegate portals do (like the non-const to
/// const cast).
///
template<typename OtherIP, typename OtherVP>
VTKM_CONT_EXPORT
ArrayPortalPermutationCont(
const ArrayPortalPermutationCont<OtherIP,OtherVP> &src)
: IndexPortal(src.GetIndexPortal()), ValuePortal(src.GetValuePortal())
{ }
VTKM_CONT_EXPORT
vtkm::Id GetNumberOfValues() const {
return this->IndexPortal.GetNumberOfValues();
}
VTKM_CONT_EXPORT
ValueType Get(vtkm::Id index) const {
vtkm::Id permutedIndex = this->IndexPortal.Get(index);
VTKM_ASSERT(permutedIndex >= 0);
VTKM_ASSERT(permutedIndex < this->ValuePortal.GetNumberOfValues());
return this->ValuePortal.Get(permutedIndex);
}
VTKM_CONT_EXPORT
ValueType Set(vtkm::Id index, const ValueType &value) const {
vtkm::Id permutedIndex = this->IndexPortal.Get(index);
VTKM_ASSERT(permutedIndex >= 0);
VTKM_ASSERT(permutedIndex < this->ValuePortal.GetNumberOfValues());
return this->ValuePortal.Set(permutedIndex, value);
}
VTKM_CONT_EXPORT
const IndexPortalType &GetIndexPortal() const { return this->IndexPortal; }
VTKM_CONT_EXPORT
const ValuePortalType &GetValuePortal() const { return this->ValuePortal; }
private:
IndexPortalType IndexPortal;
ValuePortalType ValuePortal;
};
template<typename IndexArrayType, typename ValueArrayType>
struct StorageTagPermutation { };
@ -172,10 +117,10 @@ class Storage<
public:
typedef typename ValueArrayType::ValueType ValueType;
typedef ArrayPortalPermutationCont<
typedef vtkm::exec::internal::ArrayPortalPermutation<
typename IndexArrayType::PortalConstControl,
typename ValueArrayType::PortalControl> PortalType;
typedef ArrayPortalPermutationCont<
typedef vtkm::exec::internal::ArrayPortalPermutation<
typename IndexArrayType::PortalConstControl,
typename ValueArrayType::PortalConstControl> PortalConstType;
@ -254,11 +199,11 @@ public:
typedef typename StorageType::PortalType PortalControl;
typedef typename StorageType::PortalConstType PortalConstControl;
typedef vtkm::exec::internal::ArrayPortalPermutationExec<
typedef vtkm::exec::internal::ArrayPortalPermutation<
typename IndexArrayType::template ExecutionTypes<Device>::PortalConst,
typename ValueArrayType::template ExecutionTypes<Device>::Portal>
PortalExecution;
typedef vtkm::exec::internal::ArrayPortalPermutationExec<
typedef vtkm::exec::internal::ArrayPortalPermutation<
typename IndexArrayType::template ExecutionTypes<Device>::PortalConst,
typename ValueArrayType::template ExecutionTypes<Device>::PortalConst>
PortalConstExecution;

@ -47,46 +47,52 @@ typedef vtkm::cont::internal::NullFunctorType NullFunctorType;
///
template<typename ValueType_, typename PortalType_, typename FunctorType_,
typename InverseFunctorType_=NullFunctorType>
class ArrayPortalExecTransform;
class ArrayPortalTransform;
template<typename ValueType_, typename PortalType_, typename FunctorType_>
class ArrayPortalExecTransform<ValueType_,PortalType_,FunctorType_,NullFunctorType>
class ArrayPortalTransform<ValueType_,PortalType_,FunctorType_,NullFunctorType>
{
public:
typedef PortalType_ PortalType;
typedef ValueType_ ValueType;
typedef FunctorType_ FunctorType;
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
ArrayPortalExecTransform(const PortalType &portal = PortalType(),
ArrayPortalTransform(const PortalType &portal = PortalType(),
const FunctorType &functor = FunctorType())
: Portal(portal), Functor(functor)
{ }
/// Copy constructor for any other ArrayPortalExecTransform with an iterator
/// Copy constructor for any other ArrayPortalTransform with an iterator
/// type that can be copied to this iterator type. This allows us to do any
/// type casting that the iterators do (like the non-const to const cast).
///
template<class OtherV, class OtherP, class OtherF>
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
ArrayPortalExecTransform(const ArrayPortalExecTransform<OtherV,OtherP,OtherF> &src)
ArrayPortalTransform(const ArrayPortalTransform<OtherV,OtherP,OtherF> &src)
: Portal(src.GetPortal()),
Functor(src.GetFunctor())
{ }
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
vtkm::Id GetNumberOfValues() const {
return this->Portal.GetNumberOfValues();
}
VTKM_EXEC_EXPORT
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
ValueType Get(vtkm::Id index) const {
return this->Functor(this->Portal.Get(index));
}
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
const PortalType &GetPortal() const { return this->Portal; }
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
const FunctorType &GetFunctor() const { return this->Functor; }
@ -97,33 +103,37 @@ protected:
template<typename ValueType_, typename PortalType_,
typename FunctorType_, typename InverseFunctorType_>
class ArrayPortalExecTransform : public ArrayPortalExecTransform<ValueType_,PortalType_,FunctorType_,NullFunctorType>
class ArrayPortalTransform : public ArrayPortalTransform<ValueType_,PortalType_,FunctorType_,NullFunctorType>
{
public:
typedef ArrayPortalExecTransform<ValueType_,PortalType_,FunctorType_,NullFunctorType> Superclass;
typedef ArrayPortalTransform<ValueType_,PortalType_,FunctorType_,NullFunctorType> Superclass;
typedef PortalType_ PortalType;
typedef ValueType_ ValueType;
typedef FunctorType_ FunctorType;
typedef InverseFunctorType_ InverseFunctorType;
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
ArrayPortalExecTransform(const PortalType &portal = PortalType(),
const FunctorType &functor = FunctorType(),
ArrayPortalTransform(const PortalType &portal = PortalType(),
const FunctorType &functor = FunctorType(),
const InverseFunctorType& inverseFunctor = InverseFunctorType())
: Superclass(portal,functor), InverseFunctor(inverseFunctor)
{ }
template<class OtherV, class OtherP, class OtherF, class OtherInvF>
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
ArrayPortalExecTransform(const ArrayPortalExecTransform<OtherV,OtherP,OtherF,OtherInvF> &src)
ArrayPortalTransform(const ArrayPortalTransform<OtherV,OtherP,OtherF,OtherInvF> &src)
: Superclass(src), InverseFunctor(src.GetInverseFunctor())
{ }
VTKM_EXEC_EXPORT
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
void Set(vtkm::Id index, const ValueType& value) const {
return this->Portal.Set(index,this->InverseFunctor(value));
}
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
const InverseFunctorType &GetInverseFunctor() const {
return this->InverseFunctor; }
@ -143,94 +153,6 @@ namespace cont {
namespace internal {
/// \brief An array portal that transforms a value from another portal.
///
template<typename ValueType_, typename PortalType_, typename FunctorType_,
typename InverseFunctorType=NullFunctorType>
class ArrayPortalContTransform;
template<typename ValueType_, typename PortalType_, typename FunctorType_>
class ArrayPortalContTransform<ValueType_,PortalType_,FunctorType_,NullFunctorType>
{
public:
typedef PortalType_ PortalType;
typedef ValueType_ ValueType;
typedef FunctorType_ FunctorType;
VTKM_CONT_EXPORT
ArrayPortalContTransform(const PortalType &portal = PortalType(),
const FunctorType &functor = FunctorType())
: Portal(portal), Functor(functor)
{ }
/// Copy constructor for any other ArrayPortalContTransform with an iterator
/// type that can be copied to this iterator type. This allows us to do any
/// type casting that the iterators do (like the non-const to const cast).
///
template<class OtherV, class OtherP, class OtherF>
VTKM_CONT_EXPORT
ArrayPortalContTransform(const ArrayPortalContTransform<OtherV,OtherP,OtherF> &src)
: Portal(src.GetPortal()),
Functor(src.GetFunctor())
{ }
VTKM_CONT_EXPORT
vtkm::Id GetNumberOfValues() const {
return this->Portal.GetNumberOfValues();
}
VTKM_CONT_EXPORT
ValueType Get(vtkm::Id index) const {
return this->Functor(this->Portal.Get(index));
}
VTKM_CONT_EXPORT
const PortalType &GetPortal() const { return this->Portal; }
VTKM_CONT_EXPORT
const FunctorType &GetFunctor() const { return this->Functor; }
protected:
PortalType Portal;
FunctorType Functor;
};
template<typename ValueType_, typename PortalType_, typename FunctorType_,
typename InverseFunctorType_>
class ArrayPortalContTransform : public ArrayPortalContTransform<ValueType_,PortalType_,FunctorType_,NullFunctorType>
{
public:
typedef ArrayPortalContTransform<ValueType_,PortalType_,FunctorType_,NullFunctorType> Superclass;
typedef PortalType_ PortalType;
typedef ValueType_ ValueType;
typedef FunctorType_ FunctorType;
typedef InverseFunctorType_ InverseFunctorType;
VTKM_CONT_EXPORT
ArrayPortalContTransform(const PortalType &portal = PortalType(),
const FunctorType &functor = FunctorType(),
const InverseFunctorType &inverseFunctor = InverseFunctorType())
: Superclass(portal,functor), InverseFunctor(inverseFunctor)
{ }
template<class OtherV, class OtherP, class OtherF, class OtherInvF>
VTKM_CONT_EXPORT
ArrayPortalContTransform(const ArrayPortalContTransform<OtherV,OtherP,OtherF,OtherInvF> &src)
: Superclass(src), InverseFunctor(src.GetInverseFunctor())
{ }
VTKM_CONT_EXPORT
void Set(vtkm::Id index, const ValueType& value) const {
this->Portal.Set(index,this->InverseFunctor(value));
}
VTKM_CONT_EXPORT
const InverseFunctorType &GetInverseFunctor() const { return this->InverseFunctor; }
private:
InverseFunctorType InverseFunctor;
};
template<typename ValueType, typename ArrayHandleType, typename FunctorType,
typename InverseFunctorType=NullFunctorType>
struct StorageTagTransform {};
@ -249,7 +171,7 @@ public:
typedef void *IteratorType;
};
typedef ArrayPortalContTransform<
typedef vtkm::exec::internal::ArrayPortalTransform<
ValueType, typename ArrayHandleType::PortalConstControl, FunctorType>
PortalConstType;
@ -325,10 +247,10 @@ class Storage<T,
public:
typedef T ValueType;
typedef ArrayPortalContTransform<ValueType,
typedef vtkm::exec::internal::ArrayPortalTransform<ValueType,
typename ArrayHandleType::PortalControl, FunctorType, InverseFunctorType>
PortalType;
typedef ArrayPortalContTransform<ValueType,
typedef vtkm::exec::internal::ArrayPortalTransform<ValueType,
typename ArrayHandleType::PortalConstControl,FunctorType,InverseFunctorType>
PortalConstType;
@ -421,7 +343,7 @@ public:
//meant to be an invalid writeable execution portal
typedef typename StorageType::PortalType PortalExecution;
typedef vtkm::exec::internal::ArrayPortalExecTransform<
typedef vtkm::exec::internal::ArrayPortalTransform<
ValueType,
typename ArrayHandleType::template ExecutionTypes<Device>::PortalConst,
FunctorType> PortalConstExecution;
@ -496,11 +418,11 @@ public:
typedef typename StorageType::PortalType PortalControl;
typedef typename StorageType::PortalConstType PortalConstControl;
typedef vtkm::exec::internal::ArrayPortalExecTransform<
typedef vtkm::exec::internal::ArrayPortalTransform<
ValueType,
typename ArrayHandleType::template ExecutionTypes<Device>::Portal,
FunctorType, InverseFunctorType> PortalExecution;
typedef vtkm::exec::internal::ArrayPortalExecTransform<
typedef vtkm::exec::internal::ArrayPortalTransform<
ValueType,
typename ArrayHandleType::template ExecutionTypes<Device>::PortalConst,
FunctorType, InverseFunctorType> PortalConstExecution;

@ -32,7 +32,7 @@ namespace internal {
template<typename ValueType_,
typename PortalTypeFirst_,
typename PortalTypeSecond_>
class ArrayPortalExecZip
class ArrayPortalZip
{
public:
typedef ValueType_ ValueType;
@ -42,23 +42,23 @@ public:
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
ArrayPortalExecZip()
ArrayPortalZip()
: PortalFirst(), PortalSecond()
{ } //needs to be host and device so that cuda can create lvalue of these
VTKM_CONT_EXPORT
ArrayPortalExecZip(const PortalTypeFirst &portalfirst,
const PortalTypeSecond &portalsecond)
ArrayPortalZip(const PortalTypeFirst &portalfirst,
const PortalTypeSecond &portalsecond)
: PortalFirst(portalfirst), PortalSecond(portalsecond)
{ }
/// Copy constructor for any other ArrayPortalExecZip with an iterator
/// Copy constructor for any other ArrayPortalZip with an iterator
/// type that can be copied to this iterator type. This allows us to do any
/// type casting that the iterators do (like the non-const to const cast).
///
template<class OtherV, class OtherF, class OtherS>
VTKM_CONT_EXPORT
ArrayPortalExecZip(const ArrayPortalExecZip<OtherV,OtherF,OtherS> &src)
ArrayPortalZip(const ArrayPortalZip<OtherV,OtherF,OtherS> &src)
: PortalFirst(src.GetFirstPortal()),
PortalSecond(src.GetSecondPortal())
{ }
@ -100,61 +100,6 @@ namespace cont {
namespace internal {
/// \brief An array portal that zips two portals together into a single value
/// for the control environment
template<typename ValueType_,
typename PortalTypeFirst,
typename PortalTypeSecond>
class ArrayPortalContZip
{
public:
typedef ValueType_ ValueType;
typedef ValueType_ IteratorType;
VTKM_CONT_EXPORT
ArrayPortalContZip(const PortalTypeFirst &portalfirst = PortalTypeFirst(),
const PortalTypeSecond &portalsecond = PortalTypeSecond())
: PortalFirst(portalfirst), PortalSecond(portalsecond)
{ }
/// Copy constructor for any other ArrayPortalContZip with an iterator
/// type that can be copied to this iterator type. This allows us to do any
/// type casting that the iterators do (like the non-const to const cast).
///
template<class OtherV, class OtherF, class OtherS>
VTKM_CONT_EXPORT
ArrayPortalContZip(const ArrayPortalContZip<OtherV,OtherF,OtherS> &src)
: PortalFirst(src.GetFirstPortal()),
PortalSecond(src.GetSecondPortal())
{ }
VTKM_CONT_EXPORT
vtkm::Id GetNumberOfValues() const { return this->PortalFirst.GetNumberOfValues(); }
VTKM_CONT_EXPORT
ValueType Get(vtkm::Id index) const {
return vtkm::make_Pair(this->PortalFirst.Get(index),
this->PortalSecond.Get(index));
}
VTKM_CONT_EXPORT
void Set(vtkm::Id index, const ValueType &value) const {
this->PortalFirst.Set(index, value.first);
this->PortalSecond.Set(index, value.second);
}
VTKM_CONT_EXPORT
const PortalTypeFirst &GetFirstPortal() const { return this->PortalFirst; }
VTKM_CONT_EXPORT
const PortalTypeSecond &GetSecondPortal() const { return this->PortalSecond; }
private:
PortalTypeFirst PortalFirst;
PortalTypeSecond PortalSecond;
};
template<typename FirstHandleType, typename SecondHandleType>
struct StorageTagZip { };
@ -187,10 +132,10 @@ class Storage<T, StorageTagZip<FirstHandleType, SecondHandleType > >
public:
typedef T ValueType;
typedef ArrayPortalContZip< ValueType,
typedef vtkm::exec::internal::ArrayPortalZip< ValueType,
typename FirstHandleType::PortalControl,
typename SecondHandleType::PortalControl> PortalType;
typedef ArrayPortalContZip< ValueType,
typedef vtkm::exec::internal::ArrayPortalZip< ValueType,
typename FirstHandleType::PortalConstControl,
typename SecondHandleType::PortalConstControl>
PortalConstType;
@ -273,13 +218,13 @@ public:
typedef typename StorageType::PortalType PortalControl;
typedef typename StorageType::PortalConstType PortalConstControl;
typedef vtkm::exec::internal::ArrayPortalExecZip<
typedef vtkm::exec::internal::ArrayPortalZip<
ValueType,
typename FirstHandleType::template ExecutionTypes<Device>::Portal,
typename SecondHandleType::template ExecutionTypes<Device>::Portal
> PortalExecution;
typedef vtkm::exec::internal::ArrayPortalExecZip<
typedef vtkm::exec::internal::ArrayPortalZip<
ValueType,
typename FirstHandleType::template ExecutionTypes<Device>::PortalConst,
typename SecondHandleType::template ExecutionTypes<Device>::PortalConst

@ -50,9 +50,8 @@ namespace cont {
/// ArrayPortal objects. It is mostly an internal mechanism. However, an
/// ArrayPortal can be used to pass constant input data to an ArrayHandle.
///
/// Although this documentation is given for the control environment, there are
/// instances of an identical concept in the execution environment, although
/// some features are missing there.
/// Although portals are defined in the execution environment, they are also
/// used in the control environment for accessing data on the host.
///
template<typename T>
class ArrayPortal

@ -37,6 +37,7 @@ set(headers
ArrayHandleZip.h
ArrayPortal.h
ArrayPortalToIterators.h
ArrayHandleConcatenate.h
CellSet.h
CellSetExplicit.h
CellSetListTag.h
@ -51,6 +52,7 @@ set(headers
DataSetFieldAdd.h
DeviceAdapter.h
DeviceAdapterAlgorithm.h
DeviceAdapterListTag.h
DeviceAdapterSerial.h
DynamicArrayHandle.h
DynamicCellSet.h
@ -69,6 +71,7 @@ set(headers
StorageImplicit.h
StorageListTag.h
Timer.h
TryExecute.h
)
#-----------------------------------------------------------------------------

@ -28,10 +28,6 @@
#include <vtkm/cont/DynamicArrayHandle.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/type_traits/is_base_of.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
namespace vtkm {
namespace cont {
@ -90,16 +86,15 @@ protected:
namespace internal {
/// Checks to see if the given object is a cell set. This check is compatible
/// with the Boost meta-template programming library (MPL). It contains a
/// typedef named \c type that is either boost::mpl::true_ or
/// boost::mpl::false_. Both of these have a typedef named value with the
/// Checks to see if the given object is a cell set. It contains a
/// typedef named \c type that is either std::true_type or
/// std::false_type. Both of these have a typedef named value with the
/// respective boolean value.
///
template<typename T>
struct CellSetCheck
{
typedef typename boost::is_base_of<vtkm::cont::CellSet, T>::type type;
using type = typename std::is_base_of<vtkm::cont::CellSet, T>;
};
#define VTKM_IS_CELL_SET(T) \

@ -207,11 +207,11 @@ public:
this->ConnectivityLength = 0;
}
template <vtkm::IdComponent ItemTupleLength>
template <typename IndexableType>
VTKM_CONT_EXPORT
void AddCell(vtkm::UInt8 cellType,
vtkm::IdComponent numVertices,
const vtkm::Vec<vtkm::Id,ItemTupleLength> &ids)
const IndexableType &ids)
{
this->PointToCell.Shapes.GetPortalControl().Set(this->NumberOfCells, cellType);
this->PointToCell.NumIndices.GetPortalControl().Set(this->NumberOfCells, numVertices);

@ -83,6 +83,9 @@ class CoordinateSystem : public vtkm::cont::Field
typedef vtkm::cont::Field Superclass;
public:
VTKM_CONT_EXPORT
CoordinateSystem() : Superclass() { }
VTKM_CONT_EXPORT
CoordinateSystem(std::string name,
const vtkm::cont::DynamicArrayHandle &data)
@ -255,10 +258,23 @@ public:
}
};
template<typename Functor>
void CastAndCall(const vtkm::cont::CoordinateSystem& coords, const Functor &f)
{
coords.GetData().CastAndCall(f);
}
namespace internal {
template<>
struct DynamicTransformTraits<vtkm::cont::CoordinateSystem>
{
typedef vtkm::cont::internal::DynamicTransformTagCastAndCall DynamicTag;
};
} // namespace internal
} // namespace cont
} // namespace vtkm
#endif //vtk_m_cont_CoordinateSystem_h

@ -227,7 +227,7 @@ public:
out<<" CellSets["<<this->GetNumberOfCellSets()<<"]\n";
for (vtkm::Id index = 0; index < this->GetNumberOfCellSets(); index++)
{
this->GetCellSet(index).GetCellSet().PrintSummary(out);
this->GetCellSet(index).PrintSummary(out);
}
out<<" Fields["<<this->GetNumberOfFields()<<"]\n";
@ -281,7 +281,7 @@ private:
{
for (std::size_t index=0; index < static_cast<size_t>(this->GetNumberOfCellSets()); ++index)
{
if (this->CellSets[index].GetCellSet().GetName() == name)
if (this->CellSets[index].GetName() == name)
{
found = true;
return static_cast<vtkm::Id>(index);

@ -133,7 +133,7 @@ public:
vtkm::Id cellSetIndex = 0)
{
std::string cellSetName =
dataSet.GetCellSet(cellSetIndex).GetCellSet().GetName();
dataSet.GetCellSet(cellSetIndex).GetName();
DataSetFieldAdd::AddCellField(dataSet, fieldName, field, cellSetName);
}
template <typename T, typename Storage>
@ -145,7 +145,7 @@ public:
vtkm::Id cellSetIndex = 0)
{
std::string cellSetName =
dataSet.GetCellSet(cellSetIndex).GetCellSet().GetName();
dataSet.GetCellSet(cellSetIndex).GetName();
DataSetFieldAdd::AddCellField(dataSet, fieldName, field, cellSetName);
}
template<typename T>
@ -157,7 +157,7 @@ public:
vtkm::Id cellSetIndex = 0)
{
std::string cellSetName =
dataSet.GetCellSet(cellSetIndex).GetCellSet().GetName();
dataSet.GetCellSet(cellSetIndex).GetName();
DataSetFieldAdd::AddCellField(dataSet, fieldName, field, cellSetName);
}
@ -170,7 +170,7 @@ public:
vtkm::Id cellSetIndex = 0)
{
std::string cellSetName =
dataSet.GetCellSet(cellSetIndex).GetCellSet().GetName();
dataSet.GetCellSet(cellSetIndex).GetName();
DataSetFieldAdd::AddCellField(dataSet, fieldName, field, n, cellSetName);
}

@ -50,13 +50,38 @@ struct DeviceAdapterAlgorithm
{
/// \brief Copy the contents of one ArrayHandle to another
///
/// Copies the contents of \c input to \c output. The array \c to will be
/// allocated to the appropriate size.
/// Copies the contents of \c input to \c output. The array \c output will be
/// allocated to the same size of \c input. If output has already been
/// allocated we will reallocate and clear any current values.
///
template<typename T, typename U, class CIn, class COut>
VTKM_CONT_EXPORT static void Copy(const vtkm::cont::ArrayHandle<T,CIn> &input,
vtkm::cont::ArrayHandle<U, COut> &output);
/// \brief Copy the contents of a section of one ArrayHandle to another
///
/// Copies the a range of elements of \c input to \c output. The number of
/// elements is determined by \c numberOfElementsToCopy, and initial start
/// position is determined by \c inputStartIndex. You can control where
/// in the destination the copy should occur by specifying the \c outputIndex
///
/// If inputStartIndex + numberOfElementsToCopy is greater than the length
/// of \c input we will only copy until we reach the end of the input array
///
/// If the \c outputIndex + numberOfElementsToCopy is greater than the
/// length of \c output we will reallocate the output array so it can
/// fit the number of elements we desire.
///
/// \par Requirements:
/// \arg \c input must already be sorted
///
template<typename T, typename U, class CIn, class COut>
VTKM_CONT_EXPORT static bool CopySubRange(const vtkm::cont::ArrayHandle<T,CIn> &input,
vtkm::Id inputStartIndex,
vtkm::Id numberOfElementsToCopy,
vtkm::cont::ArrayHandle<U, COut> &output,
vtkm::Id outputIndex = 0);
/// \brief Output is the first index in input for each item in values that wouldn't alter the ordering of input
///
/// LowerBounds is a vectorized search. From each value in \c values it finds
@ -513,7 +538,7 @@ public:
retval.Microseconds = 1000*currentTime.millitm;
#else
timeval currentTime;
gettimeofday(&currentTime, NULL);
gettimeofday(&currentTime, nullptr);
retval.Seconds = currentTime.tv_sec;
retval.Microseconds = currentTime.tv_usec;
#endif

@ -0,0 +1,46 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2016 Sandia Corporation.
// Copyright 2016 UT-Battelle, LLC.
// Copyright 2016 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_cont_DeviceAdapterListTag_h
#define vtk_m_cont_DeviceAdapterListTag_h
#ifndef VTKM_DEFAULT_DEVICE_ADAPTER_LIST_TAG
#define VTKM_DEFAULT_DEVICE_ADAPTER_LIST_TAG \
::vtkm::cont::DeviceAdapterListTagCommon
#endif
#include <vtkm/ListTag.h>
#include <vtkm/cont/DeviceAdapterSerial.h>
#include <vtkm/cont/cuda/DeviceAdapterCuda.h>
#include <vtkm/cont/tbb/DeviceAdapterTBB.h>
namespace vtkm {
namespace cont {
struct DeviceAdapterListTagCommon
: vtkm::ListTagBase<
vtkm::cont::DeviceAdapterTagCuda,
vtkm::cont::DeviceAdapterTagTBB,
vtkm::cont::DeviceAdapterTagSerial> { };
}
} // namespace vtkm::cont
#endif //vtk_m_cont_DeviceAdapterListTag_h

@ -29,11 +29,6 @@
#include <vtkm/cont/internal/DynamicTransform.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/utility/enable_if.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
namespace vtkm {
namespace cont {
@ -55,7 +50,7 @@ struct PolymorphicArrayHandleContainerBase
virtual void PrintSummary(std::ostream &out) const = 0;
virtual boost::shared_ptr<PolymorphicArrayHandleContainerBase>
virtual std::shared_ptr<PolymorphicArrayHandleContainerBase>
NewInstance() const = 0;
};
@ -97,10 +92,10 @@ struct PolymorphicArrayHandleContainer
vtkm::cont::printSummary_ArrayHandle(this->Array, out);
}
virtual boost::shared_ptr<PolymorphicArrayHandleContainerBase>
virtual std::shared_ptr<PolymorphicArrayHandleContainerBase>
NewInstance() const
{
return boost::shared_ptr<PolymorphicArrayHandleContainerBase>(
return std::shared_ptr<PolymorphicArrayHandleContainerBase>(
new PolymorphicArrayHandleContainer<T,Storage>());
}
};
@ -114,7 +109,7 @@ struct DynamicArrayHandleCopyHelper {
template<typename TypeList, typename StorageList>
VTKM_CONT_EXPORT
static
const boost::shared_ptr<vtkm::cont::detail::PolymorphicArrayHandleContainerBase>&
const std::shared_ptr<vtkm::cont::detail::PolymorphicArrayHandleContainerBase>&
GetArrayHandleContainer(const vtkm::cont::DynamicArrayHandleBase<TypeList,StorageList> &src)
{
return src.ArrayContainer;
@ -123,7 +118,7 @@ struct DynamicArrayHandleCopyHelper {
// A simple function to downcast an ArrayHandle encapsulated in a
// PolymorphicArrayHandleContainerBase to the given type of ArrayHandle. If the
// conversion cannot be done, NULL is returned.
// conversion cannot be done, nullptr is returned.
template<typename Type, typename Storage>
VTKM_CONT_EXPORT
vtkm::cont::ArrayHandle<Type,Storage> *
@ -134,13 +129,13 @@ DynamicArrayHandleTryCast(
downcastContainer = dynamic_cast<
vtkm::cont::detail::PolymorphicArrayHandleContainer<Type,Storage> *>(
arrayContainer);
if (downcastContainer != NULL)
if (downcastContainer != nullptr)
{
return &downcastContainer->Array;
}
else
{
return NULL;
return nullptr;
}
}
@ -148,7 +143,7 @@ template<typename Type, typename Storage>
VTKM_CONT_EXPORT
vtkm::cont::ArrayHandle<Type,Storage> *
DynamicArrayHandleTryCast(
const boost::shared_ptr<vtkm::cont::detail::PolymorphicArrayHandleContainerBase>& arrayContainer)
const std::shared_ptr<vtkm::cont::detail::PolymorphicArrayHandleContainerBase>& arrayContainer)
{
return detail::DynamicArrayHandleTryCast<Type,Storage>(arrayContainer.get());
}
@ -234,14 +229,14 @@ public:
bool IsTypeAndStorage() const {
return (
detail::DynamicArrayHandleTryCast<Type,Storage>(this->ArrayContainer)
!= NULL);
!= nullptr);
}
/// Returns true if this array matches the array handle type passed in.
///
template<typename ArrayHandleType>
VTKM_CONT_EXPORT
bool IsArrayHandleType()
bool IsType()
{
VTKM_IS_ARRAY_HANDLE(ArrayHandleType);
typedef typename ArrayHandleType::ValueType ValueType;
@ -257,7 +252,7 @@ public:
bool IsSameType(const ArrayHandleType &)
{
VTKM_IS_ARRAY_HANDLE(ArrayHandleType);
return this->IsArrayHandleType<ArrayHandleType>();
return this->IsType<ArrayHandleType>();
}
/// Returns this array cast to an ArrayHandle object of the given type and
@ -271,7 +266,7 @@ public:
CastToTypeStorage() const {
vtkm::cont::ArrayHandle<Type, Storage> *downcastArray =
detail::DynamicArrayHandleTryCast<Type,Storage>(this->ArrayContainer);
if (downcastArray == NULL)
if (downcastArray == nullptr)
{
throw vtkm::cont::ErrorControlBadType("Bad cast of dynamic array.");
}
@ -282,7 +277,7 @@ public:
}
/// Returns this array cast to the given \c ArrayHandle type. Throws \c
/// ErrorControlBadType if the cast does not work. Use \c IsArrayHandleType
/// ErrorControlBadType if the cast does not work. Use \c IsType
/// to check if the cast can happen.
///
template<typename ArrayHandleType>
@ -410,7 +405,7 @@ public:
}
private:
boost::shared_ptr<vtkm::cont::detail::PolymorphicArrayHandleContainerBase>
std::shared_ptr<vtkm::cont::detail::PolymorphicArrayHandleContainerBase>
ArrayContainer;
friend struct detail::DynamicArrayHandleCopyHelper;
@ -442,7 +437,7 @@ struct DynamicArrayHandleTryStorage {
private:
template<typename Storage>
void DoCast(Storage, boost::mpl::bool_<true>)
void DoCast(Storage, std::true_type)
{
if (!this->FoundCast &&
this->Array->template IsTypeAndStorage<Type,Storage>())
@ -453,7 +448,7 @@ private:
}
template<typename Storage>
void DoCast(Storage, boost::mpl::bool_<false>)
void DoCast(Storage, std::false_type)
{
// This type of array handle cannot exist, so do nothing.
}

@ -27,10 +27,6 @@
#include <vtkm/cont/internal/DynamicTransform.h>
#include <vtkm/cont/internal/SimplePolymorphicContainer.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/smart_ptr/shared_ptr.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
namespace vtkm {
namespace cont {
@ -49,7 +45,7 @@ struct DynamicCellSetCopyHelper {
template<typename CellSetList>
VTKM_CONT_EXPORT
static
const boost::shared_ptr<vtkm::cont::internal::SimplePolymorphicContainerBase>&
const std::shared_ptr<vtkm::cont::internal::SimplePolymorphicContainerBase>&
GetCellSetContainer(const vtkm::cont::DynamicCellSetBase<CellSetList> &src)
{
return src.CellSetContainer;
@ -58,7 +54,7 @@ struct DynamicCellSetCopyHelper {
// A simple function to downcast a CellSet encapsulated in a
// SimplePolymorphicContainerBase to the given subclass of CellSet. If the
// conversion cannot be done, NULL is returned.
// conversion cannot be done, nullptr is returned.
template<typename CellSetType>
VTKM_CONT_EXPORT
CellSetType *
@ -69,13 +65,13 @@ DynamicCellSetTryCast(
downcastContainer = dynamic_cast<
vtkm::cont::internal::SimplePolymorphicContainer<CellSetType> *>(
cellSetContainer);
if (downcastContainer != NULL)
if (downcastContainer != nullptr)
{
return &downcastContainer->Item;
}
else
{
return NULL;
return nullptr;
}
}
@ -83,7 +79,7 @@ template<typename CellSetType>
VTKM_CONT_EXPORT
CellSetType *
DynamicCellSetTryCast(
const boost::shared_ptr<vtkm::cont::internal::SimplePolymorphicContainerBase>& cellSetContainer)
const std::shared_ptr<vtkm::cont::internal::SimplePolymorphicContainerBase>& cellSetContainer)
{
return detail::DynamicCellSetTryCast<CellSetType>(cellSetContainer.get());
}
@ -166,7 +162,7 @@ public:
VTKM_CONT_EXPORT
bool IsType() const {
return (detail::DynamicCellSetTryCast<CellSetType>(this->CellSetContainer)
!= NULL);
!= nullptr);
}
/// Returns true if this cell set is the same (or equivalent) type as the
@ -181,7 +177,7 @@ public:
/// Returns the contained cell set as the abstract \c CellSet type.
///
VTKM_CONT_EXPORT
const vtkm::cont::CellSet &GetCellSet() const {
const vtkm::cont::CellSet &CastToBase() const {
return *reinterpret_cast<const vtkm::cont::CellSet *>(
this->CellSetContainer->GetVoidPointer());
}
@ -195,7 +191,7 @@ public:
CellSetType &Cast() const {
CellSetType *cellSetPointer =
detail::DynamicCellSetTryCast<CellSetType>(this->CellSetContainer);
if (cellSetPointer == NULL)
if (cellSetPointer == nullptr)
{
throw vtkm::cont::ErrorControlBadType("Bad cast of dynamic cell set.");
}
@ -257,8 +253,45 @@ public:
return newCellSet;
}
VTKM_CONT_EXPORT
virtual std::string GetName() const
{
return this->CastToBase().GetName();
}
VTKM_CONT_EXPORT
virtual vtkm::Id GetNumberOfCells() const
{
return this->CastToBase().GetNumberOfCells();
}
VTKM_CONT_EXPORT
virtual vtkm::Id GetNumberOfFaces() const
{
return this->CastToBase().GetNumberOfFaces();
}
VTKM_CONT_EXPORT
virtual vtkm::Id GetNumberOfEdges() const
{
return this->CastToBase().GetNumberOfEdges();
}
VTKM_CONT_EXPORT
virtual vtkm::Id GetNumberOfPoints() const
{
return this->CastToBase().GetNumberOfPoints();
}
VTKM_CONT_EXPORT
virtual void PrintSummary(std::ostream& stream) const
{
return this->CastToBase().PrintSummary(stream);
}
private:
boost::shared_ptr<vtkm::cont::internal::SimplePolymorphicContainerBase>
std::shared_ptr<vtkm::cont::internal::SimplePolymorphicContainerBase>
CellSetContainer;
friend struct detail::DynamicCellSetCopyHelper;
@ -286,7 +319,7 @@ struct DynamicCellSetTryCellSet
{
CellSetType *cellSet =
detail::DynamicCellSetTryCast<CellSetType>(this->CellSetContainer);
if (cellSet != NULL)
if (cellSet != nullptr)
{
this->Function(*cellSet);
this->FoundCast = true;

@ -518,7 +518,21 @@ private:
mutable bool ModifiedFlag;
};
template<typename Functor>
void CastAndCall(const vtkm::cont::Field& field, const Functor &f)
{
field.GetData().CastAndCall(f);
}
namespace internal {
template<>
struct DynamicTransformTraits<vtkm::cont::Field>
{
typedef vtkm::cont::internal::DynamicTransformTagCastAndCall DynamicTag;
};
} // namespace internal
} // namespace cont
} // namespace vtkm

@ -61,9 +61,9 @@ namespace internal {
inline void* alloc_aligned(size_t size, size_t align){
#if defined(VTKM_MEMALIGN_POSIX)
void *mem = NULL;
void *mem = nullptr;
if (posix_memalign(&mem, align, size) != 0){
mem = NULL;
mem = nullptr;
}
#elif defined(VTKM_MEMALIGN_WIN)
void *mem = _aligned_malloc(size, align);
@ -72,7 +72,7 @@ inline void* alloc_aligned(size_t size, size_t align){
#else
void *mem = malloc(size);
#endif
if (mem == NULL){
if (mem == nullptr){
throw std::bad_alloc();
}
return mem;
@ -174,12 +174,12 @@ public:
public:
VTKM_CONT_EXPORT
Storage(const ValueType *array = NULL, vtkm::Id numberOfValues = 0)
Storage(const ValueType *array = nullptr, vtkm::Id numberOfValues = 0)
: Array(const_cast<ValueType *>(array)),
NumberOfValues(numberOfValues),
AllocatedSize(numberOfValues),
DeallocateOnRelease(false),
UserProvidedMemory( array == NULL ? false : true)
UserProvidedMemory( array == nullptr ? false : true)
{
}
@ -230,20 +230,20 @@ public:
{
if (this->NumberOfValues > 0)
{
VTKM_ASSERT(this->Array != NULL);
VTKM_ASSERT(this->Array != nullptr);
if (this->DeallocateOnRelease)
{
AllocatorType allocator;
allocator.deallocate(this->Array,
static_cast<std::size_t>(this->AllocatedSize) );
}
this->Array = NULL;
this->Array = nullptr;
this->NumberOfValues = 0;
this->AllocatedSize = 0;
}
else
{
VTKM_ASSERT(this->Array == NULL);
VTKM_ASSERT(this->Array == nullptr);
}
}
@ -281,7 +281,7 @@ public:
catch (std::bad_alloc err)
{
// Make sureour state is OK.
this->Array = NULL;
this->Array = nullptr;
this->NumberOfValues = 0;
this->AllocatedSize = 0;
throw vtkm::cont::ErrorControlBadAllocation(
@ -322,10 +322,27 @@ public:
return PortalConstType(this->Array, this->Array + this->NumberOfValues);
}
/// \brief Get a pointer to the underlying data structure.
///
/// This method returns the pointer to the array held by this array. The
/// memory associated with this array still belongs to the Storage (i.e.
/// Storage will eventually deallocate the array).
///
VTKM_CONT_EXPORT
ValueType *GetArray()
{
return this->Array;
}
VTKM_CONT_EXPORT
const ValueType *GetArray() const
{
return this->Array;
}
/// \brief Take the reference away from this object.
///
/// This method returns the pointer to the array held by this array. It then
/// clears the internal array pointer to NULL, thereby ensuring that the
/// clears the internal array pointer to nullptr, thereby ensuring that the
/// Storage will never deallocate the array. This is helpful for taking a
/// reference for an array created internally by VTK-m and not having to keep
/// a VTK-m object around. Obviously the caller becomes responsible for
@ -335,7 +352,7 @@ public:
ValueType *StealArray()
{
ValueType *saveArray = this->Array;
this->Array = NULL;
this->Array = nullptr;
this->NumberOfValues = 0;
this->AllocatedSize = 0;
return saveArray;

208
vtkm/cont/TryExecute.h Normal file

@ -0,0 +1,208 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2016 Sandia Corporation.
// Copyright 2016 UT-Battelle, LLC.
// Copyright 2016 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_cont_TryExecute_h
#define vtk_m_cont_TryExecute_h
#include <vtkm/cont/DeviceAdapterListTag.h>
#include <vtkm/cont/ErrorControlBadAllocation.h>
#include <vtkm/cont/ErrorControlBadType.h>
#include <vtkm/cont/ErrorControlBadValue.h>
#include <vtkm/cont/internal/RuntimeDeviceTracker.h>
namespace vtkm {
namespace cont {
namespace detail {
template<typename Functor, typename Device, bool DeviceAdapterValid>
struct TryExecuteRunIfValid;
template<typename Functor, typename Device>
struct TryExecuteRunIfValid<Functor, Device, false>
{
VTKM_CONT_EXPORT
static bool Run(Functor &, vtkm::cont::internal::RuntimeDeviceTracker &) {
return false;
}
};
template<typename Functor, typename Device>
struct TryExecuteRunIfValid<Functor, Device, true>
{
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
VTKM_CONT_EXPORT
static bool Run(Functor &functor,
vtkm::cont::internal::RuntimeDeviceTracker &tracker)
{
if (tracker.CanRunOn(Device()))
{
try
{
return functor(Device());
}
catch(vtkm::cont::ErrorControlBadAllocation e)
{
std::cerr << "caught ErrorControlBadAllocation " << e.GetMessage() << std::endl;
//currently we only consider OOM errors worth disabling a device for
//than we fallback to another device
tracker.ReportAllocationFailure(Device(), e);
}
catch(vtkm::cont::ErrorControlBadType e)
{
//should bad type errors should stop the execution, instead of
//deferring to another device adapter?
std::cerr << "caught ErrorControlBadType : " << e.GetMessage() << std::endl;
}
catch(vtkm::cont::ErrorControlBadValue e)
{
//should bad value errors should stop the filter, instead of deferring
//to another device adapter?
std::cerr << "caught ErrorControlBadValue : " << e.GetMessage() << std::endl;
}
catch(vtkm::cont::Error e)
{
//general errors should be caught and let us try the next device adapter.
std::cerr << "exception is: " << e.GetMessage() << std::endl;
}
catch (std::exception e)
{
std::cerr << "caught standard exception: " << e.what() << std::endl;
}
catch (...)
{
std::cerr << "unknown exception caught" << std::endl;
}
}
// If we are here, then the functor was either never run or failed.
return false;
}
};
template<typename FunctorType>
struct TryExecuteImpl
{
// Warning, these are a references. Make sure referenced objects do not go
// out of scope.
FunctorType &Functor;
vtkm::cont::internal::RuntimeDeviceTracker &Tracker;
bool Success;
VTKM_CONT_EXPORT
TryExecuteImpl(FunctorType &functor,
vtkm::cont::internal::RuntimeDeviceTracker &tracker)
: Functor(functor), Tracker(tracker), Success(false) { }
template<typename Device>
VTKM_CONT_EXPORT
bool operator()(Device)
{
if (!this->Success)
{
typedef vtkm::cont::DeviceAdapterTraits<Device> DeviceTraits;
this->Success =
detail::TryExecuteRunIfValid<FunctorType,Device,DeviceTraits::Valid>
::Run(this->Functor, this->Tracker);
}
return this->Success;
}
};
} // namespace detail
/// \brief Try to execute a functor on a list of devices until one succeeds.
///
/// This function takes a functor and a list of devices. It then tries to run
/// the functor for each device (in the order given in the list) until the
/// execution succeeds.
///
/// The functor parentheses operator should take exactly one argument, which is
/// the \c DeviceAdapterTag to use. The functor should return a \c bool that is
/// \c true if the execution succeeds, \c false if it fails. If an exception is
/// thrown from the functor, then the execution is assumed to have failed.
///
/// This function also optionally takes a \c RuntimeDeviceTracker, which will
/// monitor for certain failures across calls to TryExecute and skip trying
/// devices with a history of failure.
///
/// This function returns \c true if the functor succeeded on a device,
/// \c false otherwise.
///
/// If no device list is specified, then \c VTKM_DEFAULT_DEVICE_ADAPTER_LIST_TAG
/// is used.
///
template<typename Functor, typename DeviceList>
VTKM_CONT_EXPORT
bool TryExecute(const Functor &functor,
vtkm::cont::internal::RuntimeDeviceTracker &tracker,
DeviceList)
{
detail::TryExecuteImpl<const Functor> internals(functor, tracker);
vtkm::ListForEach(internals, DeviceList());
return internals.Success;
}
template<typename Functor, typename DeviceList>
VTKM_CONT_EXPORT
bool TryExecute(Functor &functor,
vtkm::cont::internal::RuntimeDeviceTracker &tracker,
DeviceList)
{
detail::TryExecuteImpl<Functor> internals(functor, tracker);
vtkm::ListForEach(internals, DeviceList());
return internals.Success;
}
template<typename Functor, typename DeviceList>
VTKM_CONT_EXPORT
bool TryExecute(const Functor &functor, DeviceList)
{
vtkm::cont::internal::RuntimeDeviceTracker tracker;
return vtkm::cont::TryExecute(functor, tracker, DeviceList());
}
template<typename Functor, typename DeviceList>
VTKM_CONT_EXPORT
bool TryExecute(Functor &functor, DeviceList)
{
vtkm::cont::internal::RuntimeDeviceTracker tracker;
return vtkm::cont::TryExecute(functor, tracker, DeviceList());
}
template<typename Functor>
VTKM_CONT_EXPORT
bool TryExecute(const Functor &functor)
{
return vtkm::cont::TryExecute(functor,
VTKM_DEFAULT_DEVICE_ADAPTER_LIST_TAG());
}
template<typename Functor>
VTKM_CONT_EXPORT
bool TryExecute(Functor &functor)
{
return vtkm::cont::TryExecute(functor,
VTKM_DEFAULT_DEVICE_ADAPTER_LIST_TAG());
}
}
} // namespace vtkm::cont
#endif //vtk_m_cont_TryExecute_h

@ -23,9 +23,7 @@
#include <vtkm/StaticAssert.h>
#include <vtkm/internal/ExportMacros.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/type_traits/is_base_of.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
#include <type_traits>
namespace vtkm {
namespace cont {
@ -49,8 +47,8 @@ namespace internal {
template<typename ControlSignatureTag>
struct ControlSignatureTagCheck
{
static const bool Valid =
boost::is_base_of<
static VTKM_CONSTEXPR bool Valid =
std::is_base_of<
vtkm::cont::arg::ControlSignatureTagBase, ControlSignatureTag>::value;
};

@ -26,11 +26,6 @@
#include <vtkm/exec/ExecutionObjectBase.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/mpl/assert.hpp>
#include <boost/type_traits/is_base_of.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
namespace vtkm {
namespace cont {
namespace arg {
@ -49,7 +44,9 @@ struct Transport<vtkm::cont::arg::TransportTagExecObject,ContObjectType,Device>
// is not an execution object as an argument that is expected to be one. All
// execution objects are expected to inherit from
// vtkm::exec::ExecutionObjectBase.
BOOST_MPL_ASSERT(( boost::is_base_of<vtkm::exec::ExecutionObjectBase, ContObjectType> ));
static_assert(
std::is_base_of<vtkm::exec::ExecutionObjectBase, ContObjectType>::value,
"All execution objects are expected to inherit from vtkm::exec::ExecutionObjectBase");
typedef ContObjectType ExecObjectType;

@ -26,9 +26,7 @@
#include <vtkm/exec/ExecutionObjectBase.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/type_traits/is_base_of.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
#include <type_traits>
namespace vtkm {
namespace cont {
@ -43,8 +41,8 @@ struct TypeCheckTagExecObject { };
template<typename Type>
struct TypeCheck<TypeCheckTagExecObject, Type>
{
static const bool value =
boost::is_base_of<vtkm::exec::ExecutionObjectBase, Type>::value;
static VTKM_CONSTEXPR bool value =
std::is_base_of<vtkm::exec::ExecutionObjectBase, Type>::value;
};
}

@ -79,7 +79,7 @@ struct TryArrayInType
template<typename Device>
void TryArrayInTransport(Device)
{
vtkm::testing::Testing::TryAllTypes(TryArrayInType<Device>());
vtkm::testing::Testing::TryTypes(TryArrayInType<Device>());
}
void TestArrayInTransport()

@ -75,7 +75,7 @@ struct TryArrayOutType
template<typename Device>
void TryArrayOutTransport(Device)
{
vtkm::testing::Testing::TryAllTypes(TryArrayOutType<Device>());
vtkm::testing::Testing::TryTypes(TryArrayOutType<Device>());
}
void TestArrayOutTransport()

@ -99,7 +99,7 @@ void TestCheckAtomicArray()
void TestCheckArray()
{
vtkm::testing::Testing::TryAllTypes(TryArraysOfType());
vtkm::testing::Testing::TryTypes(TryArraysOfType());
std::cout << "Trying some arrays with types that do not match the list."
<< std::endl;

@ -288,7 +288,7 @@ private:
#endif
template<class InputPortal, class OutputPortal>
VTKM_CONT_EXPORT static void CopyPortal(const InputPortal &input,
const OutputPortal &output)
const OutputPortal &output)
{
try
{
@ -303,6 +303,26 @@ private:
}
}
template<class InputPortal, class OutputPortal>
VTKM_CONT_EXPORT static void CopySubRangePortal(const InputPortal &input,
vtkm::Id inputOffset,
vtkm::Id size,
const OutputPortal &output,
vtkm::Id outputOffset)
{
try
{
::thrust::copy_n(thrust::cuda::par,
IteratorBegin(input)+inputOffset,
static_cast<std::size_t>(size),
IteratorBegin(output)+outputOffset);
}
catch(...)
{
throwAsVTKmException();
}
}
template<class InputPortal, class ValuesPortal, class OutputPortal>
VTKM_CONT_EXPORT static void LowerBoundsPortal(const InputPortal &input,
const ValuesPortal &values,
@ -778,15 +798,57 @@ public:
const vtkm::cont::ArrayHandle<T,SIn> &input,
vtkm::cont::ArrayHandle<U,SOut> &output)
{
const vtkm::Id numberOfValues = input.GetNumberOfValues();
//We need call PrepareForInput on the input argument before invoking a
//function. The order of execution of parameters of a function is undefined
//so we need to make sure input is called before output, or else in-place
//use case breaks.
input.PrepareForInput(DeviceAdapterTag());
const vtkm::Id inSize = input.GetNumberOfValues();
CopyPortal(input.PrepareForInput(DeviceAdapterTag()),
output.PrepareForOutput(numberOfValues, DeviceAdapterTag()));
output.PrepareForOutput(inSize, DeviceAdapterTag()));
}
template<typename T, typename U, class SIn, class SOut>
VTKM_CONT_EXPORT static bool CopySubRange(
const vtkm::cont::ArrayHandle<T,SIn> &input,
vtkm::Id inputStartIndex,
vtkm::Id numberOfElementsToCopy,
vtkm::cont::ArrayHandle<U,SOut> &output,
vtkm::Id outputIndex = 0)
{
const vtkm::Id inSize = input.GetNumberOfValues();
if(inputStartIndex < 0 ||
numberOfElementsToCopy < 0 ||
outputIndex < 0 ||
inputStartIndex >= inSize)
{ //invalid parameters
return false;
}
//determine if the numberOfElementsToCopy needs to be reduced
if(inSize < (inputStartIndex + numberOfElementsToCopy))
{ //adjust the size
numberOfElementsToCopy = (inSize - inputStartIndex);
}
const vtkm::Id outSize = output.GetNumberOfValues();
const vtkm::Id copyOutEnd = outputIndex + numberOfElementsToCopy;
if(outSize < copyOutEnd)
{ //output is not large enough
if(outSize == 0)
{ //since output has nothing, just need to allocate to correct length
output.Allocate(copyOutEnd);
}
else
{ //we currently have data in this array, so preserve it in the new
//resized array
vtkm::cont::ArrayHandle<U, SOut> temp;
temp.Allocate(copyOutEnd);
CopySubRange(output, 0, outSize, temp);
output = temp;
}
}
CopySubRangePortal(input.PrepareForInput(DeviceAdapterTag()),
inputStartIndex,
numberOfElementsToCopy,
output.PrepareForInPlace(DeviceAdapterTag()),
outputIndex);
return true;
}
template<typename T, class SIn, class SVal, class SOut>
@ -984,8 +1046,8 @@ private:
{
const vtkm::Id ERROR_ARRAY_SIZE = 1024;
static bool errorArrayInit = false;
static char* hostPtr = NULL;
static char* devicePtr = NULL;
static char* hostPtr = nullptr;
static char* devicePtr = nullptr;
if( !errorArrayInit )
{
cudaMallocHost( (void**)&hostPtr, ERROR_ARRAY_SIZE, cudaHostAllocMapped );
@ -1047,7 +1109,7 @@ public:
//since the memory is pinned we can access it safely on the host
//without a memcpy
vtkm::Id errorArraySize = 0;
char* hostErrorPtr = NULL;
char* hostErrorPtr = nullptr;
char* deviceErrorPtr = GetPinnedErrorArray(errorArraySize, &hostErrorPtr);
//clear the first character which means that we don't contain an error
@ -1106,7 +1168,7 @@ public:
//since the memory is pinned we can access it safely on the host
//without a memcpy
vtkm::Id errorArraySize = 0;
char* hostErrorPtr = NULL;
char* hostErrorPtr = nullptr;
char* deviceErrorPtr = GetPinnedErrorArray(errorArraySize, &hostErrorPtr);
//clear the first character which means that we don't contain an error

@ -37,12 +37,12 @@ void TestCudaHandle()
{
//Verify that we can construct a cuda array handle using the class inside
//the vtkm::cont::cuda namespace
vtkm::cont::cuda::ArrayHandle<vtkm::Id> handleFoo(NULL,0);
vtkm::cont::cuda::ArrayHandle<vtkm::Id> handleFoo(nullptr,0);
vtkm::cont::Field foo("foo", vtkm::cont::Field::ASSOC_CELL_SET , "cellset", handleFoo);
//Verify that we can construct a cuda array handle using the class inside
//the vtkm::cont namespace
vtkm::cont::ArrayHandleCuda< vtkm::Vec< vtkm::Float32, 3> > handleBar(NULL,0);
vtkm::cont::ArrayHandleCuda< vtkm::Vec< vtkm::Float32, 3> > handleBar(nullptr,0);
vtkm::cont::Field bar("bar", vtkm::cont::Field::ASSOC_CELL_SET, "cellset", handleBar);
}

@ -29,7 +29,7 @@
#include <iterator>
#include <limits>
#include <boost/type_traits.hpp>
#include <type_traits>
namespace vtkm {
namespace cont {
@ -43,8 +43,8 @@ class ArrayPortalFromIterators;
///
template<class IteratorT>
class ArrayPortalFromIterators<IteratorT,
typename boost::disable_if<
boost::is_const< typename boost::remove_pointer<IteratorT>::type > >::type>
typename std::enable_if<
!std::is_const< typename std::remove_pointer<IteratorT>::type >::value >::type >
{
public:
typedef typename std::iterator_traits<IteratorT>::value_type ValueType;
@ -127,8 +127,8 @@ private:
template<class IteratorT>
class ArrayPortalFromIterators<IteratorT,
typename boost::enable_if<
boost::is_const< typename boost::remove_pointer<IteratorT>::type > >::type>
typename std::enable_if<
std::is_const< typename std::remove_pointer<IteratorT>::type >::value >::type >
{
public:
typedef typename std::iterator_traits<IteratorT>::value_type ValueType;
@ -261,7 +261,7 @@ public:
std::advance(iterator, static_cast<difference_type>(this->NumberOfValues));
#else
//Visual Studio checked iterators throw exceptions when you try to advance
//NULL iterators even if the advancement length is zero. So instead
//nullptr iterators even if the advancement length is zero. So instead
//don't do the advancement at all
if(this->NumberOfValues > 0)
{

Some files were not shown because too many files have changed in this diff Show More