mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Merge branch 'add_arrayHandle'
This commit is contained in:
commit
6466da1a11
142
CMake/CheckCXX11Features.cmake
Normal file
142
CMake/CheckCXX11Features.cmake
Normal file
@ -0,0 +1,142 @@
|
||||
# - 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)
|
8
CMake/CheckCXX11Features/cxx11-test-__func__.cpp
Normal file
8
CMake/CheckCXX11Features/cxx11-test-__func__.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
int main(void)
|
||||
{
|
||||
if (!__func__)
|
||||
return 1;
|
||||
if (!(*__func__))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
12
CMake/CheckCXX11Features/cxx11-test-auto.cpp
Normal file
12
CMake/CheckCXX11Features/cxx11-test-auto.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
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;
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
int main(void)
|
||||
{
|
||||
// must fail because there is no initializer
|
||||
auto i;
|
||||
|
||||
return 0;
|
||||
}
|
8
CMake/CheckCXX11Features/cxx11-test-auto_ret_type.cpp
Normal file
8
CMake/CheckCXX11Features/cxx11-test-auto_ret_type.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
auto foo(int i) -> int {
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
return foo(1);
|
||||
}
|
21
CMake/CheckCXX11Features/cxx11-test-class_override_final.cpp
Normal file
21
CMake/CheckCXX11Features/cxx11-test-class_override_final.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
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;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
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;
|
||||
}
|
19
CMake/CheckCXX11Features/cxx11-test-constexpr.cpp
Normal file
19
CMake/CheckCXX11Features/cxx11-test-constexpr.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
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;
|
||||
}
|
11
CMake/CheckCXX11Features/cxx11-test-cstdint.cpp
Normal file
11
CMake/CheckCXX11Features/cxx11-test-cstdint.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#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;
|
||||
}
|
10
CMake/CheckCXX11Features/cxx11-test-decltype.cpp
Normal file
10
CMake/CheckCXX11Features/cxx11-test-decltype.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
bool check_size(int i)
|
||||
{
|
||||
return sizeof(int) == sizeof(decltype(i));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
bool ret = check_size(42);
|
||||
return ret ? 0 : 1;
|
||||
}
|
27
CMake/CheckCXX11Features/cxx11-test-initializer_list.cpp
Normal file
27
CMake/CheckCXX11Features/cxx11-test-initializer_list.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#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;
|
||||
}
|
5
CMake/CheckCXX11Features/cxx11-test-lambda.cpp
Normal file
5
CMake/CheckCXX11Features/cxx11-test-lambda.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
int main()
|
||||
{
|
||||
int ret = 0;
|
||||
return ([&ret]() -> int { return ret; })();
|
||||
}
|
7
CMake/CheckCXX11Features/cxx11-test-long_long.cpp
Normal file
7
CMake/CheckCXX11Features/cxx11-test-long_long.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
int main(void)
|
||||
{
|
||||
long long l;
|
||||
unsigned long long ul;
|
||||
|
||||
return ((sizeof(l) >= 8) && (sizeof(ul) >= 8)) ? 0 : 1;
|
||||
}
|
6
CMake/CheckCXX11Features/cxx11-test-nullptr.cpp
Normal file
6
CMake/CheckCXX11Features/cxx11-test-nullptr.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
int main(void)
|
||||
{
|
||||
void *v = nullptr;
|
||||
|
||||
return v ? 1 : 0;
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
int main(void)
|
||||
{
|
||||
int i = nullptr;
|
||||
|
||||
return 1;
|
||||
}
|
26
CMake/CheckCXX11Features/cxx11-test-regex.cpp
Normal file
26
CMake/CheckCXX11Features/cxx11-test-regex.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#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;
|
||||
}
|
57
CMake/CheckCXX11Features/cxx11-test-rvalue-references.cpp
Normal file
57
CMake/CheckCXX11Features/cxx11-test-rvalue-references.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#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;
|
||||
}
|
14
CMake/CheckCXX11Features/cxx11-test-sizeof_member.cpp
Normal file
14
CMake/CheckCXX11Features/cxx11-test-sizeof_member.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
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;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
struct foo {
|
||||
int baz;
|
||||
double bar;
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return (sizeof(foo::bar) == 4) ? 0 : 1;
|
||||
}
|
5
CMake/CheckCXX11Features/cxx11-test-static_assert.cpp
Normal file
5
CMake/CheckCXX11Features/cxx11-test-static_assert.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
int main(void)
|
||||
{
|
||||
static_assert(0 < 1, "your ordering of integers is screwed");
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
int main(void)
|
||||
{
|
||||
static_assert(1 < 0, "your ordering of integers is screwed");
|
||||
return 0;
|
||||
}
|
23
CMake/CheckCXX11Features/cxx11-test-variadic_templates.cpp
Normal file
23
CMake/CheckCXX11Features/cxx11-test-variadic_templates.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
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;
|
||||
}
|
438
CMake/FindBoostHeaders.cmake
Normal file
438
CMake/FindBoostHeaders.cmake
Normal file
@ -0,0 +1,438 @@
|
||||
#
|
||||
# - Finds the Boost headers only
|
||||
# Use this module by invoking find_package with the form:
|
||||
# find_package(Boost
|
||||
# [version] [EXACT] # Minimum or EXACT version e.g. 1.36.0
|
||||
# [REQUIRED] # Fail with error if Boost is not found
|
||||
# )
|
||||
#
|
||||
# This module finds boost headers the search for the boost headers results
|
||||
# reported in variables:
|
||||
#
|
||||
# Boost_FOUND - True if headers and requested libraries were found
|
||||
# Boost_INCLUDE_DIRS - Boost include directories
|
||||
# Boost_VERSION - BOOST_VERSION value from boost/version.hpp
|
||||
# Boost_MAJOR_VERSION - Boost major version number (X in X.y.z)
|
||||
# Boost_MINOR_VERSION - Boost minor version number (Y in x.Y.z)
|
||||
# Boost_SUBMINOR_VERSION - Boost subminor version number (Z in x.y.Z)
|
||||
#
|
||||
# This module reads hints about search locations from variables:
|
||||
# BOOST_INCLUDEDIR - Preferred include directory e.g. <prefix>/include
|
||||
# Boost_NO_SYSTEM_PATHS - Set to ON to disable searching in locations not
|
||||
# specified by these hint variables. Default is OFF.
|
||||
# Boost_ADDITIONAL_VERSIONS
|
||||
# - List of Boost versions not known to this module
|
||||
# (Boost install locations may contain the version)
|
||||
# and saves search results persistently in CMake cache entries:
|
||||
# Boost_INCLUDE_DIR - Directory containing Boost headers
|
||||
#
|
||||
# Users may set these hints or results as cache entries. Projects should
|
||||
# not read these entries directly but instead use the above result variables.
|
||||
# Note that some hint names start in upper-case "BOOST". One may specify
|
||||
# these as environment variables if they are not specified as CMake variables
|
||||
# or cache entries.
|
||||
#
|
||||
# This module first searches for the Boost header files using the above hint
|
||||
# variables and saves the result in
|
||||
# Boost_INCLUDE_DIR.
|
||||
#
|
||||
#
|
||||
#=============================================================================
|
||||
# Copyright 2006-2012 Kitware, Inc.
|
||||
# Copyright 2006-2008 Andreas Schneider <mail@cynapses.org>
|
||||
# Copyright 2007 Wengo
|
||||
# Copyright 2007 Mike Jackson
|
||||
# Copyright 2008 Andreas Pakulat <apaku@gmx.de>
|
||||
# Copyright 2008-2012 Philip Lowman <philip@yhbt.com>
|
||||
#
|
||||
# CMake - Cross Platform Makefile Generator
|
||||
# Copyright 2000-2011 Kitware, Inc., Insight Software Consortium
|
||||
# All rights reserved.
|
||||
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# * Neither the names of Kitware, Inc., the Insight Software Consortium,
|
||||
# nor the names of their contributors may be used to endorse or promote
|
||||
# products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
#
|
||||
# The above copyright and license notice applies to distributions of
|
||||
# CMake in source and binary form. Some source files contain additional
|
||||
# notices of original copyright by their contributors; see each source
|
||||
# for details. Third-party software packages supplied with CMake under
|
||||
# compatible licenses provide their own copyright notices documented in
|
||||
# corresponding subdirectories.
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
#
|
||||
# CMake was initially developed by Kitware with the following sponsorship:
|
||||
#
|
||||
# * National Library of Medicine at the National Institutes of Health
|
||||
# as part of the Insight Segmentation and Registration Toolkit (ITK).
|
||||
#
|
||||
# * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel
|
||||
# Visualization Initiative.
|
||||
#
|
||||
# * National Alliance for Medical Image Computing (NAMIC) is funded by the
|
||||
# National Institutes of Health through the NIH Roadmap for Medical Research,
|
||||
# Grant U54 EB005149.
|
||||
#
|
||||
# * Kitware, Inc.
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# FindBoost functions & macros
|
||||
#
|
||||
macro(_Boost_CHANGE_DETECT changed_var)
|
||||
set(${changed_var} 0)
|
||||
foreach(v ${ARGN})
|
||||
if(DEFINED _Boost_COMPONENTS_SEARCHED)
|
||||
if(${v})
|
||||
if(_${v}_LAST)
|
||||
string(COMPARE NOTEQUAL "${${v}}" "${_${v}_LAST}" _${v}_CHANGED)
|
||||
else()
|
||||
set(_${v}_CHANGED 1)
|
||||
endif()
|
||||
elseif(_${v}_LAST)
|
||||
set(_${v}_CHANGED 1)
|
||||
endif()
|
||||
if(_${v}_CHANGED)
|
||||
set(${changed_var} 1)
|
||||
endif()
|
||||
else()
|
||||
set(_${v}_CHANGED 0)
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
#
|
||||
# Make sure the spelling of boost options is correct
|
||||
#
|
||||
function(_Boost_CHECK_SPELLING _var)
|
||||
if(${_var})
|
||||
string(TOUPPER ${_var} _var_UC)
|
||||
message(FATAL_ERROR "ERROR: ${_var} is not the correct spelling. The proper spelling is ${_var_UC}.")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
#
|
||||
# End functions/macros
|
||||
#
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# main.
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
# Check the version of Boost against the requested version.
|
||||
if(Boost_FIND_VERSION AND NOT Boost_FIND_VERSION_MINOR)
|
||||
message(SEND_ERROR "When requesting a specific version of Boost, you must provide at least the major and minor version numbers, e.g., 1.34")
|
||||
endif()
|
||||
|
||||
if(Boost_FIND_VERSION_EXACT)
|
||||
# The version may appear in a directory with or without the patch
|
||||
# level, even when the patch level is non-zero.
|
||||
set(_boost_TEST_VERSIONS
|
||||
"${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}.${Boost_FIND_VERSION_PATCH}"
|
||||
"${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}")
|
||||
else()
|
||||
# The user has not requested an exact version. Among known
|
||||
# versions, find those that are acceptable to the user request.
|
||||
set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS}
|
||||
"1.56.0" "1.56" "1.55.0" "1.55" "1.54.0" "1.54"
|
||||
"1.53.0" "1.53" "1.52.0" "1.52" "1.51.0" "1.51"
|
||||
"1.50.0" "1.50" "1.49.0" "1.49" "1.48.0" "1.48" "1.47.0" "1.47" "1.46.1"
|
||||
"1.46.0" "1.46" "1.45.0" "1.45" "1.44.0" "1.44" "1.43.0" "1.43" "1.42.0" "1.42"
|
||||
"1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37"
|
||||
"1.36.1" "1.36.0" "1.36" "1.35.1" "1.35.0" "1.35" "1.34.1" "1.34.0"
|
||||
"1.34" "1.33.1" "1.33.0" "1.33")
|
||||
set(_boost_TEST_VERSIONS)
|
||||
if(Boost_FIND_VERSION)
|
||||
set(_Boost_FIND_VERSION_SHORT "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}")
|
||||
# Select acceptable versions.
|
||||
foreach(version ${_Boost_KNOWN_VERSIONS})
|
||||
if(NOT "${version}" VERSION_LESS "${Boost_FIND_VERSION}")
|
||||
# This version is high enough.
|
||||
list(APPEND _boost_TEST_VERSIONS "${version}")
|
||||
elseif("${version}.99" VERSION_EQUAL "${_Boost_FIND_VERSION_SHORT}.99")
|
||||
# This version is a short-form for the requested version with
|
||||
# the patch level dropped.
|
||||
list(APPEND _boost_TEST_VERSIONS "${version}")
|
||||
endif()
|
||||
endforeach()
|
||||
else()
|
||||
# Any version is acceptable.
|
||||
set(_boost_TEST_VERSIONS "${_Boost_KNOWN_VERSIONS}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# The reason that we failed to find Boost. This will be set to a
|
||||
# user-friendly message when we fail to find some necessary piece of
|
||||
# Boost.
|
||||
set(Boost_ERROR_REASON)
|
||||
|
||||
if(Boost_DEBUG)
|
||||
# Output some of their choices
|
||||
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
|
||||
"_boost_TEST_VERSIONS = ${_boost_TEST_VERSIONS}")
|
||||
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
|
||||
"Boost_ADDITIONAL_VERSIONS = ${Boost_ADDITIONAL_VERSIONS}")
|
||||
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
|
||||
"Boost_NO_SYSTEM_PATHS = ${Boost_NO_SYSTEM_PATHS}")
|
||||
endif()
|
||||
|
||||
_Boost_CHECK_SPELLING(Boost_INCLUDEDIR)
|
||||
|
||||
# Collect environment variable inputs as hints. Do not consider changes.
|
||||
foreach(v BOOST_INCLUDEDIR)
|
||||
set(_env $ENV{${v}})
|
||||
if(_env)
|
||||
file(TO_CMAKE_PATH "${_env}" _ENV_${v})
|
||||
else()
|
||||
set(_ENV_${v} "")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Collect inputs and cached results. Detect changes since the last run.
|
||||
set(_Boost_VARS_DIR
|
||||
Boost_NO_SYSTEM_PATHS
|
||||
)
|
||||
|
||||
if(Boost_DEBUG)
|
||||
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
|
||||
"Declared as CMake or Environmental Variables:")
|
||||
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
|
||||
" BOOST_INCLUDEDIR = ${BOOST_INCLUDEDIR}")
|
||||
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
|
||||
"_boost_TEST_VERSIONS = ${_boost_TEST_VERSIONS}")
|
||||
endif()
|
||||
|
||||
# ------------------------------------------------------------------------
|
||||
# Search for Boost include DIR
|
||||
# ------------------------------------------------------------------------
|
||||
|
||||
set(_Boost_VARS_INC BOOST_INCLUDEDIR Boost_INCLUDE_DIR Boost_ADDITIONAL_VERSIONS)
|
||||
_Boost_CHANGE_DETECT(_Boost_CHANGE_INCDIR ${_Boost_VARS_DIR} ${_Boost_VARS_INC})
|
||||
# Clear Boost_INCLUDE_DIR if it did not change but other input affecting the
|
||||
# location did. We will find a new one based on the new inputs.
|
||||
if(_Boost_CHANGE_INCDIR AND NOT _Boost_INCLUDE_DIR_CHANGED)
|
||||
unset(Boost_INCLUDE_DIR CACHE)
|
||||
endif()
|
||||
|
||||
if(NOT Boost_INCLUDE_DIR)
|
||||
set(_boost_INCLUDE_SEARCH_DIRS "")
|
||||
if(BOOST_INCLUDEDIR)
|
||||
list(APPEND _boost_INCLUDE_SEARCH_DIRS ${BOOST_INCLUDEDIR})
|
||||
elseif(_ENV_BOOST_INCLUDEDIR)
|
||||
list(APPEND _boost_INCLUDE_SEARCH_DIRS ${_ENV_BOOST_INCLUDEDIR})
|
||||
endif()
|
||||
|
||||
if( Boost_NO_SYSTEM_PATHS)
|
||||
list(APPEND _boost_INCLUDE_SEARCH_DIRS NO_CMAKE_SYSTEM_PATH)
|
||||
else()
|
||||
list(APPEND _boost_INCLUDE_SEARCH_DIRS PATHS
|
||||
C:/boost/include
|
||||
C:/boost
|
||||
/sw/local/include
|
||||
)
|
||||
endif()
|
||||
|
||||
# Try to find Boost by stepping backwards through the Boost versions
|
||||
# we know about.
|
||||
# Build a list of path suffixes for each version.
|
||||
set(_boost_PATH_SUFFIXES)
|
||||
foreach(_boost_VER ${_boost_TEST_VERSIONS})
|
||||
# Add in a path suffix, based on the required version, ideally
|
||||
# we could read this from version.hpp, but for that to work we'd
|
||||
# need to know the include dir already
|
||||
set(_boost_BOOSTIFIED_VERSION)
|
||||
|
||||
# Transform 1.35 => 1_35 and 1.36.0 => 1_36_0
|
||||
if(_boost_VER MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
|
||||
string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1_\\2_\\3"
|
||||
_boost_BOOSTIFIED_VERSION ${_boost_VER})
|
||||
elseif(_boost_VER MATCHES "[0-9]+\\.[0-9]+")
|
||||
string(REGEX REPLACE "([0-9]+)\\.([0-9]+)" "\\1_\\2"
|
||||
_boost_BOOSTIFIED_VERSION ${_boost_VER})
|
||||
endif()
|
||||
|
||||
list(APPEND _boost_PATH_SUFFIXES
|
||||
"boost-${_boost_BOOSTIFIED_VERSION}"
|
||||
"boost_${_boost_BOOSTIFIED_VERSION}"
|
||||
"boost/boost-${_boost_BOOSTIFIED_VERSION}"
|
||||
"boost/boost_${_boost_BOOSTIFIED_VERSION}"
|
||||
)
|
||||
|
||||
endforeach()
|
||||
|
||||
if(Boost_DEBUG)
|
||||
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
|
||||
"Include debugging info:")
|
||||
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
|
||||
" _boost_INCLUDE_SEARCH_DIRS = ${_boost_INCLUDE_SEARCH_DIRS}")
|
||||
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
|
||||
" _boost_PATH_SUFFIXES = ${_boost_PATH_SUFFIXES}")
|
||||
endif()
|
||||
|
||||
# Look for a standard boost header file.
|
||||
find_path(Boost_INCLUDE_DIR
|
||||
NAMES boost/config.hpp
|
||||
HINTS ${_boost_INCLUDE_SEARCH_DIRS}
|
||||
PATH_SUFFIXES ${_boost_PATH_SUFFIXES}
|
||||
)
|
||||
endif()
|
||||
|
||||
# ------------------------------------------------------------------------
|
||||
# Extract version information from version.hpp
|
||||
# ------------------------------------------------------------------------
|
||||
|
||||
# Set Boost_FOUND based only on header location and version.
|
||||
# It will be updated below for component libraries.
|
||||
if(Boost_INCLUDE_DIR)
|
||||
if(Boost_DEBUG)
|
||||
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
|
||||
"location of version.hpp: ${Boost_INCLUDE_DIR}/boost/version.hpp")
|
||||
endif()
|
||||
|
||||
# Extract Boost_VERSION and Boost_LIB_VERSION from version.hpp
|
||||
set(Boost_VERSION 0)
|
||||
set(Boost_LIB_VERSION "")
|
||||
file(STRINGS "${Boost_INCLUDE_DIR}/boost/version.hpp" _boost_VERSION_HPP_CONTENTS REGEX "#define BOOST_(LIB_)?VERSION ")
|
||||
set(_Boost_VERSION_REGEX "([0-9]+)")
|
||||
set(_Boost_LIB_VERSION_REGEX "\"([0-9_]+)\"")
|
||||
foreach(v VERSION LIB_VERSION)
|
||||
if("${_boost_VERSION_HPP_CONTENTS}" MATCHES ".*#define BOOST_${v} ${_Boost_${v}_REGEX}.*")
|
||||
set(Boost_${v} "${CMAKE_MATCH_1}")
|
||||
endif()
|
||||
endforeach()
|
||||
unset(_boost_VERSION_HPP_CONTENTS)
|
||||
|
||||
math(EXPR Boost_MAJOR_VERSION "${Boost_VERSION} / 100000")
|
||||
math(EXPR Boost_MINOR_VERSION "${Boost_VERSION} / 100 % 1000")
|
||||
math(EXPR Boost_SUBMINOR_VERSION "${Boost_VERSION} % 100")
|
||||
|
||||
set(Boost_ERROR_REASON
|
||||
"${Boost_ERROR_REASON}Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}\nBoost include path: ${Boost_INCLUDE_DIR}")
|
||||
if(Boost_DEBUG)
|
||||
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
|
||||
"version.hpp reveals boost "
|
||||
"${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
|
||||
endif()
|
||||
|
||||
if(Boost_FIND_VERSION)
|
||||
# Set Boost_FOUND based on requested version.
|
||||
set(_Boost_VERSION "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
|
||||
if("${_Boost_VERSION}" VERSION_LESS "${Boost_FIND_VERSION}")
|
||||
set(Boost_FOUND 0)
|
||||
set(_Boost_VERSION_AGE "old")
|
||||
elseif(Boost_FIND_VERSION_EXACT AND
|
||||
NOT "${_Boost_VERSION}" VERSION_EQUAL "${Boost_FIND_VERSION}")
|
||||
set(Boost_FOUND 0)
|
||||
set(_Boost_VERSION_AGE "new")
|
||||
else()
|
||||
set(Boost_FOUND 1)
|
||||
endif()
|
||||
if(NOT Boost_FOUND)
|
||||
# State that we found a version of Boost that is too new or too old.
|
||||
set(Boost_ERROR_REASON
|
||||
"${Boost_ERROR_REASON}\nDetected version of Boost is too ${_Boost_VERSION_AGE}. Requested version was ${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}")
|
||||
if (Boost_FIND_VERSION_PATCH)
|
||||
set(Boost_ERROR_REASON
|
||||
"${Boost_ERROR_REASON}.${Boost_FIND_VERSION_PATCH}")
|
||||
endif ()
|
||||
if (NOT Boost_FIND_VERSION_EXACT)
|
||||
set(Boost_ERROR_REASON "${Boost_ERROR_REASON} (or newer)")
|
||||
endif ()
|
||||
set(Boost_ERROR_REASON "${Boost_ERROR_REASON}.")
|
||||
endif ()
|
||||
else()
|
||||
# Caller will accept any Boost version.
|
||||
set(Boost_FOUND 1)
|
||||
endif()
|
||||
else()
|
||||
set(Boost_FOUND 0)
|
||||
set(Boost_ERROR_REASON
|
||||
"${Boost_ERROR_REASON}Unable to find the Boost header files. Please set BOOST_INCLUDEDIR to the directory containing Boost's headers.")
|
||||
endif()
|
||||
|
||||
set(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIR})
|
||||
set(Boost_LIBRARY_DIRS ${Boost_LIBRARY_DIR})
|
||||
|
||||
# ------------------------------------------------------------------------
|
||||
# Notification to end user about what was found
|
||||
# ------------------------------------------------------------------------
|
||||
|
||||
if(Boost_FOUND)
|
||||
if(NOT Boost_FIND_QUIETLY)
|
||||
message(STATUS "Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
|
||||
endif()
|
||||
else()
|
||||
if(Boost_FIND_REQUIRED)
|
||||
message(SEND_ERROR "Unable to find the requested Boost libraries.\n${Boost_ERROR_REASON}")
|
||||
else()
|
||||
if(NOT Boost_FIND_QUIETLY)
|
||||
# we opt not to automatically output Boost_ERROR_REASON here as
|
||||
# it could be quite lengthy and somewhat imposing in its requests
|
||||
# Since Boost is not always a required dependency we'll leave this
|
||||
# up to the end-user.
|
||||
if(Boost_DEBUG OR Boost_DETAILED_FAILURE_MSG)
|
||||
message(STATUS "Could NOT find Boost\n${Boost_ERROR_REASON}")
|
||||
else()
|
||||
message(STATUS "Could NOT find Boost")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Configure display of cache entries in GUI.
|
||||
foreach(v ${_Boost_VARS_INC} ${_Boost_VARS_LIB})
|
||||
get_property(_type CACHE ${v} PROPERTY TYPE)
|
||||
if(_type)
|
||||
set_property(CACHE ${v} PROPERTY ADVANCED 1)
|
||||
if("x${_type}" STREQUAL "xUNINITIALIZED")
|
||||
if("x${v}" STREQUAL "xBoost_ADDITIONAL_VERSIONS")
|
||||
set_property(CACHE ${v} PROPERTY TYPE STRING)
|
||||
else()
|
||||
set_property(CACHE ${v} PROPERTY TYPE PATH)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Record last used values of input variables so we can
|
||||
# detect on the next run if the user changed them.
|
||||
foreach(v
|
||||
${_Boost_VARS_INC} ${_Boost_VARS_LIB}
|
||||
${_Boost_VARS_DIR} ${_Boost_VARS_NAME}
|
||||
)
|
||||
if(DEFINED ${v})
|
||||
set(_${v}_LAST "${${v}}" CACHE INTERNAL "Last used ${v} value.")
|
||||
else()
|
||||
unset(_${v}_LAST CACHE)
|
||||
endif()
|
||||
endforeach()
|
13
CMake/TestBuild.cxx.in
Normal file
13
CMake/TestBuild.cxx.in
Normal file
@ -0,0 +1,13 @@
|
||||
//mark that we are including headers as test for completeness.
|
||||
//This is used by headers that include thrust to properly define a proper
|
||||
//device backend / system
|
||||
#define VTKM_TEST_HEADER_BUILD
|
||||
|
||||
#define BOOST_SP_DISABLE_THREADS
|
||||
|
||||
#include <@dir_prefix@/@header@>
|
||||
|
||||
int Test_Build_For_@headername@()
|
||||
{
|
||||
return 0;
|
||||
}
|
245
CMake/VtkmCheckCopyright.cmake
Normal file
245
CMake/VtkmCheckCopyright.cmake
Normal file
@ -0,0 +1,245 @@
|
||||
##============================================================================
|
||||
## 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.
|
||||
##============================================================================
|
||||
|
||||
## This CMake script checks source files for the appropriate VTKM copyright
|
||||
## statement, which is stored in VTKm_SOURCE_DIR/CMake/VTKmCopyrightStatement.txt.
|
||||
## To run this script, execute CMake as follows:
|
||||
##
|
||||
## cmake -DVTKm_SOURCE_DIR=<VTKm_SOURCE_DIR> -P <VTKm_SOURCE_DIR>/CMake/VTKMCheckCopyright.cmake
|
||||
##
|
||||
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
set(FILES_TO_CHECK
|
||||
*.txt
|
||||
*.cmake
|
||||
*.h
|
||||
*.h.in
|
||||
*.cxx
|
||||
*.cu
|
||||
)
|
||||
|
||||
set(EXCEPTIONS
|
||||
LICENSE.txt
|
||||
README.txt
|
||||
)
|
||||
|
||||
if (NOT VTKm_SOURCE_DIR)
|
||||
message(SEND_ERROR "VTKm_SOURCE_DIR not defined.")
|
||||
endif (NOT VTKm_SOURCE_DIR)
|
||||
|
||||
set(copyright_file ${VTKm_SOURCE_DIR}/CMake/VTKMCopyrightStatement.txt)
|
||||
|
||||
if (NOT EXISTS ${copyright_file})
|
||||
message(SEND_ERROR "Cannot find VTKMCopyrightStatement.txt.")
|
||||
endif (NOT EXISTS ${copyright_file})
|
||||
|
||||
set(license_file ${VTKm_SOURCE_DIR}/LICENSE.txt)
|
||||
|
||||
if (NOT EXISTS ${license_file})
|
||||
message(SEND_ERROR "Cannot find LICENSE.txt.")
|
||||
endif (NOT EXISTS ${license_file})
|
||||
|
||||
# Get a list of third party files (with different copyrights) from the
|
||||
# license file.
|
||||
file(STRINGS ${license_file} license_lines)
|
||||
list(FIND
|
||||
license_lines
|
||||
"- - - - - - - - - - - - - - - - - - - - - - - - do not remove this line"
|
||||
separator_index
|
||||
)
|
||||
math(EXPR begin_index "${separator_index} + 1")
|
||||
list(LENGTH license_lines license_file_length)
|
||||
math(EXPR end_index "${license_file_length} - 1")
|
||||
foreach (index RANGE ${begin_index} ${end_index})
|
||||
list(GET license_lines ${index} tpl_file)
|
||||
set(EXCEPTIONS ${EXCEPTIONS} ${tpl_file})
|
||||
endforeach(index)
|
||||
message("${EXCEPTIONS}")
|
||||
|
||||
# Gets the current year (if possible).
|
||||
function (get_year var)
|
||||
if (UNIX)
|
||||
execute_process(COMMAND "date" "+%Y" OUTPUT_VARIABLE result)
|
||||
string(REGEX REPLACE "(....).*" "\\1" result "${result}")
|
||||
elseif (WIN32)
|
||||
execute_process(COMMAND "date" "/T" OUTPUT_VARIABLE result)
|
||||
string(REGEX REPLACE ".*../../(....).*" "\\1" result "${result}")
|
||||
else (UNIX)
|
||||
message("Don't know how to get date.")
|
||||
set(result "20XX")
|
||||
endif (UNIX)
|
||||
set(${var} "${result}" PARENT_SCOPE)
|
||||
endfunction (get_year)
|
||||
|
||||
set(copyright_file_year 2011)
|
||||
get_year(current_year)
|
||||
|
||||
# Escapes ';' characters (list delimiters) and splits the given string into
|
||||
# a list of its lines without newlines.
|
||||
function (list_of_lines var string)
|
||||
string(REGEX REPLACE ";" "\\\\;" conditioned_string "${string}")
|
||||
string(REGEX REPLACE "\n" ";" conditioned_string "${conditioned_string}")
|
||||
set(${var} "${conditioned_string}" PARENT_SCOPE)
|
||||
endfunction (list_of_lines)
|
||||
|
||||
# Read in copyright statement file.
|
||||
file(READ ${copyright_file} COPYRIGHT_STATEMENT)
|
||||
|
||||
# Remove trailing whitespace and ending lines. They are sometimes hard to
|
||||
# see or remove in editors.
|
||||
string(REGEX REPLACE "[ \t]*\n" "\n" COPYRIGHT_STATEMENT "${COPYRIGHT_STATEMENT}")
|
||||
string(REGEX REPLACE "\n+$" "" COPYRIGHT_STATEMENT "${COPYRIGHT_STATEMENT}")
|
||||
|
||||
# Get a list of lines in the copyright statement.
|
||||
list_of_lines(COPYRIGHT_LINE_LIST "${COPYRIGHT_STATEMENT}")
|
||||
|
||||
# Comment regular expression characters that we want to match literally.
|
||||
string(REPLACE "." "\\." COPYRIGHT_LINE_LIST "${COPYRIGHT_LINE_LIST}")
|
||||
string(REPLACE "(" "\\(" COPYRIGHT_LINE_LIST "${COPYRIGHT_LINE_LIST}")
|
||||
string(REPLACE ")" "\\)" COPYRIGHT_LINE_LIST "${COPYRIGHT_LINE_LIST}")
|
||||
|
||||
# Introduce regular expression for years we want to be generic.
|
||||
string(REPLACE
|
||||
"${copyright_file_year}"
|
||||
"20[0-9][0-9]"
|
||||
COPYRIGHT_LINE_LIST
|
||||
"${COPYRIGHT_LINE_LIST}"
|
||||
)
|
||||
|
||||
# Replace year in COPYRIGHT_STATEMENT with current year.
|
||||
string(REPLACE
|
||||
"${copyright_file_year}"
|
||||
"${current_year}"
|
||||
COPYRIGHT_STATEMENT
|
||||
"${COPYRIGHT_STATEMENT}"
|
||||
)
|
||||
|
||||
# Print an error concerning the missing copyright in the given file.
|
||||
function(missing_copyright filename comment_prefix)
|
||||
message("${filename} does not have the appropriate copyright statement:\n")
|
||||
|
||||
# Condition the copyright statement
|
||||
string(REPLACE
|
||||
"\n"
|
||||
"\n${comment_prefix} "
|
||||
comment_copyright
|
||||
"${COPYRIGHT_STATEMENT}"
|
||||
)
|
||||
set(comment_copyright "${comment_prefix} ${comment_copyright}")
|
||||
string(REPLACE
|
||||
"\n${comment_prefix} \n"
|
||||
"\n${comment_prefix}\n"
|
||||
comment_copyright
|
||||
"${comment_copyright}"
|
||||
)
|
||||
|
||||
message("${comment_prefix}=============================================================================")
|
||||
message("${comment_prefix}")
|
||||
message("${comment_copyright}")
|
||||
message("${comment_prefix}")
|
||||
message("${comment_prefix}=============================================================================\n")
|
||||
message(SEND_ERROR
|
||||
"Please add the previous statement to the beginning of ${filename}"
|
||||
)
|
||||
endfunction(missing_copyright)
|
||||
|
||||
# Get an appropriate beginning line comment for the given filename.
|
||||
function(get_comment_prefix var filename)
|
||||
get_filename_component(base "${filename}" NAME_WE)
|
||||
get_filename_component(extension "${filename}" EXT)
|
||||
if (extension STREQUAL ".cmake")
|
||||
set(${var} "##" PARENT_SCOPE)
|
||||
elseif (base STREQUAL "CMakeLists" AND extension STREQUAL ".txt")
|
||||
set(${var} "##" PARENT_SCOPE)
|
||||
elseif (extension STREQUAL ".txt")
|
||||
set(${var} "" PARENT_SCOPE)
|
||||
elseif (extension STREQUAL ".h" OR extension STREQUAL ".h.in" OR extension STREQUAL ".cxx" OR extension STREQUAL ".cu")
|
||||
set(${var} "//" PARENT_SCOPE)
|
||||
elseif (extension STREQUAL ".worklet")
|
||||
set(${var} "//" PARENT_SCOPE)
|
||||
else (extension STREQUAL ".cmake")
|
||||
message(SEND_ERROR "Could not identify file type of ${filename}.")
|
||||
endif (extension STREQUAL ".cmake")
|
||||
endfunction(get_comment_prefix)
|
||||
|
||||
# Check the given file for the appropriate copyright statement.
|
||||
function(check_copyright filename)
|
||||
|
||||
get_comment_prefix(comment_prefix "${filename}")
|
||||
|
||||
# Read in the first 2000 characters of the file and split into lines.
|
||||
# This is roughly equivalent to the file STRINGS command except that we
|
||||
# also escape semicolons (list separators) in the input, which the file
|
||||
# STRINGS command does not currently do.
|
||||
file(READ "${filename}" header_contents LIMIT 2000)
|
||||
list_of_lines(header_lines "${header_contents}")
|
||||
|
||||
# Check each copyright line.
|
||||
foreach (copyright_line IN LISTS COPYRIGHT_LINE_LIST)
|
||||
set(match)
|
||||
# My original algorithm tried to check the order by removing items from
|
||||
# header_lines as they were encountered. Unfortunately, CMake 2.8's
|
||||
# list REMOVE_AT command removed the escaping on the ; in one of the
|
||||
# header_line's items and cause the compare to fail.
|
||||
foreach (header_line IN LISTS header_lines)
|
||||
if (copyright_line)
|
||||
string(REGEX MATCH
|
||||
"^${comment_prefix}[ \t]*${copyright_line}[ \t]*$"
|
||||
match
|
||||
"${header_line}"
|
||||
)
|
||||
else (copyright_line)
|
||||
if (NOT header_line)
|
||||
set(match TRUE)
|
||||
endif (NOT header_line)
|
||||
endif (copyright_line)
|
||||
if (match)
|
||||
break()
|
||||
endif (match)
|
||||
endforeach (header_line)
|
||||
if (NOT match)
|
||||
message(STATUS "Could not find match for `${copyright_line}'")
|
||||
missing_copyright("${filename}" "${comment_prefix}")
|
||||
endif (NOT match)
|
||||
endforeach (copyright_line)
|
||||
endfunction(check_copyright)
|
||||
|
||||
foreach (glob_expression ${FILES_TO_CHECK})
|
||||
file(GLOB_RECURSE file_list
|
||||
RELATIVE "${VTKm_SOURCE_DIR}"
|
||||
"${VTKm_SOURCE_DIR}/${glob_expression}"
|
||||
)
|
||||
|
||||
foreach (file ${file_list})
|
||||
set(skip)
|
||||
foreach(exception ${EXCEPTIONS})
|
||||
if(file MATCHES "^${exception}(/.*)?$")
|
||||
# This file is an exception
|
||||
set(skip TRUE)
|
||||
endif(file MATCHES "^${exception}(/.*)?$")
|
||||
endforeach(exception)
|
||||
|
||||
if (NOT skip)
|
||||
message("Checking ${file}")
|
||||
check_copyright("${VTKm_SOURCE_DIR}/${file}")
|
||||
endif (NOT skip)
|
||||
endforeach (file)
|
||||
endforeach (glob_expression)
|
56
CMake/VtkmCompilerExtras.cmake
Normal file
56
CMake/VtkmCompilerExtras.cmake
Normal file
@ -0,0 +1,56 @@
|
||||
##============================================================================
|
||||
## 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.
|
||||
##============================================================================
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
set(CMAKE_COMPILER_IS_CLANGXX 1)
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
|
||||
|
||||
include(CheckCXXCompilerFlag)
|
||||
|
||||
# Standard warning flags we should always have
|
||||
set(CMAKE_CXX_FLAGS_WARN " -Wall")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
||||
"${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${CMAKE_CXX_FLAGS_WARN}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG
|
||||
"${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_WARN}")
|
||||
|
||||
# Addtional warnings for GCC
|
||||
set(CMAKE_CXX_FLAGS_WARN_EXTRA "-Wno-long-long -Wcast-align -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()
|
||||
|
||||
# Set up the debug CXX_FLAGS for extra warnings
|
||||
option(VTKM_EXTRA_COMPILER_WARNINGS "Add compiler flags to do stricter checking when building debug." ON)
|
||||
# We used to add the compiler flags globally, but this caused problems with
|
||||
# the CUDA compiler (and its lack of support for GCC pragmas). Instead,
|
||||
# the vtkm_declare_headers and vtkm_unit_tests CMake functions add these flags
|
||||
# to their compiles. As long as the unit tests have good coverage, this
|
||||
# should catch all problems.
|
||||
if(VTKM_EXTRA_COMPILER_WARNINGS)
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
||||
"${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${CMAKE_CXX_FLAGS_WARN_EXTRA}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG
|
||||
"${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_WARN_EXTRA}")
|
||||
endif()
|
||||
endif()
|
||||
|
40
CMake/VtkmConfig.cmake.in
Normal file
40
CMake/VtkmConfig.cmake.in
Normal file
@ -0,0 +1,40 @@
|
||||
##============================================================================
|
||||
## 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.
|
||||
##============================================================================
|
||||
|
||||
# This file should be installed in the include directory.
|
||||
# Find the root directory.
|
||||
get_filename_component(_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
get_filename_component(_install_dir "${_dir}/.." ABSOLUTE)
|
||||
|
||||
# The VTKm include file directories.
|
||||
set(VTKm_INCLUDE_DIRS "@VTKm_INCLUDE_DIRS_CONFIG@")
|
||||
|
||||
# The VTKm version number
|
||||
set(VTKm_MAJOR_VERSION "@VTKm_MAJOR_VERSION@")
|
||||
set(VTKm_MINOR_VERSION "@VTKm_MINOR_VERSION@")
|
||||
set(VTKm_PATCH_VERSION "@VTKm_PATCH_VERSION@")
|
||||
|
||||
set(VTKm_REQUIRED_BOOST_VERSION "@VTKm_REQUIRED_BOOST_VERSION@")
|
||||
|
||||
set(VTKm_CMAKE_MODULE_PATH "@VTKm_CMAKE_MODULE_PATH_CONFIG@")
|
||||
|
||||
# VTKm requires some CMake Find modules not included with CMake, so
|
||||
# include the CMake modules distributed with VTKm.
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${VTKm_CMAKE_MODULE_PATH})
|
10
CMake/VtkmConfigVersion.cmake.in
Normal file
10
CMake/VtkmConfigVersion.cmake.in
Normal file
@ -0,0 +1,10 @@
|
||||
set(PACKAGE_VERSION "@VTKm_VERSION@")
|
||||
|
||||
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
|
||||
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
||||
else()
|
||||
set(PACKAGE_VERSION_COMPATIBLE TRUE)
|
||||
if ("${PACKAGE_VERSION}" STREQUAL "${PACKAGE_FIND_VERSION}")
|
||||
set(PACKAGE_VERSION_EXACT TRUE)
|
||||
endif()
|
||||
endif()
|
17
CMake/VtkmCopyrightStatement.txt
Normal file
17
CMake/VtkmCopyrightStatement.txt
Normal file
@ -0,0 +1,17 @@
|
||||
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.
|
343
CMake/VtkmMacros.cmake
Normal file
343
CMake/VtkmMacros.cmake
Normal file
@ -0,0 +1,343 @@
|
||||
##============================================================================
|
||||
## 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(CMakeParseArguments)
|
||||
|
||||
# Utility to build a kit name from the current directory.
|
||||
function(vtkm_get_kit_name kitvar)
|
||||
# Will this always work? It should if ${CMAKE_CURRENT_SOURCE_DIR} is
|
||||
# built from ${VTKm_SOURCE_DIR}.
|
||||
string(REPLACE "${VTKm_SOURCE_DIR}/" "" dir_prefix ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
string(REPLACE "/" "_" kit "${dir_prefix}")
|
||||
set(${kitvar} "${kit}" PARENT_SCOPE)
|
||||
# Optional second argument to get dir_prefix.
|
||||
if (${ARGC} GREATER 1)
|
||||
set(${ARGV1} "${dir_prefix}" PARENT_SCOPE)
|
||||
endif (${ARGC} GREATER 1)
|
||||
endfunction(vtkm_get_kit_name)
|
||||
|
||||
# Builds a source file and an executable that does nothing other than
|
||||
# compile the given header files.
|
||||
function(vtkm_add_header_build_test name dir_prefix use_cuda)
|
||||
set(hfiles ${ARGN})
|
||||
if (use_cuda)
|
||||
set(suffix ".cu")
|
||||
else (use_cuda)
|
||||
set(suffix ".cxx")
|
||||
endif (use_cuda)
|
||||
set(cxxfiles)
|
||||
foreach (header ${ARGN})
|
||||
get_source_file_property(cant_be_tested ${header} VTKm_CANT_BE_HEADER_TESTED)
|
||||
|
||||
if( NOT cant_be_tested )
|
||||
string(REPLACE "${CMAKE_CURRENT_BINARY_DIR}" "" header "${header}")
|
||||
get_filename_component(headername ${header} NAME_WE)
|
||||
set(src ${CMAKE_CURRENT_BINARY_DIR}/testing/TestBuild_${name}_${headername}${suffix})
|
||||
configure_file(${VTKm_SOURCE_DIR}/CMake/TestBuild.cxx.in ${src} @ONLY)
|
||||
list(APPEND cxxfiles ${src})
|
||||
endif()
|
||||
|
||||
endforeach (header)
|
||||
|
||||
#only attempt to add a test build executable if we have any headers to
|
||||
#test. this might not happen when everything depends on thrust.
|
||||
list(LENGTH cxxfiles cxxfiles_len)
|
||||
if (use_cuda AND ${cxxfiles_len} GREATER 0)
|
||||
cuda_add_library(TestBuild_${name} ${cxxfiles} ${hfiles})
|
||||
elseif (${cxxfiles_len} GREATER 0)
|
||||
add_library(TestBuild_${name} ${cxxfiles} ${hfiles})
|
||||
if(VTKm_EXTRA_COMPILER_WARNINGS)
|
||||
set_target_properties(TestBuild_${name}
|
||||
PROPERTIES COMPILE_FLAGS ${CMAKE_CXX_FLAGS_WARN_EXTRA})
|
||||
endif(VTKm_EXTRA_COMPILER_WARNINGS)
|
||||
endif ()
|
||||
set_source_files_properties(${hfiles}
|
||||
PROPERTIES HEADER_FILE_ONLY TRUE
|
||||
)
|
||||
endfunction(vtkm_add_header_build_test)
|
||||
|
||||
function(vtkm_install_headers dir_prefix)
|
||||
set(hfiles ${ARGN})
|
||||
install(FILES ${hfiles}
|
||||
DESTINATION ${VTKm_INSTALL_INCLUDE_DIR}/${dir_prefix}
|
||||
)
|
||||
endfunction(vtkm_install_headers)
|
||||
|
||||
# Declare a list of headers that require thrust to be enabled
|
||||
# for them to header tested. In cases of thrust version 1.5 or less
|
||||
# we have to make sure openMP is enabled, otherwise we are okay
|
||||
function(vtkm_requires_thrust_to_test)
|
||||
#determine the state of thrust and testing
|
||||
set(cant_be_tested FALSE)
|
||||
if(NOT VTKm_ENABLE_THRUST)
|
||||
#mark as not valid
|
||||
set(cant_be_tested TRUE)
|
||||
elseif(NOT VTKm_ENABLE_OPENMP)
|
||||
#mark also as not valid
|
||||
set(cant_be_tested TRUE)
|
||||
endif()
|
||||
|
||||
foreach(header ${ARGN})
|
||||
#set a property on the file that marks if we can header test it
|
||||
set_source_files_properties( ${header}
|
||||
PROPERTIES VTKm_CANT_BE_HEADER_TESTED ${cant_be_tested} )
|
||||
|
||||
endforeach(header)
|
||||
|
||||
endfunction(vtkm_requires_thrust_to_test)
|
||||
|
||||
# Declare a list of header files. Will make sure the header files get
|
||||
# compiled and show up in an IDE.
|
||||
function(vtkm_declare_headers)
|
||||
set(options CUDA)
|
||||
set(oneValueArgs)
|
||||
set(multiValueArgs)
|
||||
cmake_parse_arguments(VTKm_DH "${options}"
|
||||
"${oneValueArgs}" "${multiValueArgs}"
|
||||
${ARGN}
|
||||
)
|
||||
set(hfiles ${VTKm_DH_UNPARSED_ARGUMENTS})
|
||||
vtkm_get_kit_name(name dir_prefix)
|
||||
|
||||
#only do header testing if enable testing is turned on
|
||||
if (VTKm_ENABLE_TESTING)
|
||||
vtkm_add_header_build_test(
|
||||
"${name}" "${dir_prefix}" "${VTKm_DH_CUDA}" ${hfiles})
|
||||
endif()
|
||||
#always install headers
|
||||
vtkm_install_headers("${dir_prefix}" ${hfiles})
|
||||
endfunction(vtkm_declare_headers)
|
||||
|
||||
# Declare a list of worklet files.
|
||||
function(vtkm_declare_worklets)
|
||||
# Currently worklets are just really header files.
|
||||
vtkm_declare_headers(${ARGN})
|
||||
endfunction(vtkm_declare_worklets)
|
||||
|
||||
# Declare unit tests, which should be in the same directory as a kit
|
||||
# (package, module, whatever you call it). Usage:
|
||||
#
|
||||
# vtkm_unit_tests(
|
||||
# SOURCES <source_list>
|
||||
# LIBRARIES <dependent_library_list>
|
||||
# )
|
||||
function(vtkm_unit_tests)
|
||||
set(options CUDA)
|
||||
set(oneValueArgs)
|
||||
set(multiValueArgs SOURCES LIBRARIES)
|
||||
cmake_parse_arguments(VTKm_UT
|
||||
"${options}" "${oneValueArgs}" "${multiValueArgs}"
|
||||
${ARGN}
|
||||
)
|
||||
|
||||
#set up what we possibly need to link too.
|
||||
list(APPEND VTKm_UT_LIBRARIES ${TBB_LIBRARIES})
|
||||
#set up storage for the include dirs
|
||||
set(VTKm_UT_INCLUDE_DIRS )
|
||||
|
||||
if(VTKm_ENABLE_OPENGL_INTEROP)
|
||||
list(APPEND VTKm_UT_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIR} )
|
||||
list(APPEND VTKm_UT_LIBRARIES ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES} )
|
||||
endif()
|
||||
|
||||
if(VTKm_ENABLE_OPENGL_TESTS)
|
||||
list(APPEND VTKm_UT_INCLUDE_DIRS ${GLUT_INCLUDE_DIR} )
|
||||
list(APPEND VTKm_UT_LIBRARIES ${GLUT_LIBRARIES} )
|
||||
endif()
|
||||
|
||||
if (VTKm_ENABLE_TESTING)
|
||||
vtkm_get_kit_name(kit)
|
||||
#we use UnitTests_kit_ so that it is an unique key to exclude from coverage
|
||||
set(test_prog UnitTests_kit_${kit})
|
||||
create_test_sourcelist(TestSources ${test_prog}.cxx ${VTKm_UT_SOURCES})
|
||||
if (VTKm_UT_CUDA)
|
||||
cuda_add_executable(${test_prog} ${TestSources})
|
||||
else (VTKm_UT_CUDA)
|
||||
add_executable(${test_prog} ${TestSources})
|
||||
if(VTKm_EXTRA_COMPILER_WARNINGS)
|
||||
set_target_properties(${test_prog}
|
||||
PROPERTIES COMPILE_FLAGS ${CMAKE_CXX_FLAGS_WARN_EXTRA})
|
||||
endif(VTKm_EXTRA_COMPILER_WARNINGS)
|
||||
endif (VTKm_UT_CUDA)
|
||||
|
||||
#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_UT_INCLUDE_DIRS} )
|
||||
|
||||
target_link_libraries(${test_prog} ${VTKm_UT_LIBRARIES})
|
||||
|
||||
|
||||
foreach (test ${VTKm_UT_SOURCES})
|
||||
get_filename_component(tname ${test} NAME_WE)
|
||||
add_test(NAME ${tname}
|
||||
COMMAND ${test_prog} ${tname}
|
||||
)
|
||||
endforeach (test)
|
||||
endif (VTKm_ENABLE_TESTING)
|
||||
endfunction(vtkm_unit_tests)
|
||||
|
||||
# Save the worklets to test with each device adapter
|
||||
# Usage:
|
||||
#
|
||||
# vtkm_save_worklet_unit_tests( sources )
|
||||
#
|
||||
# notes: will save the sources absolute path as the
|
||||
# vtkm_source_worklet_unit_tests global property
|
||||
function(vtkm_save_worklet_unit_tests )
|
||||
|
||||
#create the test driver when we are called, since
|
||||
#the test driver expect the test files to be in the same
|
||||
#directory as the test driver
|
||||
create_test_sourcelist(test_sources WorkletTestDriver.cxx ${ARGN})
|
||||
|
||||
#store the absolute path for the test drive and all the test
|
||||
#files
|
||||
set(driver ${CMAKE_CURRENT_BINARY_DIR}/WorkletTestDriver.cxx)
|
||||
set(cxx_sources)
|
||||
set(cu_sources)
|
||||
|
||||
#we need to store the absolute source for the file so that
|
||||
#we can properly compile it into the test driver. At
|
||||
#the same time we want to configure each file into the build
|
||||
#directory as a .cu file so that we can compile it with cuda
|
||||
#if needed
|
||||
foreach(fname ${ARGN})
|
||||
set(absPath)
|
||||
|
||||
get_filename_component(absPath ${fname} ABSOLUTE)
|
||||
get_filename_component(file_name_only ${fname} NAME_WE)
|
||||
|
||||
set(cuda_file_name "${CMAKE_CURRENT_BINARY_DIR}/${file_name_only}.cu")
|
||||
configure_file("${absPath}"
|
||||
"${cuda_file_name}"
|
||||
COPYONLY)
|
||||
list(APPEND cxx_sources ${absPath})
|
||||
list(APPEND cu_sources ${cuda_file_name})
|
||||
endforeach()
|
||||
|
||||
#we create a property that holds all the worklets to test,
|
||||
#but don't actually attempt to create a unit test with the yet.
|
||||
#That is done by each device adapter
|
||||
set_property( GLOBAL APPEND
|
||||
PROPERTY vtkm_worklet_unit_tests_sources ${cxx_sources})
|
||||
set_property( GLOBAL APPEND
|
||||
PROPERTY vtkm_worklet_unit_tests_cu_sources ${cu_sources})
|
||||
set_property( GLOBAL APPEND
|
||||
PROPERTY vtkm_worklet_unit_tests_drivers ${driver})
|
||||
|
||||
endfunction(vtkm_save_worklet_unit_tests)
|
||||
|
||||
# Call each worklet test for the given device adapter
|
||||
# Usage:
|
||||
#
|
||||
# vtkm_worklet_unit_tests( device_adapter )
|
||||
#
|
||||
# notes: will look for the vtkm_source_worklet_unit_tests global
|
||||
# property to find what are the worklet unit tests that need to be
|
||||
# compiled for the give device adapter
|
||||
function(vtkm_worklet_unit_tests device_adapter)
|
||||
|
||||
set(unit_test_srcs)
|
||||
get_property(unit_test_srcs GLOBAL
|
||||
PROPERTY vtkm_worklet_unit_tests_sources )
|
||||
|
||||
set(unit_test_drivers)
|
||||
get_property(unit_test_drivers GLOBAL
|
||||
PROPERTY vtkm_worklet_unit_tests_drivers )
|
||||
|
||||
#detect if we are generating a .cu files
|
||||
set(is_cuda FALSE)
|
||||
set(old_nvcc_flags ${CUDA_NVCC_FLAGS})
|
||||
if("${device_adapter}" STREQUAL "VTKm_DEVICE_ADAPTER_CUDA")
|
||||
set(is_cuda TRUE)
|
||||
#if we are generating cu files need to setup three things.
|
||||
#1. us the configured .cu files
|
||||
#2. Set BOOST_SP_DISABLE_THREADS to disable threading warnings
|
||||
#3. Disable unused function warnings
|
||||
#the FindCUDA module and helper methods don't read target level
|
||||
#properties so we have to modify CUDA_NVCC_FLAGS instead of using
|
||||
# target and source level COMPILE_FLAGS and COMPILE_DEFINITIONS
|
||||
#
|
||||
get_property(unit_test_srcs GLOBAL PROPERTY vtkm_worklet_unit_tests_cu_sources )
|
||||
list(APPEND CUDA_NVCC_FLAGS -DBOOST_SP_DISABLE_THREADS)
|
||||
list(APPEND CUDA_NVCC_FLAGS "-w")
|
||||
endif()
|
||||
|
||||
if(VTKm_ENABLE_TESTING)
|
||||
vtkm_get_kit_name(kit)
|
||||
set(test_prog WorkletTests_${kit})
|
||||
|
||||
if(is_cuda)
|
||||
cuda_add_executable(${test_prog} ${unit_test_drivers} ${unit_test_srcs})
|
||||
else()
|
||||
add_executable(${test_prog} ${unit_test_drivers} ${unit_test_srcs})
|
||||
endif()
|
||||
|
||||
#add a test for each worklet test file. We will inject the device
|
||||
#adapter type into the test name so that it is easier to see what
|
||||
#exact device a test is failing on.
|
||||
|
||||
string(REPLACE "VTKm_DEVICE_ADAPTER_" "" device_type ${device_adapter})
|
||||
|
||||
foreach (test ${unit_test_srcs})
|
||||
get_filename_component(tname ${test} NAME_WE)
|
||||
add_test(NAME "${tname}${device_type}"
|
||||
COMMAND ${test_prog} ${tname}
|
||||
)
|
||||
endforeach (test)
|
||||
|
||||
#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})
|
||||
endif()
|
||||
|
||||
set(CUDA_NVCC_FLAGS ${old_nvcc_flags})
|
||||
endfunction(vtkm_worklet_unit_tests)
|
||||
|
||||
# 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
|
||||
# pragmas cause errors. Thus, this macro will disable the compiler warnings.
|
||||
macro(vtkm_disable_troublesome_thrust_warnings)
|
||||
vtkm_disable_troublesome_thrust_warnings_var(CMAKE_CXX_FLAGS_DEBUG)
|
||||
vtkm_disable_troublesome_thrust_warnings_var(CMAKE_CXX_FLAGS_MINSIZEREL)
|
||||
vtkm_disable_troublesome_thrust_warnings_var(CMAKE_CXX_FLAGS_RELEASE)
|
||||
vtkm_disable_troublesome_thrust_warnings_var(CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
||||
endmacro(vtkm_disable_troublesome_thrust_warnings)
|
||||
|
||||
macro(vtkm_disable_troublesome_thrust_warnings_var flags_var)
|
||||
set(old_flags "${${flags_var}}")
|
||||
string(REPLACE "-Wshadow" "" new_flags "${old_flags}")
|
||||
string(REPLACE "-Wunused-parameter" "" new_flags "${new_flags}")
|
||||
string(REPLACE "-Wunused" "" new_flags "${new_flags}")
|
||||
string(REPLACE "-Wextra" "" new_flags "${new_flags}")
|
||||
string(REPLACE "-Wall" "" new_flags "${new_flags}")
|
||||
set(${flags_var} "${new_flags}")
|
||||
endmacro(vtkm_disable_troublesome_thrust_warnings_var)
|
156
CMakeLists.txt
Normal file
156
CMakeLists.txt
Normal file
@ -0,0 +1,156 @@
|
||||
##============================================================================
|
||||
## 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.
|
||||
##============================================================================
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.10)
|
||||
project (VTKm)
|
||||
|
||||
set(VTKm_MAJOR_VERSION 0)
|
||||
set(VTKm_MINOR_VERSION 1)
|
||||
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_CMAKE_MODULE_DIR "share/vtkm/cmake")
|
||||
|
||||
set(VTKm_REQUIRED_BOOST_VERSION 1.48.0)
|
||||
|
||||
# include some vtkm-specific cmake code.
|
||||
include(CMake/VTKmMacros.cmake)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${VTKm_SOURCE_DIR}/CMake)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# 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 supplemental compiler warnings, and GCC visibility support.
|
||||
include(CMake/VTKmCompilerExtras.cmake)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Configurable Options
|
||||
option(VTKm_ENABLE_TESTING "Enable VTKm Testing" ON)
|
||||
|
||||
option(VTKm_USE_DOUBLE_PRECISION
|
||||
"Use double precision for floating point calculations"
|
||||
OFF
|
||||
)
|
||||
option(VTKm_USE_64BIT_IDS "Use 64-bit indices." OFF)
|
||||
|
||||
if (VTKm_ENABLE_TESTING)
|
||||
enable_testing()
|
||||
include(CTest)
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
## Set the directory where the binaries will be stored
|
||||
set( EXECUTABLE_OUTPUT_PATH
|
||||
${PROJECT_BINARY_DIR}/bin
|
||||
CACHE PATH
|
||||
"Directory where all executable will be stored"
|
||||
)
|
||||
|
||||
## Set the directory where the libraries will be stored
|
||||
set( LIBRARY_OUTPUT_PATH
|
||||
${PROJECT_BINARY_DIR}/libs
|
||||
CACHE PATH
|
||||
"Directory where all the libraries will be stored"
|
||||
)
|
||||
mark_as_advanced(
|
||||
EXECUTABLE_OUTPUT_PATH
|
||||
LIBRARY_OUTPUT_PATH)
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Add test to check for copyright statement on all source files.
|
||||
if (VTKm_ENABLE_TESTING)
|
||||
add_test(NAME CopyrightStatement
|
||||
COMMAND ${CMAKE_COMMAND} "-DVTKm_SOURCE_DIR=${VTKm_SOURCE_DIR}" -P "${VTKm_SOURCE_DIR}/CMake/VTKmCheckCopyright.cmake"
|
||||
)
|
||||
endif (VTKm_ENABLE_TESTING)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Check basic type sizes.
|
||||
include(CheckTypeSize)
|
||||
|
||||
check_type_size(float VTKm_SIZE_FLOAT BUILTIN_TYPES_ONLY)
|
||||
check_type_size(double VTKm_SIZE_DOUBLE BUILTIN_TYPES_ONLY)
|
||||
check_type_size(int VTKm_SIZE_INT BUILTIN_TYPES_ONLY)
|
||||
check_type_size(long VTKm_SIZE_LONG BUILTIN_TYPES_ONLY)
|
||||
check_type_size("long long" VTKm_SIZE_LONG_LONG BUILTIN_TYPES_ONLY)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Build the configure file.
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/vtkm/internal/Configure.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/vtkm/internal/Configure.h
|
||||
@ONLY)
|
||||
vtkm_install_headers(
|
||||
vtkm/internal ${CMAKE_CURRENT_BINARY_DIR}/vtkm/internal/Configure.h)
|
||||
|
||||
|
||||
# List of Boost features used:
|
||||
# * Smart Ptr
|
||||
# * Meta programming language
|
||||
find_package(BoostHeaders ${VTKm_REQUIRED_BOOST_VERSION} REQUIRED)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Add subdirectories
|
||||
add_subdirectory(vtkm)
|
||||
|
||||
# Install the readme and license files.
|
||||
install(FILES ${VTKm_SOURCE_DIR}/README.md
|
||||
DESTINATION ${VTKm_INSTALL_CONFIG_DIR}
|
||||
RENAME VTKmREADME.md
|
||||
)
|
||||
install(FILES ${VTKm_SOURCE_DIR}/LICENSE.txt
|
||||
DESTINATION ${VTKm_INSTALL_CONFIG_DIR}
|
||||
RENAME VTKmLICENSE.txt
|
||||
)
|
||||
|
||||
# Install helper configure files.
|
||||
install(
|
||||
FILES
|
||||
${VTKm_SOURCE_DIR}/CMake/FindBoostHeaders.cmake
|
||||
DESTINATION ${VTKm_INSTALL_CMAKE_MODULE_DIR}
|
||||
)
|
||||
|
||||
# Enable CPack packaging
|
||||
set(CPACK_PACKAGE_DESCRIPTION_FILE ${VTKm_SOURCE_DIR}/README.md)
|
||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The VTKm Toolkit")
|
||||
set(CPACK_PACKAGE_NAME "VTKm")
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR ${VTKm_MAJOR_VERSION})
|
||||
set(CPACK_PACKAGE_VERSION_MINOR ${VTKm_MINOR_VERSION})
|
||||
set(CPACK_PACKAGE_VERSION_PATCH ${VTKm_PATCH_VERSION})
|
||||
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)
|
75
LICENSE.txt
Normal file
75
LICENSE.txt
Normal file
@ -0,0 +1,75 @@
|
||||
VTKm License Version 1.0
|
||||
========================================================================
|
||||
|
||||
Copyright (c) 2014,
|
||||
Sandia Corporation, Los Alamos National Security, LLC.,
|
||||
UT-Battelle, LLC., Kitware Inc., University of California Davis
|
||||
All rights reserved.
|
||||
|
||||
Sandia National Laboratories, New Mexico
|
||||
PO Box 5800
|
||||
Albuquerque, NM 87185
|
||||
USA
|
||||
|
||||
UT-Battelle
|
||||
1 Bethel Valley Rd
|
||||
Oak Ridge, TN 37830
|
||||
|
||||
Los Alamos National Security, LLC
|
||||
105 Central Park Square
|
||||
Los Alamos, NM 87544
|
||||
|
||||
Kitware Inc.
|
||||
28 Corporate Drive
|
||||
Clifton Park, NY 12065
|
||||
USA
|
||||
|
||||
University of California, Davis
|
||||
One Shields Avenue
|
||||
Davis, CA 95616
|
||||
USA
|
||||
|
||||
Under the terms of Contract DE-AC04-94AL85000, there is a
|
||||
non-exclusive license for use of this work by or on behalf of the
|
||||
U.S. Government.
|
||||
|
||||
Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||
Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
this software.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
* Neither the name of Kitware nor the names of any contributors may
|
||||
be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
========================================================================
|
||||
|
||||
The following files and directories come from third parties. Check the
|
||||
contents of these for details on the specifics of their respective
|
||||
licenses.
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - do not remove this line
|
||||
CMake/CheckCXX11Features.cmake
|
||||
CMake/FindBoostHeaders.cmake
|
||||
vtkm/testing/OptionParser.h
|
28
docs/PosterPresentation.md
Normal file
28
docs/PosterPresentation.md
Normal file
@ -0,0 +1,28 @@
|
||||
Poster & Presentation:
|
||||
|
||||
Things that we want to do.
|
||||
Things that we are going to do.
|
||||
What would we call it?
|
||||
|
||||
dynamic vs templates interfacing.
|
||||
The pull between insitu and general purpose library, where we want
|
||||
high performance
|
||||
|
||||
foundation / groundwork / experimental work
|
||||
|
||||
What are the different layers that each project fills
|
||||
|
||||
[dax] - [eavl]
|
||||
|
||||
[filter] - []
|
||||
|
||||
[worklet] -
|
||||
|
||||
Todo:
|
||||
|
||||
1. Dynamic Arrays with tuple(s)
|
||||
|
||||
2. Sum of a cell set.
|
||||
|
||||
3. [Rob] Create the basic layout with and get the basic concrete array handle
|
||||
to compile with nothing else.
|
38
vtkm/CMakeLists.txt
Normal file
38
vtkm/CMakeLists.txt
Normal file
@ -0,0 +1,38 @@
|
||||
##============================================================================
|
||||
## 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_directories(${Boost_INCLUDE_DIRS})
|
||||
|
||||
set(headers
|
||||
Types.h
|
||||
TypeTraits.h
|
||||
VectorTraits.h
|
||||
)
|
||||
|
||||
vtkm_declare_headers(${headers})
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#first add all the components vtkm that are shared between control and exec
|
||||
add_subdirectory(testing)
|
||||
add_subdirectory(internal)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#add the control and exec folders
|
||||
add_subdirectory(cont)
|
145
vtkm/TypeTraits.h
Normal file
145
vtkm/TypeTraits.h
Normal file
@ -0,0 +1,145 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_TypeTraits_h
|
||||
#define vtkm_TypeTraits_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
namespace vtkm {
|
||||
|
||||
/// Tag used to identify types that store real (floating-point) numbers. A
|
||||
/// TypeTraits class will typedef this class to NumericTag if it stores real
|
||||
/// numbers (or vectors of real numbers).
|
||||
///
|
||||
struct TypeTraitsRealTag {};
|
||||
|
||||
/// Tag used to identify types that store integer numbers. A TypeTraits class
|
||||
/// will typedef this class to NumericTag if it stores integer numbers (or
|
||||
/// vectors of integers).
|
||||
///
|
||||
struct TypeTraitsIntegerTag {};
|
||||
|
||||
/// Tag used to identify 0 dimensional types (scalars). Scalars can also be
|
||||
/// treated like vectors when used with VectorTraits. A TypeTraits class will
|
||||
/// typedef this class to DimensionalityTag.
|
||||
///
|
||||
struct TypeTraitsScalarTag {};
|
||||
|
||||
/// Tag used to identify 1 dimensional types (vectors). A TypeTraits class will
|
||||
/// typedef this class to DimensionalityTag.
|
||||
///
|
||||
struct TypeTraitsVectorTag {};
|
||||
|
||||
template<typename T> struct TypeTraits;
|
||||
|
||||
#ifdef VTKM_DOXYGEN_ONLY
|
||||
|
||||
/// The TypeTraits class provides helpful compile-time information about the
|
||||
/// basic types used in VTKm (and a few others for convienience). The majority
|
||||
/// of TypeTraits contents are typedefs to tags that can be used to easily
|
||||
/// override behavior of called functions.
|
||||
///
|
||||
template<typename T>
|
||||
class TypeTraits {
|
||||
typedef int tag_type; // Shut up, test compile.
|
||||
public:
|
||||
|
||||
/// \brief A tag to determing whether the type is integer or real.
|
||||
///
|
||||
/// This tag is either TypeTraitsRealTag or TypeTraitsIntegerTag.
|
||||
typedef tag_type NumericTag;
|
||||
|
||||
/// \brief A tag to determine whether the type has multiple components.
|
||||
///
|
||||
/// This tag is either TypeTraitsScalarTag or TypeTraitsVectorTag. Scalars can
|
||||
/// also be treated as vectors.
|
||||
typedef tag_type DimensionalityTag;
|
||||
};
|
||||
|
||||
#endif //VTKM_DOXYGEN_ONLY
|
||||
|
||||
// Const types should have the same traits as their non-const counterparts.
|
||||
//
|
||||
template<typename T>
|
||||
struct TypeTraits<const T> : TypeTraits<T>
|
||||
{ };
|
||||
|
||||
#define VTKM_BASIC_REAL_TYPE(T) \
|
||||
template<> struct TypeTraits<T> { \
|
||||
typedef TypeTraitsRealTag NumericTag; \
|
||||
typedef TypeTraitsScalarTag DimensionalityTag; \
|
||||
}
|
||||
|
||||
#define VTKM_BASIC_INTEGER_TYPE(T) \
|
||||
template<> struct TypeTraits<T> { \
|
||||
typedef TypeTraitsIntegerTag NumericTag; \
|
||||
typedef TypeTraitsScalarTag DimensionalityTag; \
|
||||
}
|
||||
|
||||
/// Traits for basic C++ types.
|
||||
///
|
||||
|
||||
VTKM_BASIC_REAL_TYPE(float);
|
||||
VTKM_BASIC_REAL_TYPE(double);
|
||||
VTKM_BASIC_INTEGER_TYPE(char);
|
||||
VTKM_BASIC_INTEGER_TYPE(unsigned char);
|
||||
VTKM_BASIC_INTEGER_TYPE(short);
|
||||
VTKM_BASIC_INTEGER_TYPE(unsigned short);
|
||||
VTKM_BASIC_INTEGER_TYPE(int);
|
||||
VTKM_BASIC_INTEGER_TYPE(unsigned int);
|
||||
#if VTKM_SIZE_LONG == 8
|
||||
VTKM_BASIC_INTEGER_TYPE(long);
|
||||
VTKM_BASIC_INTEGER_TYPE(unsigned long);
|
||||
#elif VTKM_SIZE_LONG_LONG == 8
|
||||
VTKM_BASIC_INTEGER_TYPE(long long);
|
||||
VTKM_BASIC_INTEGER_TYPE(unsigned long long);
|
||||
#else
|
||||
#error No implementation for 64-bit integer traits.
|
||||
#endif
|
||||
|
||||
#undef VTKM_BASIC_REAL_TYPE
|
||||
#undef VTKM_BASIC_INTEGER_TYPE
|
||||
|
||||
#define VTKM_VECTOR_TYPE(T, NTag) \
|
||||
template<> struct TypeTraits<T> { \
|
||||
typedef NTag NumericTag; \
|
||||
typedef TypeTraitsVectorTag DimensionalityTag; \
|
||||
}
|
||||
|
||||
/// Traits for vector types.
|
||||
///
|
||||
|
||||
VTKM_VECTOR_TYPE(vtkm::Id3, TypeTraitsIntegerTag);
|
||||
VTKM_VECTOR_TYPE(vtkm::Vector2, TypeTraitsRealTag);
|
||||
VTKM_VECTOR_TYPE(vtkm::Vector3, TypeTraitsRealTag);
|
||||
VTKM_VECTOR_TYPE(vtkm::Vector4, TypeTraitsRealTag);
|
||||
|
||||
#undef VTKM_VECTOR_TYPE
|
||||
|
||||
/// Traits for tuples.
|
||||
///
|
||||
template<typename T, int Size> struct TypeTraits<vtkm::Tuple<T, Size> > {
|
||||
typedef typename TypeTraits<T>::NumericTag NumericTag;
|
||||
typedef TypeTraitsVectorTag DimensionalityTag;
|
||||
};
|
||||
|
||||
} // namespace vtkm
|
||||
|
||||
#endif //vtkm_TypeTraits_h
|
704
vtkm/Types.h
Normal file
704
vtkm/Types.h
Normal file
@ -0,0 +1,704 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_Types_h
|
||||
#define vtkm_Types_h
|
||||
|
||||
#include <vtkm/internal/Configure.h>
|
||||
#include <vtkm/internal/ExportMacros.h>
|
||||
|
||||
/*!
|
||||
* \namespace vtkm
|
||||
* \brief VTKm Toolkit.
|
||||
*
|
||||
* vtkm is the namespace for the VTKm Toolkit. It contains other sub namespaces,
|
||||
* as well as basic data types and functions callable from all components in VTKm
|
||||
* toolkit.
|
||||
*
|
||||
* \namespace vtkm::cont
|
||||
* \brief VTKm Control Environment.
|
||||
*
|
||||
* vtkm::cont defines the publicly accessible API for the VTKm Control
|
||||
* Environment. Users of the VTKm Toolkit can use this namespace to access the
|
||||
* Control Environment.
|
||||
*
|
||||
* \namespace vtkm::cuda
|
||||
* \brief CUDA implementation.
|
||||
*
|
||||
* vtkm::cuda includes the code to implement the VTKm for CUDA-based platforms.
|
||||
*
|
||||
* \namespace vtkm::cuda::cont
|
||||
* \brief CUDA implementation for Control Environment.
|
||||
*
|
||||
* vtkm::cuda::cont includes the code to implement the VTKm Control Environment
|
||||
* for CUDA-based platforms.
|
||||
*
|
||||
* \namespace vtkm::cuda::exec
|
||||
* \brief CUDA implementation for Execution Environment.
|
||||
*
|
||||
* vtkm::cuda::exec includes the code to implement the VTKm Execution Environment
|
||||
* for CUDA-based platforms.
|
||||
*
|
||||
* \namespace vtkm::exec
|
||||
* \brief VTKm Execution Environment.
|
||||
*
|
||||
* vtkm::exec defines the publicly accessible API for the VTKm Execution
|
||||
* Environment. Worklets typically use classes/apis defined within this
|
||||
* namespace alone.
|
||||
*
|
||||
* \namespace vtkm::internal
|
||||
* \brief VTKm Internal Environment
|
||||
*
|
||||
* vtkm::internal defines API which is internal and subject to frequent
|
||||
* change. This should not be used for projects using VTKm. Instead it servers
|
||||
* are a reference for the developers of VTKm.
|
||||
*
|
||||
* \namespace vtkm::math
|
||||
* \brief Utility math functions
|
||||
*
|
||||
* vtkm::math defines the publicly accessible API for Utility Math functions.
|
||||
*
|
||||
* \namespace vtkm::testing
|
||||
* \brief Internal testing classes
|
||||
*
|
||||
*/
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
//*****************************************************************************
|
||||
// Typedefs for basic types.
|
||||
//*****************************************************************************
|
||||
|
||||
/// Alignment requirements are prescribed by CUDA on device (Table B-1 in NVIDIA
|
||||
/// CUDA C Programming Guide 4.0)
|
||||
|
||||
namespace internal {
|
||||
|
||||
#if VTKM_SIZE_INT == 4
|
||||
typedef int Int32Type;
|
||||
typedef unsigned int UInt32Type;
|
||||
#else
|
||||
#error Could not find a 32-bit integer.
|
||||
#endif
|
||||
|
||||
#if VTKM_SIZE_LONG == 8
|
||||
typedef long Int64Type;
|
||||
typedef unsigned long UInt64Type;
|
||||
#elif VTKM_SIZE_LONG_LONG == 8
|
||||
typedef long long Int64Type;
|
||||
typedef unsigned long long UInt64Type;
|
||||
#else
|
||||
#error Could not find a 64-bit integer.
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template<int Size>
|
||||
struct equals
|
||||
{
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT bool operator()(const T& a, const T& b) const
|
||||
{
|
||||
return equals<Size-1>()(a,b) && a[Size-1] == b[Size-1];
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct equals<1>
|
||||
{
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT bool operator()(const T& a, const T& b) const
|
||||
{
|
||||
return a[0] == b[0];
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct equals<2>
|
||||
{
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT bool operator()(const T& a, const T& b) const
|
||||
{
|
||||
return a[0] == b[0] && a[1] == b[1];
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct equals<3>
|
||||
{
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT bool operator()(const T& a, const T& b) const
|
||||
{
|
||||
return a[0] == b[0] && a[1] == b[1] && a[2] == b[2];
|
||||
}
|
||||
};
|
||||
|
||||
template<int Size>
|
||||
struct assign_scalar_to_vector
|
||||
{
|
||||
template<typename VectorType, typename ComponentType>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
void operator()(VectorType &dest, const ComponentType &src)
|
||||
{
|
||||
assign_scalar_to_vector<Size-1>()(dest, src);
|
||||
dest[Size-1] = src;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct assign_scalar_to_vector<1>
|
||||
{
|
||||
template<typename VectorType, typename ComponentType>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
void operator()(VectorType &dest, const ComponentType &src)
|
||||
{
|
||||
dest[0] = src;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct assign_scalar_to_vector<2>
|
||||
{
|
||||
template<typename VectorType, typename ComponentType>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
void operator()(VectorType &dest, const ComponentType &src)
|
||||
{
|
||||
dest[0] = src; dest[1] = src;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct assign_scalar_to_vector<3>
|
||||
{
|
||||
template<typename VectorType, typename ComponentType>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
void operator()(VectorType &dest, const ComponentType &src)
|
||||
{
|
||||
dest[0] = src; dest[1] = src; dest[2] = src;
|
||||
}
|
||||
};
|
||||
|
||||
template<int Size>
|
||||
struct copy_vector
|
||||
{
|
||||
template<typename T1, typename T2>
|
||||
VTKM_EXEC_CONT_EXPORT void operator()(T1 &dest, const T2 &src)
|
||||
{
|
||||
copy_vector<Size-1>()(dest, src);
|
||||
dest[Size-1] = src[Size-1];
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct copy_vector<1>
|
||||
{
|
||||
template<typename T1, typename T2>
|
||||
VTKM_EXEC_CONT_EXPORT void operator()(T1 &dest, const T2 &src)
|
||||
{
|
||||
dest[0] = src[0];
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct copy_vector<2>
|
||||
{
|
||||
template<typename T1, typename T2>
|
||||
VTKM_EXEC_CONT_EXPORT void operator()(T1 &dest, const T2 &src)
|
||||
{
|
||||
dest[0] = src[0]; dest[1] = src[1];
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct copy_vector<3>
|
||||
{
|
||||
template<typename T1, typename T2>
|
||||
VTKM_EXEC_CONT_EXPORT void operator()(T1 &dest, const T2 &src)
|
||||
{
|
||||
dest[0] = src[0]; dest[1] = src[1]; dest[2] = src[2];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace internal
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if VTKM_SIZE_ID == 4
|
||||
|
||||
/// Represents an ID.
|
||||
typedef internal::Int32Type Id __attribute__ ((aligned(VTKM_SIZE_ID)));
|
||||
|
||||
#elif VTKM_SIZE_ID == 8
|
||||
|
||||
/// Represents an ID.
|
||||
typedef internal::Int64Type Id __attribute__ ((aligned(VTKM_SIZE_ID)));
|
||||
|
||||
#else
|
||||
#error Unknown Id Size
|
||||
#endif
|
||||
|
||||
#ifdef VTKM_USE_DOUBLE_PRECISION
|
||||
|
||||
/// Scalar corresponds to a floating point number.
|
||||
typedef double Scalar __attribute__ ((aligned(VTKM_SIZE_SCALAR)));
|
||||
|
||||
#else //VTKM_USE_DOUBLE_PRECISION
|
||||
|
||||
/// Scalar corresponds to a floating point number.
|
||||
typedef float Scalar __attribute__ ((aligned(VTKM_SIZE_SCALAR)));
|
||||
|
||||
#endif //VTKM_USE_DOUBLE_PRECISION
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/// Tuple corresponds to a Size-tuple of type T
|
||||
template<typename T, int Size>
|
||||
class Tuple {
|
||||
public:
|
||||
typedef T ComponentType;
|
||||
static const int NUM_COMPONENTS=Size;
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT Tuple(){}
|
||||
VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value)
|
||||
{
|
||||
for(int i=0; i < NUM_COMPONENTS;++i)
|
||||
{
|
||||
this->Components[i]=value;
|
||||
}
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType* values)
|
||||
{
|
||||
for(int i=0; i < NUM_COMPONENTS;++i)
|
||||
{
|
||||
this->Components[i]=values[i];
|
||||
}
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
Tuple(const Tuple<ComponentType, Size> &src)
|
||||
{
|
||||
for (int i = 0; i < NUM_COMPONENTS; i++)
|
||||
{
|
||||
this->Components[i] = src[i];
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
Tuple<ComponentType, Size> &operator=(const Tuple<ComponentType, Size> &src)
|
||||
{
|
||||
for (int i = 0; i < NUM_COMPONENTS; i++)
|
||||
{
|
||||
this->Components[i] = src[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT const ComponentType &operator[](int idx) const {
|
||||
return this->Components[idx];
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT ComponentType &operator[](int idx) {
|
||||
return this->Components[idx];
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
bool operator==(const Tuple<T,NUM_COMPONENTS> &other) const
|
||||
{
|
||||
bool same = true;
|
||||
for (int componentIndex=0; componentIndex<NUM_COMPONENTS; componentIndex++)
|
||||
{
|
||||
same &= (this->Components[componentIndex] == other[componentIndex]);
|
||||
}
|
||||
return same;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
bool operator<(const Tuple<T,NUM_COMPONENTS> &other) const
|
||||
{
|
||||
for(vtkm::Id i=0; i < NUM_COMPONENTS; ++i)
|
||||
{
|
||||
//ignore equals as that represents check next value
|
||||
if(this->Components[i] < other[i])
|
||||
return true;
|
||||
else if(other[i] < this->Components[i])
|
||||
return false;
|
||||
} //if all same we are not less
|
||||
return false;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
bool operator!=(const Tuple<T,NUM_COMPONENTS> &other) const
|
||||
{
|
||||
return !(this->operator==(other));
|
||||
}
|
||||
|
||||
protected:
|
||||
ComponentType Components[NUM_COMPONENTS];
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Specializations for common tuple sizes (with special names).
|
||||
|
||||
template<typename T>
|
||||
class Tuple<T,2>{
|
||||
public:
|
||||
typedef T ComponentType;
|
||||
static const int NUM_COMPONENTS = 2;
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT Tuple(){}
|
||||
VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value)
|
||||
{
|
||||
internal::assign_scalar_to_vector<NUM_COMPONENTS>()(this->Components,value);
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType* values)
|
||||
{
|
||||
internal::copy_vector<NUM_COMPONENTS>()(this->Components, values);
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT Tuple(ComponentType x, ComponentType y) {
|
||||
this->Components[0] = x;
|
||||
this->Components[1] = y;
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
Tuple(const Tuple<ComponentType, NUM_COMPONENTS> &src)
|
||||
{
|
||||
internal::copy_vector<NUM_COMPONENTS>()(this->Components, src.Components);
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
Tuple<ComponentType, NUM_COMPONENTS> &
|
||||
operator=(const Tuple<ComponentType, NUM_COMPONENTS> &src)
|
||||
{
|
||||
internal::copy_vector<NUM_COMPONENTS>()(this->Components, src.Components);
|
||||
return *this;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT const ComponentType &operator[](int idx) const {
|
||||
return this->Components[idx];
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT ComponentType &operator[](int idx) {
|
||||
return this->Components[idx];
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
bool operator==(const Tuple<T,NUM_COMPONENTS> &other) const
|
||||
{
|
||||
return internal::equals<NUM_COMPONENTS>()(*this, other);
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
bool operator!=(const Tuple<T,NUM_COMPONENTS> &other) const
|
||||
{
|
||||
return !(this->operator==(other));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
bool operator<(const Tuple<T,NUM_COMPONENTS> &other) const
|
||||
{
|
||||
return( (this->Components[0] < other[0]) ||
|
||||
(!(other[0] < this->Components[0]) && (this->Components[1] < other[1]))
|
||||
);
|
||||
}
|
||||
|
||||
protected:
|
||||
ComponentType Components[NUM_COMPONENTS];
|
||||
};
|
||||
|
||||
/// Vector2 corresponds to a 2-tuple
|
||||
typedef vtkm::Tuple<vtkm::Scalar,2>
|
||||
Vector2 __attribute__ ((aligned(VTKM_ALIGNMENT_TWO_SCALAR)));
|
||||
|
||||
|
||||
/// Id2 corresponds to a 2-dimensional index
|
||||
typedef vtkm::Tuple<vtkm::Id,2> Id2 __attribute__ ((aligned(VTKM_SIZE_ID)));
|
||||
|
||||
template<typename T>
|
||||
class Tuple<T,3>{
|
||||
public:
|
||||
typedef T ComponentType;
|
||||
static const int NUM_COMPONENTS = 3;
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT Tuple(){}
|
||||
VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value)
|
||||
{
|
||||
internal::assign_scalar_to_vector<NUM_COMPONENTS>()(this->Components,value);
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType* values)
|
||||
{
|
||||
internal::copy_vector<NUM_COMPONENTS>()(this->Components, values);
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
Tuple(ComponentType x, ComponentType y, ComponentType z) {
|
||||
this->Components[0] = x;
|
||||
this->Components[1] = y;
|
||||
this->Components[2] = z;
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
Tuple(const Tuple<ComponentType, NUM_COMPONENTS> &src)
|
||||
{
|
||||
internal::copy_vector<NUM_COMPONENTS>()(this->Components, src.Components);
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
Tuple<ComponentType, NUM_COMPONENTS> &
|
||||
operator=(const Tuple<ComponentType, NUM_COMPONENTS> &src)
|
||||
{
|
||||
internal::copy_vector<NUM_COMPONENTS>()(this->Components, src.Components);
|
||||
return *this;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT const ComponentType &operator[](int idx) const {
|
||||
return this->Components[idx];
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT ComponentType &operator[](int idx) {
|
||||
return this->Components[idx];
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
bool operator==(const Tuple<T,NUM_COMPONENTS> &other) const
|
||||
{
|
||||
return internal::equals<NUM_COMPONENTS>()(*this, other);
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
bool operator!=(const Tuple<T,NUM_COMPONENTS> &other) const
|
||||
{
|
||||
return !(this->operator==(other));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
bool operator<(const Tuple<T,NUM_COMPONENTS> &other) const
|
||||
{
|
||||
return((this->Components[0] < other[0]) ||
|
||||
( !(other[0] < this->Components[0]) &&
|
||||
(this->Components[1] < other[1])) ||
|
||||
( !(other[0] < this->Components[0]) &&
|
||||
!(other[1] < this->Components[1]) &&
|
||||
(this->Components[2] < other[2]) ) );
|
||||
}
|
||||
|
||||
protected:
|
||||
ComponentType Components[NUM_COMPONENTS];
|
||||
};
|
||||
|
||||
/// Vector3 corresponds to a 3-tuple
|
||||
typedef vtkm::Tuple<vtkm::Scalar,3>
|
||||
Vector3 __attribute__ ((aligned(VTKM_SIZE_SCALAR)));
|
||||
|
||||
template<typename T>
|
||||
class Tuple<T,4>{
|
||||
public:
|
||||
typedef T ComponentType;
|
||||
static const int NUM_COMPONENTS = 4;
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT Tuple(){}
|
||||
VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value)
|
||||
{
|
||||
internal::assign_scalar_to_vector<NUM_COMPONENTS>()(this->Components,value);
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType* values)
|
||||
{
|
||||
internal::copy_vector<NUM_COMPONENTS>()(this->Components, values);
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
Tuple(ComponentType x, ComponentType y, ComponentType z, ComponentType w) {
|
||||
this->Components[0] = x;
|
||||
this->Components[1] = y;
|
||||
this->Components[2] = z;
|
||||
this->Components[3] = w;
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
Tuple(const Tuple<ComponentType, NUM_COMPONENTS> &src)
|
||||
{
|
||||
internal::copy_vector<NUM_COMPONENTS>()(this->Components, src.Components);
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
Tuple<ComponentType, NUM_COMPONENTS> &
|
||||
operator=(const Tuple<ComponentType, NUM_COMPONENTS> &src)
|
||||
{
|
||||
internal::copy_vector<NUM_COMPONENTS>()(this->Components, src.Components);
|
||||
return *this;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT const ComponentType &operator[](int idx) const {
|
||||
return this->Components[idx];
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT ComponentType &operator[](int idx) {
|
||||
return this->Components[idx];
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
bool operator==(const Tuple<T,NUM_COMPONENTS> &other) const
|
||||
{
|
||||
return internal::equals<NUM_COMPONENTS>()(*this, other);
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
bool operator!=(const Tuple<T,NUM_COMPONENTS> &other) const
|
||||
{
|
||||
return !(this->operator==(other));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
bool operator<(const Tuple<T,NUM_COMPONENTS> &other) const
|
||||
{
|
||||
return((this->Components[0] < other[0]) ||
|
||||
( !(other[0] < this->Components[0]) &&
|
||||
this->Components[1] < other[1]) ||
|
||||
( !(other[0] < this->Components[0]) &&
|
||||
!(other[1] < this->Components[1]) &&
|
||||
(this->Components[2] < other[2]) ) ||
|
||||
( !(other[0] < this->Components[0]) &&
|
||||
!(other[1] < this->Components[1]) &&
|
||||
!(other[2] < this->Components[2]) &&
|
||||
(this->Components[3] < other[3])) );
|
||||
}
|
||||
|
||||
protected:
|
||||
ComponentType Components[NUM_COMPONENTS];
|
||||
};
|
||||
|
||||
/// Vector4 corresponds to a 4-tuple
|
||||
typedef vtkm::Tuple<vtkm::Scalar,4>
|
||||
Vector4 __attribute__ ((aligned(VTKM_ALIGNMENT_FOUR_SCALAR)));
|
||||
|
||||
|
||||
/// Id3 corresponds to a 3-dimensional index for 3d arrays. Note that
|
||||
/// the precision of each index may be less than vtkm::Id.
|
||||
typedef vtkm::Tuple<vtkm::Id,3> Id3 __attribute__ ((aligned(VTKM_SIZE_ID)));
|
||||
|
||||
/// Initializes and returns a Vector2.
|
||||
VTKM_EXEC_CONT_EXPORT vtkm::Vector2 make_Vector2(vtkm::Scalar x,
|
||||
vtkm::Scalar y)
|
||||
{
|
||||
return vtkm::Vector2(x, y);
|
||||
}
|
||||
|
||||
/// Initializes and returns a Vector3.
|
||||
VTKM_EXEC_CONT_EXPORT vtkm::Vector3 make_Vector3(vtkm::Scalar x,
|
||||
vtkm::Scalar y,
|
||||
vtkm::Scalar z)
|
||||
{
|
||||
return vtkm::Vector3(x, y, z);
|
||||
}
|
||||
|
||||
/// Initializes and returns a Vector4.
|
||||
VTKM_EXEC_CONT_EXPORT vtkm::Vector4 make_Vector4(vtkm::Scalar x,
|
||||
vtkm::Scalar y,
|
||||
vtkm::Scalar z,
|
||||
vtkm::Scalar w)
|
||||
{
|
||||
return vtkm::Vector4(x, y, z, w);
|
||||
}
|
||||
|
||||
/// Initializes and returns an Id3
|
||||
VTKM_EXEC_CONT_EXPORT vtkm::Id3 make_Id3(vtkm::Id x, vtkm::Id y, vtkm::Id z)
|
||||
{
|
||||
return vtkm::Id3(x, y, z);
|
||||
}
|
||||
|
||||
template<typename T, int Size>
|
||||
VTKM_EXEC_CONT_EXPORT T dot(const vtkm::Tuple<T,Size> &a,
|
||||
const vtkm::Tuple<T,Size> &b)
|
||||
{
|
||||
T result = a[0]*b[0];
|
||||
for (int componentIndex = 1; componentIndex < Size; componentIndex++)
|
||||
{
|
||||
result += a[componentIndex]*b[componentIndex];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT vtkm::Id dot(vtkm::Id a, vtkm::Id b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT vtkm::Scalar dot(vtkm::Scalar a, vtkm::Scalar b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
|
||||
} // End of namespace vtkm
|
||||
|
||||
template<typename T, int Size>
|
||||
VTKM_EXEC_CONT_EXPORT vtkm::Tuple<T,Size> operator+(const vtkm::Tuple<T,Size> &a,
|
||||
const vtkm::Tuple<T,Size> &b)
|
||||
{
|
||||
vtkm::Tuple<T,Size> result;
|
||||
for (int componentIndex = 0; componentIndex < Size; componentIndex++)
|
||||
{
|
||||
result[componentIndex] = a[componentIndex] + b[componentIndex];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
template<typename T, int Size>
|
||||
VTKM_EXEC_CONT_EXPORT vtkm::Tuple<T,Size> operator-(const vtkm::Tuple<T,Size> &a,
|
||||
const vtkm::Tuple<T,Size> &b)
|
||||
{
|
||||
vtkm::Tuple<T,Size> result;
|
||||
for (int componentIndex = 0; componentIndex < Size; componentIndex++)
|
||||
{
|
||||
result[componentIndex] = a[componentIndex] - b[componentIndex];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
template<typename T, int Size>
|
||||
VTKM_EXEC_CONT_EXPORT vtkm::Tuple<T,Size> operator*(const vtkm::Tuple<T,Size> &a,
|
||||
const vtkm::Tuple<T,Size> &b)
|
||||
{
|
||||
vtkm::Tuple<T,Size> result;
|
||||
for (int componentIndex = 0; componentIndex < Size; componentIndex++)
|
||||
{
|
||||
result[componentIndex] = a[componentIndex] * b[componentIndex];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
template<typename T, int Size>
|
||||
VTKM_EXEC_CONT_EXPORT vtkm::Tuple<T,Size> operator/(const vtkm::Tuple<T,Size> &a,
|
||||
const vtkm::Tuple<T,Size> &b)
|
||||
{
|
||||
vtkm::Tuple<T,Size> result;
|
||||
for (int componentIndex = 0; componentIndex < Size; componentIndex++)
|
||||
{
|
||||
result[componentIndex] = a[componentIndex] / b[componentIndex];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename Ta, typename Tb, int Size>
|
||||
VTKM_EXEC_CONT_EXPORT vtkm::Tuple<Ta,Size> operator*(const vtkm::Tuple<Ta,Size> &a,
|
||||
const Tb &b)
|
||||
{
|
||||
vtkm::Tuple<Ta,Size> result;
|
||||
for (int componentIndex = 0; componentIndex < Size; componentIndex++)
|
||||
{
|
||||
result[componentIndex] = a[componentIndex] * b;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
template<typename Ta, typename Tb, int Size>
|
||||
VTKM_EXEC_CONT_EXPORT vtkm::Tuple<Tb,Size> operator*(const Ta &a,
|
||||
const vtkm::Tuple<Tb,Size> &b)
|
||||
{
|
||||
vtkm::Tuple<Tb,Size> result;
|
||||
for (int componentIndex = 0; componentIndex < Size; componentIndex++)
|
||||
{
|
||||
result[componentIndex] = a * b[componentIndex];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif //vtkm_Types_h
|
222
vtkm/VectorTraits.h
Normal file
222
vtkm/VectorTraits.h
Normal file
@ -0,0 +1,222 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_VectorTraits_h
|
||||
#define vtkm_VectorTraits_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
|
||||
namespace vtkm {
|
||||
|
||||
/// A tag for vectors that are "true" vectors (i.e. have more than one
|
||||
/// component).
|
||||
///
|
||||
struct VectorTraitsTagMultipleComponents { };
|
||||
|
||||
/// A tag for vectors that a really just scalars (i.e. have only one component)
|
||||
///
|
||||
struct VectorTraitsTagSingleComponent { };
|
||||
|
||||
namespace internal {
|
||||
|
||||
template<int numComponents>
|
||||
struct VectorTraitsMultipleComponentChooser {
|
||||
typedef VectorTraitsTagMultipleComponents Type;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct VectorTraitsMultipleComponentChooser<1> {
|
||||
typedef VectorTraitsTagSingleComponent Type;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/// The VectorTraits class gives several static members that define how
|
||||
/// to use a given type as a vector.
|
||||
///
|
||||
template<class VectorType>
|
||||
struct VectorTraits
|
||||
#ifdef VTKM_DOXYGEN_ONLY
|
||||
{
|
||||
/// Type of the components in the vector.
|
||||
///
|
||||
typedef typename VectorType::ComponentType ComponentType;
|
||||
|
||||
/// Number of components in the vector.
|
||||
///
|
||||
static const int NUM_COMPONENTS = VectorType::NUM_COMPONENTS;
|
||||
|
||||
/// A tag specifying whether this vector has multiple components (i.e. is a
|
||||
/// "real" vector). This tag can be useful for creating specialized functions
|
||||
/// when a vector is really just a scalar.
|
||||
///
|
||||
typedef typename internal::VectorTraitsMultipleComponentChooser<
|
||||
NUM_COMPONENTS>::Type HasMultipleComponents;
|
||||
|
||||
/// Returns the value in a given component of the vector.
|
||||
///
|
||||
VTKM_EXEC_CONT_EXPORT static const ComponentType &GetComponent(
|
||||
const typename boost::remove_const<VectorType>::type &vector,
|
||||
int component);
|
||||
VTKM_EXEC_CONT_EXPORT static ComponentType &GetComponent(
|
||||
typename boost::remove_const<VectorType>::type &vector,
|
||||
int component);
|
||||
|
||||
/// Changes the value in a given component of the vector.
|
||||
///
|
||||
VTKM_EXEC_CONT_EXPORT static void SetComponent(VectorType &vector,
|
||||
int component,
|
||||
ComponentType value);
|
||||
|
||||
/// Converts whatever type this vector is into the standard VTKm Tuple.
|
||||
///
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static vtkm::Tuple<ComponentType,NUM_COMPONENTS>
|
||||
ToTuple(const VectorType &vector);
|
||||
};
|
||||
#else // VTKM_DOXYGEN_ONLY
|
||||
;
|
||||
#endif // VTKM_DOXYGEN_ONLY
|
||||
|
||||
// This partial specialization allows you to define a non-const version of
|
||||
// VectorTraits and have it still work for const version.
|
||||
//
|
||||
template<typename T>
|
||||
struct VectorTraits<const T> : VectorTraits<T>
|
||||
{ };
|
||||
|
||||
template<typename T, int Size>
|
||||
struct VectorTraits<vtkm::Tuple<T,Size> >
|
||||
{
|
||||
typedef vtkm::Tuple<T,Size> VectorType;
|
||||
|
||||
/// Type of the components in the vector.
|
||||
///
|
||||
typedef typename VectorType::ComponentType ComponentType;
|
||||
|
||||
/// Number of components in the vector.
|
||||
///
|
||||
static const int NUM_COMPONENTS = VectorType::NUM_COMPONENTS;
|
||||
|
||||
/// A tag specifying whether this vector has multiple components (i.e. is a
|
||||
/// "real" vector). This tag can be useful for creating specialized functions
|
||||
/// when a vector is really just a scalar.
|
||||
///
|
||||
typedef typename internal::VectorTraitsMultipleComponentChooser<
|
||||
NUM_COMPONENTS>::Type HasMultipleComponents;
|
||||
|
||||
/// Returns the value in a given component of the vector.
|
||||
///
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static const ComponentType &GetComponent(const VectorType &vector,
|
||||
int component)
|
||||
{
|
||||
return vector[component];
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static ComponentType &GetComponent(VectorType &vector, int component) {
|
||||
return vector[component];
|
||||
}
|
||||
|
||||
/// Changes the value in a given component of the vector.
|
||||
///
|
||||
VTKM_EXEC_CONT_EXPORT static void SetComponent(VectorType &vector,
|
||||
int component,
|
||||
ComponentType value) {
|
||||
vector[component] = value;
|
||||
}
|
||||
|
||||
/// Converts whatever type this vector is into the standard VTKm Tuple.
|
||||
///
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static vtkm::Tuple<ComponentType,NUM_COMPONENTS>
|
||||
ToTuple(const VectorType &vector)
|
||||
{
|
||||
return vector;
|
||||
}
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
/// Used for overriding VectorTraits for basic scalar types.
|
||||
///
|
||||
template<typename ScalarType>
|
||||
struct VectorTraitsBasic {
|
||||
typedef ScalarType ComponentType;
|
||||
static const int NUM_COMPONENTS = 1;
|
||||
typedef VectorTraitsTagSingleComponent HasMultipleComponents;
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT static const ComponentType &GetComponent(
|
||||
const ScalarType &vector,
|
||||
int) {
|
||||
return vector;
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static ComponentType &GetComponent(ScalarType &vector, int) {
|
||||
return vector;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT static void SetComponent(ScalarType &vector,
|
||||
int,
|
||||
ComponentType value) {
|
||||
vector = value;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
static vtkm::Tuple<ScalarType,1> ToTuple(const ScalarType &vector)
|
||||
{
|
||||
return vtkm::Tuple<ScalarType,1>(vector);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#define VTKM_BASIC_TYPE_VECTOR(type) \
|
||||
template<> \
|
||||
struct VectorTraits<type> \
|
||||
: public vtkm::internal::VectorTraitsBasic<type> { };/* \
|
||||
template<> \
|
||||
struct VectorTraits<const type> \
|
||||
: public vtkm::internal::VectorTraitsBasic<type> { }*/
|
||||
|
||||
/// Allows you to treat basic types as if they were vectors.
|
||||
|
||||
VTKM_BASIC_TYPE_VECTOR(float);
|
||||
VTKM_BASIC_TYPE_VECTOR(double);
|
||||
VTKM_BASIC_TYPE_VECTOR(char);
|
||||
VTKM_BASIC_TYPE_VECTOR(unsigned char);
|
||||
VTKM_BASIC_TYPE_VECTOR(short);
|
||||
VTKM_BASIC_TYPE_VECTOR(unsigned short);
|
||||
VTKM_BASIC_TYPE_VECTOR(int);
|
||||
VTKM_BASIC_TYPE_VECTOR(unsigned int);
|
||||
#if VTKM_SIZE_LONG == 8
|
||||
VTKM_BASIC_TYPE_VECTOR(long);
|
||||
VTKM_BASIC_TYPE_VECTOR(unsigned long);
|
||||
#elif VTKM_SIZE_LONG_LONG == 8
|
||||
VTKM_BASIC_TYPE_VECTOR(long long);
|
||||
VTKM_BASIC_TYPE_VECTOR(unsigned long long);
|
||||
#else
|
||||
#error No implementation for 64-bit vector traits.
|
||||
#endif
|
||||
|
||||
#undef VTKM_BASIC_TYPE_VECTOR
|
||||
|
||||
}
|
||||
|
||||
#endif //vtkm_VectorTraits_h
|
168
vtkm/cont/ArrayContainerControl.h
Normal file
168
vtkm/cont/ArrayContainerControl.h
Normal file
@ -0,0 +1,168 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont__ArrayContainerControl_h
|
||||
#define vtkm_cont__ArrayContainerControl_h
|
||||
|
||||
#define VTKM_ARRAY_CONTAINER_CONTROL_ERROR -1
|
||||
#define VTKM_ARRAY_CONTAINER_CONTROL_UNDEFINED 0
|
||||
#define VTKM_ARRAY_CONTAINER_CONTROL_BASIC 1
|
||||
|
||||
#ifndef VTKM_ARRAY_CONTAINER_CONTROL
|
||||
#define VTKM_ARRAY_CONTAINER_CONTROL VTKM_ARRAY_CONTAINER_CONTROL_BASIC
|
||||
#endif
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
#ifdef VTKM_DOXYGEN_ONLY
|
||||
/// \brief A tag specifying client memory allocation.
|
||||
///
|
||||
/// An ArrayContainerControl tag specifies how an ArrayHandle allocates and
|
||||
/// frees memory. The tag ArrayContainerControlTag___ does not actually exist.
|
||||
/// Rather, this documentation is provided to describe how array containers are
|
||||
/// specified. Loading the vtkm/cont/ArrayContainerControl.h header will set a
|
||||
/// default array container. You can specify the default array container by
|
||||
/// first setting the VTKM_ARRAY_CONTAINER_CONTROL macro. Currently it can only
|
||||
/// be set to VTKM_ARRAY_CONTAINER_CONTROL_BASIC.
|
||||
///
|
||||
/// User code external to VTKm is free to make its own ArrayContainerControlTag.
|
||||
/// This is a good way to get VTKm to read data directly in and out of arrays
|
||||
/// from other libraries. However, care should be taken when creating an
|
||||
/// ArrayContainerControl. One particular problem that is likely is a container
|
||||
/// that "constructs" all the items in the array. If done incorrectly, then
|
||||
/// memory of the array can be incorrectly bound to the wrong process. If you
|
||||
/// do provide your own ArrayContainerControlTag, please be diligent in
|
||||
/// comparing its performance to the ArrayContainerControlTagBasic.
|
||||
///
|
||||
/// To implement your own ArrayContainerControlTag, you first must create a tag
|
||||
/// class (an empty struct) defining your tag (i.e. struct
|
||||
/// ArrayContainerControlTagMyAlloc { };). Then provide a partial template
|
||||
/// specialization of vtkm::cont::internal::ArrayContainerControl for your new
|
||||
/// tag.
|
||||
///
|
||||
struct ArrayContainerControlTag___ { };
|
||||
#endif // VTKM_DOXYGEN_ONLY
|
||||
|
||||
namespace internal {
|
||||
|
||||
/// This templated class must be partially specialized for each
|
||||
/// ArrayContainerControlTag created, which will define the implementation for
|
||||
/// that tag.
|
||||
///
|
||||
template<typename T, class ArrayContainerControlTag>
|
||||
class ArrayContainerControl
|
||||
#ifdef VTKM_DOXYGEN_ONLY
|
||||
{
|
||||
public:
|
||||
|
||||
/// The type of each item in the array.
|
||||
///
|
||||
typedef T ValueType;
|
||||
|
||||
/// \brief The type of portal objects for the array.
|
||||
///
|
||||
/// The actual portal object can take any form. This is a simple example of a
|
||||
/// portal to a C array.
|
||||
///
|
||||
typedef ::vtkm::cont::internal::ArrayPortalFromIterators<ValueType*> PortalType;
|
||||
|
||||
/// \brief The type of portal objects (const version) for the array.
|
||||
///
|
||||
/// The actual portal object can take any form. This is a simple example of a
|
||||
/// portal to a C array.
|
||||
///
|
||||
typedef ::vtkm::cont::internal::ArrayPortalFromIterators<const ValueType*> PortalConstType;
|
||||
|
||||
/// Returns a portal to the array.
|
||||
///
|
||||
VTKM_CONT_EXPORT
|
||||
PortalType GetPortal();
|
||||
|
||||
/// Returns a portal to the array with immutable values.
|
||||
///
|
||||
VTKM_CONT_EXPORT
|
||||
PortalConstType GetPortalConst() const;
|
||||
|
||||
/// Retuns the number of entries allocated in the array.
|
||||
VTKM_CONT_EXPORT
|
||||
vtkm::Id GetNumberOfValues() const;
|
||||
|
||||
/// \brief Allocates an array large enough to hold the given number of values.
|
||||
///
|
||||
/// The allocation may be done on an already existing array, but can wipe out
|
||||
/// any data already in the array. This method can throw
|
||||
/// ErrorControlOutOfMemory if the array cannot be allocated.
|
||||
///
|
||||
VTKM_CONT_EXPORT
|
||||
void Allocate(vtkm::Id numberOfValues);
|
||||
|
||||
/// \brief Reduces the size of the array without changing its values.
|
||||
///
|
||||
/// This method allows you to resize the array without reallocating it. The
|
||||
/// number of entries in the array is changed to \c numberOfValues. The data
|
||||
/// in the array (from indices 0 to \c numberOfValues - 1) are the same, but
|
||||
/// \c numberOfValues must be equal or less than the preexisting size
|
||||
/// (returned from GetNumberOfValues). That is, this method can only be used
|
||||
/// to shorten the array, not lengthen.
|
||||
VTKM_CONT_EXPORT
|
||||
void Shrink(vtkm::Id numberOfValues);
|
||||
|
||||
/// \brief Frees any resources (i.e. memory) stored in this array.
|
||||
///
|
||||
/// After calling this method GetNumberOfValues will return 0 and
|
||||
/// GetIteratorBegin and GetIteratorEnd will return the same iterator. The
|
||||
/// resources should also be released when the ArrayContainerControl class is
|
||||
/// destroyed.
|
||||
VTKM_CONT_EXPORT
|
||||
void ReleaseResources();
|
||||
};
|
||||
#else // VTKM_DOXYGEN_ONLY
|
||||
;
|
||||
#endif // VTKM_DOXYGEN_ONLY
|
||||
|
||||
} // namespace internal
|
||||
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
||||
// This is put at the bottom of the header so that the ArrayContainerControl
|
||||
// template is declared before any implementations are called.
|
||||
|
||||
#if VTKM_ARRAY_CONTAINER_CONTROL == VTKM_ARRAY_CONTAINER_CONTROL_BASIC
|
||||
|
||||
#include <vtkm/cont/ArrayContainerControlBasic.h>
|
||||
#define VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG \
|
||||
::vtkm::cont::ArrayContainerControlTagBasic
|
||||
|
||||
#elif VTKM_ARRAY_CONTAINER_CONTROL == VTKM_ARRAY_CONTAINER_CONTROL_ERROR
|
||||
|
||||
#include <vtkm/cont/internal/ArrayContainerControlError.h>
|
||||
#define VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG \
|
||||
::vtkm::cont::internal::ArrayContainerControlTagError
|
||||
|
||||
#elif (VTKM_ARRAY_CONTAINER_CONTROL == VTKM_ARRAY_CONTAINER_CONTROL_UNDEFINED) || !defined(VTKM_ARRAY_CONTAINER_CONTROL)
|
||||
|
||||
#ifndef VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG
|
||||
#warning If array container for control is undefined, VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG must be defined.
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif //vtkm_cont__ArrayContainerControl_h
|
184
vtkm/cont/ArrayContainerControlBasic.h
Normal file
184
vtkm/cont/ArrayContainerControlBasic.h
Normal file
@ -0,0 +1,184 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont__ArrayContainerControlBasic_h
|
||||
#define vtkm_cont__ArrayContainerControlBasic_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/cont/ArrayContainerControl.h>
|
||||
#include <vtkm/cont/Assert.h>
|
||||
#include <vtkm/cont/ErrorControlBadValue.h>
|
||||
#include <vtkm/cont/ErrorControlOutOfMemory.h>
|
||||
#include <vtkm/cont/internal/ArrayPortalFromIterators.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
/// A tag for the basic implementation of an ArrayContainerControl object.
|
||||
struct ArrayContainerControlTagBasic { };
|
||||
|
||||
namespace internal {
|
||||
|
||||
/// A basic implementation of an ArrayContainerControl object.
|
||||
///
|
||||
/// \todo This container does \em not construct the values within the array.
|
||||
/// Thus, it is important to not use this class with any type that will fail if
|
||||
/// not constructed. These are things like basic types (int, float, etc.) and
|
||||
/// the VTKm Tuple classes. In the future it would be nice to have a compile
|
||||
/// time check to enforce this.
|
||||
///
|
||||
template <typename ValueT>
|
||||
class ArrayContainerControl<ValueT, vtkm::cont::ArrayContainerControlTagBasic>
|
||||
{
|
||||
public:
|
||||
typedef ValueT ValueType;
|
||||
typedef vtkm::cont::internal::ArrayPortalFromIterators<ValueType*> PortalType;
|
||||
typedef vtkm::cont::internal::ArrayPortalFromIterators<const ValueType*> PortalConstType;
|
||||
|
||||
private:
|
||||
/// The original design of this class provided an allocator as a template
|
||||
/// parameters. That messed things up, though, because other templated
|
||||
/// classes assume that the \c ArrayContainerControl has one template
|
||||
/// parameter. There are other ways to allow you to specify the allocator,
|
||||
/// but it is uncertain whether that would ever be useful. So, instead of
|
||||
/// jumping through hoops implementing them, just fix the allocator for now.
|
||||
///
|
||||
typedef std::allocator<ValueType> AllocatorType;
|
||||
|
||||
public:
|
||||
|
||||
ArrayContainerControl() : Array(NULL), NumberOfValues(0), AllocatedSize(0) { }
|
||||
|
||||
~ArrayContainerControl()
|
||||
{
|
||||
this->ReleaseResources();
|
||||
}
|
||||
|
||||
void ReleaseResources()
|
||||
{
|
||||
if (this->NumberOfValues > 0)
|
||||
{
|
||||
VTKM_ASSERT_CONT(this->Array != NULL);
|
||||
AllocatorType allocator;
|
||||
allocator.deallocate(this->Array, this->AllocatedSize);
|
||||
this->Array = NULL;
|
||||
this->NumberOfValues = 0;
|
||||
this->AllocatedSize = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
VTKM_ASSERT_CONT(this->Array == NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void Allocate(vtkm::Id numberOfValues)
|
||||
{
|
||||
if (numberOfValues <= this->AllocatedSize)
|
||||
{
|
||||
this->NumberOfValues = numberOfValues;
|
||||
return;
|
||||
}
|
||||
|
||||
this->ReleaseResources();
|
||||
try
|
||||
{
|
||||
if (numberOfValues > 0)
|
||||
{
|
||||
AllocatorType allocator;
|
||||
this->Array = allocator.allocate(numberOfValues);
|
||||
this->AllocatedSize = numberOfValues;
|
||||
this->NumberOfValues = numberOfValues;
|
||||
}
|
||||
else
|
||||
{
|
||||
// ReleaseResources should have already set AllocatedSize to 0.
|
||||
VTKM_ASSERT_CONT(this->AllocatedSize == 0);
|
||||
}
|
||||
}
|
||||
catch (std::bad_alloc err)
|
||||
{
|
||||
// Make sureour state is OK.
|
||||
this->Array = NULL;
|
||||
this->NumberOfValues = 0;
|
||||
this->AllocatedSize = 0;
|
||||
throw vtkm::cont::ErrorControlOutOfMemory(
|
||||
"Could not allocate basic control array.");
|
||||
}
|
||||
}
|
||||
|
||||
vtkm::Id GetNumberOfValues() const
|
||||
{
|
||||
return this->NumberOfValues;
|
||||
}
|
||||
|
||||
void Shrink(vtkm::Id numberOfValues)
|
||||
{
|
||||
if (numberOfValues > this->GetNumberOfValues())
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"Shrink method cannot be used to grow array.");
|
||||
}
|
||||
|
||||
this->NumberOfValues = numberOfValues;
|
||||
}
|
||||
|
||||
PortalType GetPortal()
|
||||
{
|
||||
return PortalType(this->Array, this->Array + this->NumberOfValues);
|
||||
}
|
||||
|
||||
PortalConstType GetPortalConst() const
|
||||
{
|
||||
return PortalConstType(this->Array, this->Array + this->NumberOfValues);
|
||||
}
|
||||
|
||||
/// \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
|
||||
/// ArrayContainerControl will never deallocate the array. This is
|
||||
/// helpful for taking a reference for an array created internally by VTKm and
|
||||
/// not having to keep a VTKm object around. Obviously the caller becomes
|
||||
/// responsible for destroying the memory.
|
||||
///
|
||||
ValueType *StealArray()
|
||||
{
|
||||
ValueType *saveArray = this->Array;
|
||||
this->Array = NULL;
|
||||
this->NumberOfValues = 0;
|
||||
this->AllocatedSize = 0;
|
||||
return saveArray;
|
||||
}
|
||||
|
||||
private:
|
||||
// Not implemented.
|
||||
ArrayContainerControl(const ArrayContainerControl<ValueType, ArrayContainerControlTagBasic> &src);
|
||||
void operator=(const ArrayContainerControl<ValueType, ArrayContainerControlTagBasic> &src);
|
||||
|
||||
ValueType *Array;
|
||||
vtkm::Id NumberOfValues;
|
||||
vtkm::Id AllocatedSize;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
||||
#endif //vtkm_cont__ArrayContainerControlBasic_h
|
192
vtkm/cont/ArrayContainerControlImplicit.h
Normal file
192
vtkm/cont/ArrayContainerControlImplicit.h
Normal file
@ -0,0 +1,192 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_ArrayContainerControlImplicit
|
||||
#define vtkm_cont_ArrayContainerControlImplicit
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
#include <vtkm/cont/ArrayContainerControl.h>
|
||||
#include <vtkm/cont/Assert.h>
|
||||
#include <vtkm/cont/ErrorControlBadValue.h>
|
||||
#include <vtkm/cont/internal/ArrayTransfer.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
/// \brief An implementation for read-only implicit arrays.
|
||||
///
|
||||
/// It is sometimes the case that you want VTKm to operate on an array of
|
||||
/// implicit values. That is, rather than store the data in an actual array, it
|
||||
/// is gerenated on the fly by a function. This is handled in VTKm by creating
|
||||
/// an ArrayHandle in VTKm with an ArrayContainerControlTagImplicit type of
|
||||
/// ArrayContainerControl. This tag itself is templated to specify an
|
||||
/// ArrayPortal that generates the desired values. An ArrayHandle created with
|
||||
/// this tag will raise an error on any operation that tries to modify it.
|
||||
///
|
||||
/// \todo The ArrayHandle currently copies the array in cases where the control
|
||||
/// and environment do not share memory. This is wasteful and should be fixed.
|
||||
///
|
||||
template<class ArrayPortalType>
|
||||
struct ArrayContainerControlTagImplicit {
|
||||
typedef ArrayPortalType PortalType;
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
|
||||
template<class ArrayPortalType>
|
||||
class ArrayContainerControl<
|
||||
typename ArrayPortalType::ValueType,
|
||||
ArrayContainerControlTagImplicit<ArrayPortalType> >
|
||||
{
|
||||
public:
|
||||
typedef typename ArrayPortalType::ValueType ValueType;
|
||||
typedef ArrayPortalType PortalConstType;
|
||||
|
||||
// This is meant to be invalid. Because implicit arrays are read only, you
|
||||
// should only be able to use the const version.
|
||||
struct PortalType {
|
||||
typedef void *ValueType;
|
||||
typedef void *IteratorType;
|
||||
};
|
||||
|
||||
// All these methods do nothing but raise errors.
|
||||
PortalType GetPortal() {
|
||||
throw vtkm::cont::ErrorControlBadValue("Implicit arrays are read-only.");
|
||||
}
|
||||
PortalConstType GetPortalConst() const {
|
||||
// This does not work because the ArrayHandle holds the constant
|
||||
// ArrayPortal, not the container.
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"Implicit container does not store array portal. "
|
||||
"Perhaps you did not set the ArrayPortal when "
|
||||
"constructing the ArrayHandle.");
|
||||
}
|
||||
vtkm::Id GetNumberOfValues() const {
|
||||
// This does not work because the ArrayHandle holds the constant
|
||||
// ArrayPortal, not the container.
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"Implicit container does not store array portal. "
|
||||
"Perhaps you did not set the ArrayPortal when "
|
||||
"constructing the ArrayHandle.");
|
||||
}
|
||||
void Allocate(vtkm::Id vtkmNotUsed(numberOfValues)) {
|
||||
throw vtkm::cont::ErrorControlBadValue("Implicit arrays are read-only.");
|
||||
}
|
||||
void Shrink(vtkm::Id vtkmNotUsed(numberOfValues)) {
|
||||
throw vtkm::cont::ErrorControlBadValue("Implicit arrays are read-only.");
|
||||
}
|
||||
void ReleaseResources() {
|
||||
throw vtkm::cont::ErrorControlBadValue("Implicit arrays are read-only.");
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, class ArrayPortalType, class DeviceAdapterTag>
|
||||
class ArrayTransfer<
|
||||
T, ArrayContainerControlTagImplicit<ArrayPortalType>, DeviceAdapterTag>
|
||||
{
|
||||
private:
|
||||
typedef ArrayContainerControlTagImplicit<ArrayPortalType>
|
||||
ArrayContainerControlTag;
|
||||
typedef vtkm::cont::internal::ArrayContainerControl<T,ArrayContainerControlTag>
|
||||
ContainerType;
|
||||
|
||||
public:
|
||||
typedef T ValueType;
|
||||
|
||||
typedef typename ContainerType::PortalType PortalControl;
|
||||
typedef typename ContainerType::PortalConstType PortalConstControl;
|
||||
typedef PortalControl PortalExecution;
|
||||
typedef PortalConstControl PortalConstExecution;
|
||||
|
||||
ArrayTransfer() : PortalValid(false) { }
|
||||
|
||||
VTKM_CONT_EXPORT vtkm::Id GetNumberOfValues() const {
|
||||
VTKM_ASSERT_CONT(this->PortalValid);
|
||||
return this->Portal.GetNumberOfValues();
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT void LoadDataForInput(PortalConstControl portal) {
|
||||
this->Portal = portal;
|
||||
this->PortalValid = true;
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT void LoadDataForInput(const ContainerType &controlArray) {
|
||||
this->LoadDataForInput(controlArray.GetPortalConst());
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void LoadDataForInPlace(ContainerType &vtkmNotUsed(controlArray))
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"Implicit arrays cannot be used for output or in place.");
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT void AllocateArrayForOutput(
|
||||
ContainerType &vtkmNotUsed(controlArray),
|
||||
vtkm::Id vtkmNotUsed(numberOfValues))
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"Implicit arrays cannot be used for output.");
|
||||
}
|
||||
VTKM_CONT_EXPORT void RetrieveOutputData(
|
||||
ContainerType &vtkmNotUsed(controlArray)) const
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"Implicit arrays cannot be used for output.");
|
||||
}
|
||||
|
||||
template <class IteratorTypeControl>
|
||||
VTKM_CONT_EXPORT void CopyInto(IteratorTypeControl dest) const
|
||||
{
|
||||
VTKM_ASSERT_CONT(this->PortalValid);
|
||||
std::copy(this->Portal.GetIteratorBegin(),
|
||||
this->Portal.GetIteratorEnd(),
|
||||
dest);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT void Shrink(vtkm::Id vtkmNotUsed(numberOfValues))
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue("Implicit arrays cannot be resized.");
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT PortalExecution GetPortalExecution()
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"Implicit arrays are read-only. (Get the const portal.)");
|
||||
}
|
||||
VTKM_CONT_EXPORT PortalConstExecution GetPortalConstExecution() const
|
||||
{
|
||||
VTKM_ASSERT_CONT(this->PortalValid);
|
||||
return this->Portal;
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT void ReleaseResources() { }
|
||||
|
||||
private:
|
||||
PortalConstExecution Portal;
|
||||
bool PortalValid;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
||||
#endif //vtkm_cont_ArrayContainerControlImplicit
|
537
vtkm/cont/ArrayHandle.h
Normal file
537
vtkm/cont/ArrayHandle.h
Normal file
@ -0,0 +1,537 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_ArrayHandle_h
|
||||
#define vtkm_cont_ArrayHandle_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
#include <vtkm/cont/ArrayContainerControl.h>
|
||||
#include <vtkm/cont/Assert.h>
|
||||
#include <vtkm/cont/ErrorControlBadValue.h>
|
||||
#include <vtkm/cont/internal/ArrayHandleExecutionManager.h>
|
||||
#include <vtkm/cont/internal/ArrayTransfer.h>
|
||||
#include <vtkm/cont/internal/DeviceAdapterTag.h>
|
||||
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <boost/smart_ptr/scoped_ptr.hpp>
|
||||
#include <boost/smart_ptr/shared_ptr.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
// Forward declaration
|
||||
namespace internal { class ArrayHandleAccess; }
|
||||
|
||||
/// \brief Manages an array-worth of data.
|
||||
///
|
||||
/// \c ArrayHandle manages as array of data that can be manipulated by VTKm
|
||||
/// algorithms. The \c ArrayHandle may have up to two copies of the array, one
|
||||
/// for the control environment and one for the execution environment, although
|
||||
/// depending on the device and how the array is being used, the \c ArrayHandle
|
||||
/// will only have one copy when possible.
|
||||
///
|
||||
/// An ArrayHandle can be constructed one of two ways. Its default construction
|
||||
/// creates an empty, unallocated array that can later be allocated and filled
|
||||
/// either by the user or a VTKm algorithm. The \c ArrayHandle can also be
|
||||
/// constructed with iterators to a user's array. In this case the \c
|
||||
/// ArrayHandle will keep a reference to this array but may drop it if the
|
||||
/// array is reallocated.
|
||||
///
|
||||
/// \c ArrayHandle behaves like a shared smart pointer in that when it is copied
|
||||
/// each copy holds a reference to the same array. These copies are reference
|
||||
/// counted so that when all copies of the \c ArrayHandle are destroyed, any
|
||||
/// allocated memory is released.
|
||||
///
|
||||
template<
|
||||
typename T,
|
||||
typename ArrayContainerControlTag_ = VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG>
|
||||
class ArrayHandle
|
||||
{
|
||||
private:
|
||||
typedef vtkm::cont::internal
|
||||
::ArrayContainerControl<T,ArrayContainerControlTag_>
|
||||
ArrayContainerControlType;
|
||||
typedef vtkm::cont::internal
|
||||
::ArrayHandleExecutionManagerBase<T,ArrayContainerControlTag_>
|
||||
ExecutionManagerType;
|
||||
public:
|
||||
typedef T ValueType;
|
||||
typedef ArrayContainerControlTag_ ArrayContainerControlTag;
|
||||
typedef typename ArrayContainerControlType::PortalType PortalControl;
|
||||
typedef typename ArrayContainerControlType::PortalConstType
|
||||
PortalConstControl;
|
||||
template <typename DeviceAdapterTag>
|
||||
struct ExecutionTypes {
|
||||
typedef typename ExecutionManagerType
|
||||
::template ExecutionTypes<DeviceAdapterTag>::Portal Portal;
|
||||
typedef typename ExecutionManagerType
|
||||
::template ExecutionTypes<DeviceAdapterTag>::PortalConst PortalConst;
|
||||
};
|
||||
|
||||
/// Constructs an empty ArrayHandle. Typically used for output or
|
||||
/// intermediate arrays that will be filled by a VTKm algorithm.
|
||||
///
|
||||
VTKM_CONT_EXPORT ArrayHandle() : Internals(new InternalStruct)
|
||||
{
|
||||
this->Internals->UserPortalValid = false;
|
||||
this->Internals->ControlArrayValid = false;
|
||||
this->Internals->ExecutionArrayValid = false;
|
||||
}
|
||||
|
||||
/// Constructs an ArrayHandle pointing to the data in the given array portal.
|
||||
///
|
||||
VTKM_CONT_EXPORT ArrayHandle(PortalConstControl userData)
|
||||
: Internals(new InternalStruct)
|
||||
{
|
||||
this->Internals->UserPortal = userData;
|
||||
this->Internals->UserPortalValid = true;
|
||||
|
||||
this->Internals->ControlArrayValid = false;
|
||||
this->Internals->ExecutionArrayValid = false;
|
||||
}
|
||||
|
||||
/// Get the array portal of the control array.
|
||||
///
|
||||
VTKM_CONT_EXPORT PortalControl GetPortalControl()
|
||||
{
|
||||
this->SyncControlArray();
|
||||
if (this->Internals->UserPortalValid)
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"ArrayHandle has a read-only control portal.");
|
||||
}
|
||||
else if (this->Internals->ControlArrayValid)
|
||||
{
|
||||
// If the user writes into the iterator we return, then the execution
|
||||
// array will become invalid. Play it safe and release the execution
|
||||
// resources. (Use the const version to preserve the execution array.)
|
||||
this->ReleaseResourcesExecution();
|
||||
return this->Internals->ControlArray.GetPortal();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue("ArrayHandle contains no data.");
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the array portal of the control array.
|
||||
///
|
||||
VTKM_CONT_EXPORT PortalConstControl GetPortalConstControl() const
|
||||
{
|
||||
this->SyncControlArray();
|
||||
if (this->Internals->UserPortalValid)
|
||||
{
|
||||
return this->Internals->UserPortal;
|
||||
}
|
||||
else if (this->Internals->ControlArrayValid)
|
||||
{
|
||||
return this->Internals->ControlArray.GetPortalConst();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue("ArrayHandle contains no data.");
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the number of entries in the array.
|
||||
///
|
||||
VTKM_CONT_EXPORT vtkm::Id GetNumberOfValues() const
|
||||
{
|
||||
if (this->Internals->UserPortalValid)
|
||||
{
|
||||
return this->Internals->UserPortal.GetNumberOfValues();
|
||||
}
|
||||
else if (this->Internals->ControlArrayValid)
|
||||
{
|
||||
return this->Internals->ControlArray.GetNumberOfValues();
|
||||
}
|
||||
else if (this->Internals->ExecutionArrayValid)
|
||||
{
|
||||
return
|
||||
this->Internals->ExecutionArray->GetNumberOfValues();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// \brief Reduces the size of the array without changing its values.
|
||||
///
|
||||
/// This method allows you to resize the array without reallocating it. The
|
||||
/// number of entries in the array is changed to \c numberOfValues. The data
|
||||
/// in the array (from indices 0 to \c numberOfValues - 1) are the same, but
|
||||
/// \c numberOfValues must be equal or less than the preexisting size
|
||||
/// (returned from GetNumberOfValues). That is, this method can only be used
|
||||
/// to shorten the array, not lengthen.
|
||||
void Shrink(vtkm::Id numberOfValues)
|
||||
{
|
||||
vtkm::Id originalNumberOfValues = this->GetNumberOfValues();
|
||||
|
||||
if (numberOfValues < originalNumberOfValues)
|
||||
{
|
||||
if (this->Internals->UserPortalValid)
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"ArrayHandle has a read-only control portal.");
|
||||
}
|
||||
if (this->Internals->ControlArrayValid)
|
||||
{
|
||||
this->Internals->ControlArray.Shrink(numberOfValues);
|
||||
}
|
||||
if (this->Internals->ExecutionArrayValid)
|
||||
{
|
||||
this->Internals->ExecutionArray->Shrink(numberOfValues);
|
||||
}
|
||||
}
|
||||
else if (numberOfValues == originalNumberOfValues)
|
||||
{
|
||||
// Nothing to do.
|
||||
}
|
||||
else // numberOfValues > originalNumberOfValues
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"ArrayHandle::Shrink cannot be used to grow array.");
|
||||
}
|
||||
|
||||
VTKM_ASSERT_CONT(this->GetNumberOfValues() == numberOfValues);
|
||||
}
|
||||
|
||||
/// Releases any resources being used in the execution environment (that are
|
||||
/// not being shared by the control environment).
|
||||
///
|
||||
VTKM_CONT_EXPORT void ReleaseResourcesExecution()
|
||||
{
|
||||
if (this->Internals->ExecutionArrayValid)
|
||||
{
|
||||
this->Internals->ExecutionArray->ReleaseResources();
|
||||
this->Internals->ExecutionArrayValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Releases all resources in both the control and execution environments.
|
||||
///
|
||||
VTKM_CONT_EXPORT void ReleaseResources()
|
||||
{
|
||||
this->ReleaseResourcesExecution();
|
||||
|
||||
// Forget about any user iterators.
|
||||
this->Internals->UserPortalValid = false;
|
||||
|
||||
if (this->Internals->ControlArrayValid)
|
||||
{
|
||||
this->Internals->ControlArray.ReleaseResources();
|
||||
this->Internals->ControlArrayValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Prepares this array to be used as an input to an operation in the
|
||||
/// execution environment. If necessary, copies data to the execution
|
||||
/// environment. Can throw an exception if this array does not yet contain
|
||||
/// any data. Returns a portal that can be used in code running in the
|
||||
/// execution environment.
|
||||
///
|
||||
template<typename DeviceAdapterTag>
|
||||
VTKM_CONT_EXPORT
|
||||
typename ExecutionTypes<DeviceAdapterTag>::PortalConst
|
||||
PrepareForInput(DeviceAdapterTag) const
|
||||
{
|
||||
VTKM_IS_DEVICE_ADAPTER_TAG(DeviceAdapterTag);
|
||||
|
||||
if (this->Internals->ExecutionArrayValid)
|
||||
{
|
||||
// Nothing to do, data already loaded.
|
||||
}
|
||||
else if (this->Internals->UserPortalValid)
|
||||
{
|
||||
VTKM_ASSERT_CONT(!this->Internals->ControlArrayValid);
|
||||
this->PrepareForDevice(DeviceAdapterTag());
|
||||
this->Internals->ExecutionArray->LoadDataForInput(
|
||||
this->Internals->UserPortal);
|
||||
this->Internals->ExecutionArrayValid = true;
|
||||
}
|
||||
else if (this->Internals->ControlArrayValid)
|
||||
{
|
||||
this->PrepareForDevice(DeviceAdapterTag());
|
||||
this->Internals->ExecutionArray->LoadDataForInput(
|
||||
this->Internals->ControlArray);
|
||||
this->Internals->ExecutionArrayValid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"ArrayHandle has no data when PrepareForInput called.");
|
||||
}
|
||||
return this->Internals->ExecutionArray->GetPortalConstExecution(
|
||||
DeviceAdapterTag());
|
||||
}
|
||||
|
||||
/// Prepares (allocates) this array to be used as an output from an operation
|
||||
/// in the execution environment. The internal state of this class is set to
|
||||
/// have valid data in the execution array with the assumption that the array
|
||||
/// will be filled soon (i.e. before any other methods of this object are
|
||||
/// called). Returns a portal that can be used in code running in the
|
||||
/// execution environment.
|
||||
///
|
||||
template<typename DeviceAdapterTag>
|
||||
VTKM_CONT_EXPORT
|
||||
typename ExecutionTypes<DeviceAdapterTag>::Portal
|
||||
PrepareForOutput(vtkm::Id numberOfValues, DeviceAdapterTag)
|
||||
{
|
||||
VTKM_IS_DEVICE_ADAPTER_TAG(DeviceAdapterTag);
|
||||
|
||||
// Invalidate any control arrays.
|
||||
// Should the control array resource be released? Probably not a good
|
||||
// idea when shared with execution.
|
||||
this->Internals->UserPortalValid = false;
|
||||
this->Internals->ControlArrayValid = false;
|
||||
|
||||
this->PrepareForDevice(DeviceAdapterTag());
|
||||
this->Internals->ExecutionArray->AllocateArrayForOutput(
|
||||
this->Internals->ControlArray, numberOfValues);
|
||||
|
||||
// We are assuming that the calling code will fill the array using the
|
||||
// iterators we are returning, so go ahead and mark the execution array as
|
||||
// having valid data. (A previous version of this class had a separate call
|
||||
// to mark the array as filled, but that was onerous to call at the the
|
||||
// right time and rather pointless since it is basically always the case
|
||||
// that the array is going to be filled before anything else. In this
|
||||
// implementation the only access to the array is through the iterators
|
||||
// returned from this method, so you would have to work to invalidate this
|
||||
// assumption anyway.)
|
||||
this->Internals->ExecutionArrayValid = true;
|
||||
|
||||
return this->Internals->ExecutionArray->GetPortalExecution(DeviceAdapterTag());
|
||||
}
|
||||
|
||||
/// Prepares this array to be used in an in-place operation (both as input
|
||||
/// and output) in the execution environment. If necessary, copies data to
|
||||
/// the execution environment. Can throw an exception if this array does not
|
||||
/// yet contain any data. Returns a portal that can be used in code running
|
||||
/// in the execution environment.
|
||||
///
|
||||
template<typename DeviceAdapterTag>
|
||||
VTKM_CONT_EXPORT
|
||||
typename ExecutionTypes<DeviceAdapterTag>::Portal
|
||||
PrepareForInPlace(DeviceAdapterTag)
|
||||
{
|
||||
VTKM_IS_DEVICE_ADAPTER_TAG(DeviceAdapterTag);
|
||||
|
||||
if (this->Internals->UserPortalValid)
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"In place execution cannot be used with an ArrayHandle that has "
|
||||
"user arrays because this might write data back into user space "
|
||||
"unexpectedly. Copy the data to a new array first.");
|
||||
}
|
||||
|
||||
// This code is similar to PrepareForInput except that we have to give a
|
||||
// writable portal instead of the const portal to the execution array
|
||||
// manager so that the data can (potentially) be written to.
|
||||
if (this->Internals->ExecutionArrayValid)
|
||||
{
|
||||
// Nothing to do, data already loaded.
|
||||
}
|
||||
else if (this->Internals->ControlArrayValid)
|
||||
{
|
||||
this->PrepareForDevice(DeviceAdapterTag());
|
||||
this->Internals->ExecutionArray->LoadDataForInPlace(
|
||||
this->Internals->ControlArray);
|
||||
this->Internals->ExecutionArrayValid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue(
|
||||
"ArrayHandle has no data when PrepareForInput called.");
|
||||
}
|
||||
|
||||
// Invalidate any control arrays since their data will become invalid when
|
||||
// the execution data is overwritten. Don't actually release the control
|
||||
// array. It may be shared as the execution array.
|
||||
this->Internals->ControlArrayValid = false;
|
||||
|
||||
return this->Internals->ExecutionArray->GetPortalExecution(DeviceAdapterTag());
|
||||
}
|
||||
|
||||
// protected:
|
||||
/// Special constructor for subclass specializations that need to set the
|
||||
/// initial state of the control array. When this constructor is used, it
|
||||
/// is assumed that the control array is valid.
|
||||
///
|
||||
ArrayHandle(const ArrayContainerControlType &container)
|
||||
: Internals(new InternalStruct)
|
||||
{
|
||||
this->Internals->UserPortalValid = false;
|
||||
this->Internals->ControlArray = container;
|
||||
this->Internals->ControlArrayValid = true;
|
||||
this->Internals->ExecutionArrayValid = false;
|
||||
}
|
||||
|
||||
// private:
|
||||
struct InternalStruct {
|
||||
PortalConstControl UserPortal;
|
||||
bool UserPortalValid;
|
||||
|
||||
ArrayContainerControlType ControlArray;
|
||||
bool ControlArrayValid;
|
||||
|
||||
boost::scoped_ptr<
|
||||
vtkm::cont::internal::ArrayHandleExecutionManagerBase<
|
||||
ValueType,ArrayContainerControlTag> > ExecutionArray;
|
||||
bool ExecutionArrayValid;
|
||||
};
|
||||
|
||||
ArrayHandle(boost::shared_ptr<InternalStruct> i)
|
||||
: Internals(i)
|
||||
{ }
|
||||
|
||||
/// Gets this array handle ready to interact with the given device. If the
|
||||
/// array handle has already interacted with this device, then this method
|
||||
/// does nothing. Although the internal state of this class can change, the
|
||||
/// method is declared const because logically the data does not.
|
||||
///
|
||||
template<typename DeviceAdapterTag>
|
||||
VTKM_CONT_EXPORT
|
||||
void PrepareForDevice(DeviceAdapterTag) const
|
||||
{
|
||||
if (this->Internals->ExecutionArray != NULL)
|
||||
{
|
||||
if (this->Internals->ExecutionArray->IsDeviceAdapter(DeviceAdapterTag()))
|
||||
{
|
||||
// Already have manager for correct device adapter. Nothing to do.
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Have the wrong manager. Delete the old one and create a new one
|
||||
// of the right type. (BTW, it would be possible for the array handle
|
||||
// to hold references to execution arrays on multiple devices. However,
|
||||
// there is not a clear use case for that yet and it is unclear what
|
||||
// the behavior of "dirty" arrays should be, so it is not currently
|
||||
// implemented.)
|
||||
this->SyncControlArray();
|
||||
// Need to change some state that does not change the logical state from
|
||||
// an external point of view.
|
||||
InternalStruct *internals
|
||||
= const_cast<InternalStruct*>(this->Internals.get());
|
||||
internals->ExecutionArray.reset();
|
||||
internals->ExecutionArrayValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_ASSERT_CONT(this->Internals->ExecutionArray == NULL);
|
||||
VTKM_ASSERT_CONT(this->Internals->ExecutionArrayValid == false);
|
||||
// Need to change some state that does not change the logical state from
|
||||
// an external point of view.
|
||||
InternalStruct *internals
|
||||
= const_cast<InternalStruct*>(this->Internals.get());
|
||||
internals->ExecutionArray.reset(
|
||||
new vtkm::cont::internal::ArrayHandleExecutionManager<
|
||||
T, ArrayContainerControlTag, DeviceAdapterTag>);
|
||||
}
|
||||
|
||||
/// Synchronizes the control array with the execution array. If either the
|
||||
/// user array or control array is already valid, this method does nothing
|
||||
/// (because the data is already available in the control environment).
|
||||
/// Although the internal state of this class can change, the method is
|
||||
/// declared const because logically the data does not.
|
||||
///
|
||||
VTKM_CONT_EXPORT void SyncControlArray() const
|
||||
{
|
||||
if ( !this->Internals->UserPortalValid
|
||||
&& !this->Internals->ControlArrayValid)
|
||||
{
|
||||
// Need to change some state that does not change the logical state from
|
||||
// an external point of view.
|
||||
InternalStruct *internals
|
||||
= const_cast<InternalStruct*>(this->Internals.get());
|
||||
internals->ExecutionArray->RetrieveOutputData(internals->ControlArray);
|
||||
internals->ControlArrayValid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// It should never be the case that both the user and control array are
|
||||
// valid.
|
||||
VTKM_ASSERT_CONT(!this->Internals->UserPortalValid
|
||||
|| !this->Internals->ControlArrayValid);
|
||||
// Nothing to do.
|
||||
}
|
||||
}
|
||||
|
||||
boost::shared_ptr<InternalStruct> Internals;
|
||||
};
|
||||
|
||||
/// A convenience function for creating an ArrayHandle from a standard C
|
||||
/// array. Unless properly specialized, this only works with container types
|
||||
/// that use an array portal that accepts a pair of pointers to signify the
|
||||
/// beginning and end of the array.
|
||||
///
|
||||
template<typename T, typename ArrayContainerControlTag>
|
||||
VTKM_CONT_EXPORT
|
||||
vtkm::cont::ArrayHandle<T, ArrayContainerControlTag>
|
||||
make_ArrayHandle(const T *array,
|
||||
vtkm::Id length,
|
||||
ArrayContainerControlTag)
|
||||
{
|
||||
typedef vtkm::cont::ArrayHandle<T, ArrayContainerControlTag> ArrayHandleType;
|
||||
typedef typename ArrayHandleType::PortalConstControl PortalType;
|
||||
return ArrayHandleType(PortalType(array, array+length));
|
||||
}
|
||||
template<typename T>
|
||||
VTKM_CONT_EXPORT
|
||||
vtkm::cont::ArrayHandle<T, VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG>
|
||||
make_ArrayHandle(const T *array, vtkm::Id length)
|
||||
{
|
||||
return make_ArrayHandle(array,
|
||||
length,
|
||||
VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG());
|
||||
}
|
||||
|
||||
/// A convenience function for creating an ArrayHandle from an std::vector.
|
||||
/// Unless properly specialized, this only works with container types that use
|
||||
/// an array portal that accepts a pair of pointers to signify the beginning
|
||||
/// and end of the array.
|
||||
///
|
||||
template<typename T,
|
||||
typename Allocator,
|
||||
typename ArrayContainerControlTag>
|
||||
VTKM_CONT_EXPORT
|
||||
vtkm::cont::ArrayHandle<T, ArrayContainerControlTag>
|
||||
make_ArrayHandle(const std::vector<T,Allocator> &array,
|
||||
ArrayContainerControlTag)
|
||||
{
|
||||
typedef vtkm::cont::ArrayHandle<T, ArrayContainerControlTag> ArrayHandleType;
|
||||
typedef typename ArrayHandleType::PortalConstControl PortalType;
|
||||
return ArrayHandleType(PortalType(&array.front(), &array.back() + 1));
|
||||
}
|
||||
template<typename T, typename Allocator>
|
||||
VTKM_CONT_EXPORT
|
||||
vtkm::cont::ArrayHandle<T, VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG>
|
||||
make_ArrayHandle(const std::vector<T,Allocator> &array)
|
||||
{
|
||||
return make_ArrayHandle(array, VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif //vtkm_cont_ArrayHandle_h
|
107
vtkm/cont/ArrayPortal.h
Normal file
107
vtkm/cont/ArrayPortal.h
Normal file
@ -0,0 +1,107 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_ArrayPortal_h
|
||||
#define vtkm_cont_ArrayPortal_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
#ifdef VTKM_DOXYGEN_ONLY
|
||||
|
||||
/// \brief A class that points to and access and array of data.
|
||||
///
|
||||
/// The ArrayPortal class itself does not exist; this code is provided for
|
||||
/// documentation purposes only.
|
||||
///
|
||||
/// An ArrayPortal object acts like a pointer to a random-access container
|
||||
/// (that is, an array) and also lets you set and get values in that array. In
|
||||
/// many respects an ArrayPortal is similar in concept to that of iterators but
|
||||
/// with a much simpler interface and no internal concept of position.
|
||||
/// Otherwise, ArrayPortal objects may be passed and copied around so that
|
||||
/// multiple entities may be accessing the same array.
|
||||
///
|
||||
/// An ArrayPortal differs from an ArrayHandle in that the ArrayPortal is a
|
||||
/// much lighterweight object and that it does not manage things like
|
||||
/// allocation and control/execution sharing. An ArrayPortal also differs from
|
||||
/// an ArrayContainer in that it does not actually contain the data but rather
|
||||
/// points to it. In this way the ArrayPortal can be copied and passed and
|
||||
/// still point to the same data.
|
||||
///
|
||||
/// Most VTKm users generally do not need to do much or anything with
|
||||
/// 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.
|
||||
///
|
||||
template<typename T>
|
||||
class ArrayPortal
|
||||
{
|
||||
public:
|
||||
/// The type of each value in the array.
|
||||
///
|
||||
typedef T ValueType;
|
||||
|
||||
/// The total number of values in the array. They are index from 0 to
|
||||
/// GetNumberOfValues()-1.
|
||||
///
|
||||
VTKM_CONT_EXPORT
|
||||
vtkm::Id GetNumberOfValues() const;
|
||||
|
||||
/// Gets a value from the array.
|
||||
///
|
||||
VTKM_CONT_EXPORT
|
||||
ValueType Get(vtkm::Id index) const;
|
||||
|
||||
/// Sets a value in the array. This function may not exist for an ArrayPortal
|
||||
/// pointing to a const array.
|
||||
///
|
||||
VTKM_CONT_EXPORT
|
||||
void Set(vtkm::Id index, const ValueType &value) const;
|
||||
|
||||
/// An iterator type that can be used as an alternate way to access the data.
|
||||
/// If the container being pointed to has a natural iterator that can be
|
||||
/// used, then use that. Otherwise, use IteratorForArrayPortal. Iterators are
|
||||
/// not necessary for array portals in the execution environment.
|
||||
///
|
||||
typedef ValueType *IteratorType;
|
||||
|
||||
/// Returns an iterator to the beginning of the array. Iterators are not
|
||||
/// necessary for array portals in the execution environment.
|
||||
///
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorBegin() const;
|
||||
|
||||
/// Returns an iterator to the end of the array. Iterators are not necessary
|
||||
/// for array portals in the execution environment.
|
||||
///
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorEnd() const;
|
||||
};
|
||||
|
||||
#endif // VTKM_DOXYGEN_ONLY
|
||||
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
||||
#endif //vtkm_cont_ArrayPortal_h
|
64
vtkm/cont/Assert.h
Normal file
64
vtkm/cont/Assert.h
Normal file
@ -0,0 +1,64 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_Assert_h
|
||||
#define vtkm_cont_Assert_h
|
||||
|
||||
#include <vtkm/cont/ErrorControlAssert.h>
|
||||
|
||||
// Stringify macros for VTKM_ASSERT_CONT
|
||||
#define __VTKM_ASSERT_CONT_STRINGIFY_2ND(s) #s
|
||||
#define __VTKM_ASSERT_CONT_STRINGIFY(s) __VTKM_ASSERT_CONT_STRINGIFY_2ND(s)
|
||||
|
||||
/// \def VTKM_ASSERT_CONT(condition)
|
||||
///
|
||||
/// Asserts that \a condition resolves to true. If \a condition is false,
|
||||
/// then an error is raised. This macro is meant to work in the VTKm control
|
||||
/// environment and throws an ErrorControlAssert object on failure.
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define VTKM_ASSERT_CONT(condition) \
|
||||
if (!(condition)) \
|
||||
::vtkm::cont::Assert(condition, __FILE__, __LINE__, #condition)
|
||||
#else
|
||||
#define VTKM_ASSERT_CONT(condition)
|
||||
#endif
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
VTKM_CONT_EXPORT void Assert(bool condition,
|
||||
const std::string &file,
|
||||
vtkm::Id line,
|
||||
const std::string &message)
|
||||
{
|
||||
if (condition)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
else
|
||||
{
|
||||
throw vtkm::cont::ErrorControlAssert(file, line, message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
||||
#endif //vtkm_cont_Assert_h
|
46
vtkm/cont/CMakeLists.txt
Normal file
46
vtkm/cont/CMakeLists.txt
Normal file
@ -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 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_directories(${Boost_INCLUDE_DIRS})
|
||||
|
||||
set(headers
|
||||
ArrayContainerControl.h
|
||||
ArrayContainerControlBasic.h
|
||||
ArrayContainerControlImplicit.h
|
||||
ArrayHandle.h
|
||||
ArrayPortal.h
|
||||
Assert.h
|
||||
Error.h
|
||||
ErrorControl.h
|
||||
ErrorControlAssert.h
|
||||
ErrorControlBadValue.h
|
||||
ErrorControlInternal.h
|
||||
ErrorControlOutOfMemory.h
|
||||
ErrorExecution.h
|
||||
)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
add_subdirectory(internal)
|
||||
|
||||
vtkm_declare_headers(${impl_headers} ${headers})
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
add_subdirectory(testing)
|
54
vtkm/cont/Error.h
Normal file
54
vtkm/cont/Error.h
Normal file
@ -0,0 +1,54 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_Error_h
|
||||
#define vtkm_cont_Error_h
|
||||
|
||||
// Note that this class and (most likely) all of its subclasses are not
|
||||
// templated. If there is any reason to create a VTKm control library,
|
||||
// this class and its subclasses should probably go there.
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
/// The superclass of all exceptions thrown by any VTKm function or method.
|
||||
///
|
||||
class Error
|
||||
{
|
||||
public:
|
||||
const std::string &GetMessage() const { return this->Message; }
|
||||
|
||||
protected:
|
||||
Error() { }
|
||||
Error(const std::string message) : Message(message) { }
|
||||
|
||||
void SetMessage(const std::string &message) {
|
||||
this->Message = message;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string Message;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
||||
#endif //vtkm_cont_Error_h
|
41
vtkm/cont/ErrorControl.h
Normal file
41
vtkm/cont/ErrorControl.h
Normal file
@ -0,0 +1,41 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_ErrorControl_h
|
||||
#define vtkm_cont_ErrorControl_h
|
||||
|
||||
#include <vtkm/cont/Error.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
/// The superclass of all exceptions thrown from within the VTKm control
|
||||
/// environment.
|
||||
///
|
||||
class ErrorControl : public vtkm::cont::Error
|
||||
{
|
||||
protected:
|
||||
ErrorControl() { }
|
||||
ErrorControl(const std::string message) : Error(message) { }
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
||||
#endif //vtkm_cont_ErrorControl_h
|
56
vtkm/cont/ErrorControlAssert.h
Normal file
56
vtkm/cont/ErrorControlAssert.h
Normal file
@ -0,0 +1,56 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_ErrorControlAssert_h
|
||||
#define vtkm_cont_ErrorControlAssert_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/cont/ErrorControl.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
/// This error is thrown whenever VTKM_ASSERT_CONT fails.
|
||||
///
|
||||
class ErrorControlAssert : public vtkm::cont::ErrorControl
|
||||
{
|
||||
public:
|
||||
ErrorControlAssert(const std::string &file,
|
||||
vtkm::Id line,
|
||||
const std::string &condition)
|
||||
: ErrorControl(), File(file), Line(line), Condition(condition)
|
||||
{
|
||||
std::stringstream message;
|
||||
message << this->File << ":" << this->Line
|
||||
<< ": Assert Failed (" << this->Condition << ")";
|
||||
this->SetMessage(message.str());
|
||||
}
|
||||
|
||||
private:
|
||||
std::string File;
|
||||
vtkm::Id Line;
|
||||
std::string Condition;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif //vtkm_cont_ErrorControlAssert_h
|
41
vtkm/cont/ErrorControlBadValue.h
Normal file
41
vtkm/cont/ErrorControlBadValue.h
Normal file
@ -0,0 +1,41 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_ErrorControlBadValue_h
|
||||
#define vtkm_cont_ErrorControlBadValue_h
|
||||
|
||||
#include <vtkm/cont/ErrorControl.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
/// This class is thrown when a VTKm function or method encounters an invalid
|
||||
/// value that inhibits progress.
|
||||
///
|
||||
class ErrorControlBadValue : public ErrorControl
|
||||
{
|
||||
public:
|
||||
ErrorControlBadValue(const std::string &message)
|
||||
: ErrorControl(message) { }
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
||||
#endif //vtkm_cont_ErrorControlBadValue_h
|
42
vtkm/cont/ErrorControlInternal.h
Normal file
42
vtkm/cont/ErrorControlInternal.h
Normal file
@ -0,0 +1,42 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_ErrorControlInternal_h
|
||||
#define vtkm_cont_ErrorControlInternal_h
|
||||
|
||||
#include <vtkm/cont/ErrorControl.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
/// This class is thrown when VTKm detects an internal state that should never
|
||||
/// be reached. This error usually indicates a bug in vtkm or, at best, VTKm
|
||||
/// failed to detect an invalid input it should have.
|
||||
///
|
||||
class ErrorControlInternal : public ErrorControl
|
||||
{
|
||||
public:
|
||||
ErrorControlInternal(const std::string &message)
|
||||
: ErrorControl(message) { }
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
||||
#endif //vtkm_cont_ErrorControlInternal_h
|
41
vtkm/cont/ErrorControlOutOfMemory.h
Normal file
41
vtkm/cont/ErrorControlOutOfMemory.h
Normal file
@ -0,0 +1,41 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_ErrorControlOutOfMemory_h
|
||||
#define vtkm_cont_ErrorControlOutOfMemory_h
|
||||
|
||||
#include <vtkm/cont/ErrorControl.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
/// This class is thrown when a vtkm function or method tries to allocate an
|
||||
/// array and fails.
|
||||
///
|
||||
class ErrorControlOutOfMemory : public ErrorControl
|
||||
{
|
||||
public:
|
||||
ErrorControlOutOfMemory(const std::string &message)
|
||||
: ErrorControl(message) { }
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
||||
#endif //vtkm_cont_ErrorControlOutOfMemory_h
|
41
vtkm/cont/ErrorExecution.h
Normal file
41
vtkm/cont/ErrorExecution.h
Normal file
@ -0,0 +1,41 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_ErrorExecution_h
|
||||
#define vtkm_cont_ErrorExecution_h
|
||||
|
||||
#include <vtkm/cont/Error.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
/// This class is thrown in the control environment whenever an error occurs in
|
||||
/// the execution environment.
|
||||
///
|
||||
class ErrorExecution : public vtkm::cont::Error
|
||||
{
|
||||
public:
|
||||
ErrorExecution(const std::string message)
|
||||
: Error(message) { }
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
||||
#endif //vtkm_cont_ErrorExecution_h
|
42
vtkm/cont/internal/ArrayContainerControlError.h
Normal file
42
vtkm/cont/internal/ArrayContainerControlError.h
Normal file
@ -0,0 +1,42 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_internal_ArrayContainerControlError_h
|
||||
#define vtkm_cont_internal_ArrayContainerControlError_h
|
||||
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
namespace internal {
|
||||
|
||||
/// This is an invalid ArrayContainerControl. The point of this class is to
|
||||
/// include the header file to make this invalid class the default
|
||||
/// ArrayContainerControl. From that point, you have to specify an appropriate
|
||||
/// ArrayContainerControl or else get a compile error.
|
||||
///
|
||||
struct ArrayContainerControlTagError
|
||||
{
|
||||
// Not implemented.
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::internal
|
||||
|
||||
#endif //vtkm_cont_internal_ArrayContainerControlError_h
|
286
vtkm/cont/internal/ArrayHandleExecutionManager.h
Normal file
286
vtkm/cont/internal/ArrayHandleExecutionManager.h
Normal file
@ -0,0 +1,286 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_exec_ArrayHandleExecutionManager_h
|
||||
#define vtkm_cont_exec_ArrayHandleExecutionManager_h
|
||||
|
||||
#include <vtkm/cont/ArrayContainerControl.h>
|
||||
#include <vtkm/cont/ErrorControlInternal.h>
|
||||
#include <vtkm/cont/internal/ArrayTransfer.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
namespace internal {
|
||||
|
||||
/// The common base for ArrayHandleExecutionManager. This is the interface
|
||||
/// used when the type of the device is not known at run time.
|
||||
///
|
||||
template<typename T, typename Container>
|
||||
class ArrayHandleExecutionManagerBase
|
||||
{
|
||||
private:
|
||||
typedef vtkm::cont::internal::ArrayContainerControl<T,Container>
|
||||
ContainerType;
|
||||
|
||||
public:
|
||||
template <typename DeviceAdapter>
|
||||
struct ExecutionTypes {
|
||||
private:
|
||||
typedef vtkm::cont::internal::ArrayTransfer<T,Container,DeviceAdapter>
|
||||
ArrayTransferType;
|
||||
public:
|
||||
typedef typename ArrayTransferType::PortalExecution Portal;
|
||||
typedef typename ArrayTransferType::PortalConstExecution PortalConst;
|
||||
};
|
||||
|
||||
/// The type of value held in the array (vtkm::Scalar, vtkm::Vector3, etc.)
|
||||
///
|
||||
typedef T ValueType;
|
||||
|
||||
/// An array portal that can be used in the control environment.
|
||||
///
|
||||
typedef typename ContainerType::PortalType PortalControl;
|
||||
typedef typename ContainerType::PortalConstType PortalConstControl;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual ~ArrayHandleExecutionManagerBase() { }
|
||||
|
||||
/// Returns the number of values stored in the array. Results are undefined
|
||||
/// if data has not been loaded or allocated.
|
||||
///
|
||||
virtual vtkm::Id GetNumberOfValues() const = 0;
|
||||
|
||||
/// Allocates a large enough array in the execution environment and copies
|
||||
/// the given data to that array. The allocated array can later be accessed
|
||||
/// via the GetPortalConstExecution method. If control and execution share
|
||||
/// arrays, then this method may save the iterators to be returned in the \c
|
||||
/// GetPortalConst methods.
|
||||
///
|
||||
virtual void LoadDataForInput(PortalConstControl portal) = 0;
|
||||
|
||||
/// Allocates a large enough array in the execution environment and copies
|
||||
/// the given data to that array. The allocated array can later be accessed
|
||||
/// via the GetPortalConstExecution method. If control and execution share
|
||||
/// arrays, then this method may save the iterators to be returned in the \c
|
||||
/// GetPortalConst methods.
|
||||
///
|
||||
virtual void LoadDataForInput(const ContainerType &controlArray) = 0;
|
||||
|
||||
/// Allocates a large enough array in the execution environment and copies
|
||||
/// the given data to that array. The allocated array can later be accessed
|
||||
/// via the GetPortalExection method. If control and execution share arrays,
|
||||
/// then this method may save the iterators of the container to be returned
|
||||
/// in the \c GetPortal* methods.
|
||||
///
|
||||
virtual void LoadDataForInPlace(ContainerType &controlArray) = 0;
|
||||
|
||||
/// Allocates an array in the execution environment of the specified size.
|
||||
/// If control and execution share arrays, then this class can allocate
|
||||
/// data using the given ArrayContainerExecution and remember its iterators
|
||||
/// so that it can be used directly in the execution environment.
|
||||
///
|
||||
virtual void AllocateArrayForOutput(ContainerType &controlArray,
|
||||
vtkm::Id numberOfValues) = 0;
|
||||
|
||||
/// Allocates data in the given ArrayContainerControl and copies data held
|
||||
/// in the execution environment (managed by this class) into the control
|
||||
/// array. If control and execution share arrays, this can be no operation.
|
||||
/// This method should only be called after AllocateArrayForOutput is
|
||||
/// called.
|
||||
///
|
||||
virtual void RetrieveOutputData(ContainerType &controlArray) const = 0;
|
||||
|
||||
/// \brief Reduces the size of the array without changing its values.
|
||||
///
|
||||
/// This method allows you to resize the array without reallocating it. The
|
||||
/// number of entries in the array is changed to \c numberOfValues. The data
|
||||
/// in the array (from indices 0 to \c numberOfValues - 1) are the same, but
|
||||
/// \c numberOfValues must be equal or less than the preexisting size
|
||||
/// (returned from GetNumberOfValues). That is, this method can only be used
|
||||
/// to shorten the array, not lengthen.
|
||||
///
|
||||
virtual void Shrink(vtkm::Id numberOfValues) = 0;
|
||||
|
||||
/// Returns an array portal that can be used in the execution environment.
|
||||
/// This portal was defined in either LoadDataForInput or
|
||||
/// AllocateArrayForOutput. If control and environment share memory space,
|
||||
/// this class may return the iterator from the \c controlArray.
|
||||
///
|
||||
template<typename DeviceAdapter>
|
||||
VTKM_CONT_EXPORT
|
||||
typename ExecutionTypes<DeviceAdapter>::Portal
|
||||
GetPortalExecution(DeviceAdapter device)
|
||||
{
|
||||
this->VerifyDeviceAdapter(device);
|
||||
|
||||
typename ExecutionTypes<DeviceAdapter>::Portal portal;
|
||||
this->GetPortalExecutionImpl(&portal);
|
||||
return portal;
|
||||
}
|
||||
|
||||
/// Const version of GetPortal.
|
||||
///
|
||||
template<typename DeviceAdapter>
|
||||
VTKM_CONT_EXPORT
|
||||
typename ExecutionTypes<DeviceAdapter>::PortalConst
|
||||
GetPortalConstExecution(DeviceAdapter device) const
|
||||
{
|
||||
this->VerifyDeviceAdapter(device);
|
||||
|
||||
typename ExecutionTypes<DeviceAdapter>::PortalConst portal;
|
||||
this->GetPortalConstExecutionImpl(&portal);
|
||||
return portal;
|
||||
}
|
||||
|
||||
/// Frees any resources (i.e. memory) allocated for the exeuction
|
||||
/// environment, if any.
|
||||
///
|
||||
virtual void ReleaseResources() = 0;
|
||||
|
||||
template<typename DeviceAdapter>
|
||||
VTKM_CONT_EXPORT
|
||||
bool IsDeviceAdapter(DeviceAdapter) const
|
||||
{
|
||||
return this->IsDeviceAdapterImpl(
|
||||
vtkm::cont::internal::DeviceAdapterTraits<DeviceAdapter>::GetId());
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void GetPortalExecutionImpl(void *portalExecution) = 0;
|
||||
|
||||
virtual void GetPortalConstExecutionImpl(
|
||||
void *portalConstExecution) const = 0;
|
||||
|
||||
virtual bool IsDeviceAdapterImpl(
|
||||
const vtkm::cont::internal::DeviceAdapterId &id) const = 0;
|
||||
|
||||
private:
|
||||
template<typename DeviceAdapter>
|
||||
VTKM_CONT_EXPORT
|
||||
void VerifyDeviceAdapter(DeviceAdapter device) const
|
||||
{
|
||||
if (!this->IsDeviceAdapter(device))
|
||||
{
|
||||
throw vtkm::cont::ErrorControlInternal("Device Adapter Mismatch");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/// \brief Used by ArrayHandle to manage execution arrays
|
||||
///
|
||||
/// This is an internal class used by ArrayHandle to manage execution arrays.
|
||||
/// This class uses virtual method polymorphism to allocate and transfer data
|
||||
/// in the execution environment. This virtual method polymorphism allows the
|
||||
/// ArrayHandle to change its device at run time.
|
||||
///
|
||||
template<typename T,
|
||||
typename Container,
|
||||
typename DeviceAdapter>
|
||||
class ArrayHandleExecutionManager
|
||||
: public ArrayHandleExecutionManagerBase<T, Container>
|
||||
{
|
||||
typedef ArrayHandleExecutionManagerBase<T, Container> Superclass;
|
||||
typedef vtkm::cont::internal::ArrayTransfer<T,Container,DeviceAdapter>
|
||||
ArrayTransferType;
|
||||
typedef vtkm::cont::internal::ArrayContainerControl<T,Container> ContainerType;
|
||||
|
||||
public:
|
||||
typedef typename ArrayTransferType::PortalControl PortalControl;
|
||||
typedef typename ArrayTransferType::PortalConstControl PortalConstControl;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
vtkm::Id GetNumberOfValues() const
|
||||
{
|
||||
return this->Transfer.GetNumberOfValues();
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void LoadDataForInput(PortalConstControl portal)
|
||||
{
|
||||
this->Transfer.LoadDataForInput(portal);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void LoadDataForInput(const ContainerType &controlArray)
|
||||
{
|
||||
this->Transfer.LoadDataForInput(controlArray);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void LoadDataForInPlace(ContainerType &controlArray)
|
||||
{
|
||||
this->Transfer.LoadDataForInPlace(controlArray);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void AllocateArrayForOutput(ContainerType &controlArray, Id numberOfValues)
|
||||
{
|
||||
this->Transfer.AllocateArrayForOutput(controlArray, numberOfValues);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void RetrieveOutputData(ContainerType &controlArray) const
|
||||
{
|
||||
this->Transfer.RetrieveOutputData(controlArray);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void Shrink(Id numberOfValues)
|
||||
{
|
||||
this->Transfer.Shrink(numberOfValues);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void ReleaseResources()
|
||||
{
|
||||
this->Transfer.ReleaseResources();
|
||||
}
|
||||
|
||||
protected:
|
||||
VTKM_CONT_EXPORT
|
||||
void GetPortalExecutionImpl(void *portalExecutionVoid)
|
||||
{
|
||||
typedef typename ArrayTransferType::PortalExecution PortalType;
|
||||
PortalType portalExecution = this->Transfer.GetPortalExecution();
|
||||
*reinterpret_cast<PortalType *>(portalExecutionVoid) = portalExecution;
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void GetPortalConstExecutionImpl(void *portalExecutionVoid) const
|
||||
{
|
||||
typedef typename ArrayTransferType::PortalConstExecution PortalType;
|
||||
PortalType portalExecution = this->Transfer.GetPortalConstExecution();
|
||||
*reinterpret_cast<PortalType *>(portalExecutionVoid) = portalExecution;
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
bool IsDeviceAdapterImpl(const DeviceAdapterId &id) const
|
||||
{
|
||||
return id == vtkm::cont::internal::DeviceAdapterTraits<DeviceAdapter>::GetId();
|
||||
}
|
||||
|
||||
private:
|
||||
ArrayTransferType Transfer;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::internal
|
||||
|
||||
#endif //vtkm_cont_exec_ArrayHandleExecutionManager_h
|
172
vtkm/cont/internal/ArrayManagerExecution.h
Normal file
172
vtkm/cont/internal/ArrayManagerExecution.h
Normal file
@ -0,0 +1,172 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_internal_ArrayManagerExecution_h
|
||||
#define vtkm_cont_internal_ArrayManagerExecution_h
|
||||
|
||||
#include <vtkm/cont/internal/DeviceAdapterTag.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
namespace internal {
|
||||
|
||||
/// \brief Class that manages data in the execution environment.
|
||||
///
|
||||
/// This templated class must be partially specialized for each
|
||||
/// DeviceAdapterTag crated, which will define the implementation for that tag.
|
||||
///
|
||||
/// This is a class that is responsible for allocating data in the execution
|
||||
/// environment and copying data back and forth between control and
|
||||
/// execution. It is also expected that this class will automatically release
|
||||
/// any resources in its destructor.
|
||||
///
|
||||
/// This class typically takes on one of two forms. If the control and
|
||||
/// execution environments have seperate memory spaces, then this class
|
||||
/// behaves how you would expect. It allocates/deallocates arrays and copies
|
||||
/// data. However, if the control and execution environments share the same
|
||||
/// memory space, this class should delegate all its operations to the
|
||||
/// ArrayContainerControl. The latter can probably be implemented with a
|
||||
/// trivial subclass of
|
||||
/// vtkm::cont::internal::ArrayManagerExecutionShareWithControl.
|
||||
///
|
||||
template<typename T, class ArrayContainerControlTag, class DeviceAdapterTag>
|
||||
class ArrayManagerExecution
|
||||
#ifdef VTKM_DOXYGEN_ONLY
|
||||
{
|
||||
private:
|
||||
typedef vtkm::cont::internal::ArrayContainerControl<T,ArrayContainerControlTag>
|
||||
ContainerType;
|
||||
|
||||
public:
|
||||
/// The type of value held in the array (vtkm::Scalar, vtkm::Vector3, etc.)
|
||||
///
|
||||
typedef T ValueType;
|
||||
|
||||
/// An array portal that can be used in the execution environment to access
|
||||
/// portions of the arrays. This example defines the portal with a pointer,
|
||||
/// but any portal with methods that can be called and data that can be
|
||||
/// accessed from the execution environment can be used.
|
||||
///
|
||||
typedef vtkm::exec::internal::ArrayPortalFromIterators<ValueType*> PortalType;
|
||||
|
||||
/// Const version of PortalType. You must be able to cast PortalType to
|
||||
/// PortalConstType.
|
||||
///
|
||||
typedef vtkm::exec::internal::ArrayPortalFromIterators<const ValueType*>
|
||||
PortalConstType;
|
||||
|
||||
/// Returns the number of values stored in the array. Results are undefined
|
||||
/// if data has not been loaded or allocated.
|
||||
///
|
||||
VTKM_CONT_EXPORT vtkm::Id GetNumberOfValues() const;
|
||||
|
||||
/// Allocates a large enough array in the execution environment and copies
|
||||
/// the given data to that array. The allocated array can later be accessed
|
||||
/// via the GetPortalConst method. If control and execution share arrays,
|
||||
/// then this method may save the iterators to be returned in the \c
|
||||
/// GetPortalConst method.
|
||||
///
|
||||
VTKM_CONT_EXPORT void LoadDataForInput(
|
||||
typename ContainerType::PortalConstType portal);
|
||||
|
||||
/// Allocates a large enough array in the execution environment and copies
|
||||
/// the given data to that array. The allocated array can later be accessed
|
||||
/// via the GetPortal method. If control and execution share arrays, then
|
||||
/// this method may save the iterators of the container to be returned in the
|
||||
/// \c GetPortal* methods.
|
||||
///
|
||||
VTKM_CONT_EXPORT void LoadDataForInPlace(PortalType portal);
|
||||
|
||||
/// Allocates an array in the execution environment of the specified size.
|
||||
/// If control and execution share arrays, then this class can allocate
|
||||
/// data using the given ArrayContainerExecution and remember its iterators
|
||||
/// so that it can be used directly in the execution environment.
|
||||
///
|
||||
VTKM_CONT_EXPORT void AllocateArrayForOutput(ContainerType &controlArray,
|
||||
vtkm::Id numberOfValues);
|
||||
|
||||
/// Allocates data in the given ArrayContainerControl and copies data held
|
||||
/// in the execution environment (managed by this class) into the control
|
||||
/// array. If control and execution share arrays, this can be no operation.
|
||||
/// This method should only be called after AllocateArrayForOutput is
|
||||
/// called.
|
||||
///
|
||||
VTKM_CONT_EXPORT void RetrieveOutputData(ContainerType &controlArray) const;
|
||||
|
||||
/// Similar to RetrieveOutputData except that instead of writing to the
|
||||
/// controlArray itself, it writes to the given control environment
|
||||
/// iterator. This allows the user to retrieve data without necessarily
|
||||
/// allocating an array in the ArrayContainerControl (assuming that control
|
||||
/// and exeuction have seperate memory spaces).
|
||||
///
|
||||
template <class IteratorTypeControl>
|
||||
VTKM_CONT_EXPORT void CopyInto(IteratorTypeControl dest) const;
|
||||
|
||||
/// \brief Reduces the size of the array without changing its values.
|
||||
///
|
||||
/// This method allows you to resize the array without reallocating it. The
|
||||
/// number of entries in the array is changed to \c numberOfValues. The data
|
||||
/// in the array (from indices 0 to \c numberOfValues - 1) are the same, but
|
||||
/// \c numberOfValues must be equal or less than the preexisting size
|
||||
/// (returned from GetNumberOfValues). That is, this method can only be used
|
||||
/// to shorten the array, not lengthen.
|
||||
///
|
||||
VTKM_CONT_EXPORT void Shrink(vtkm::Id numberOfValues);
|
||||
|
||||
/// Returns an array portal that can be used in the execution environment.
|
||||
/// This portal was defined in either LoadDataForInput or
|
||||
/// AllocateArrayForOutput. If control and environment share memory space,
|
||||
/// this class may return the iterator from the \c controlArray.
|
||||
///
|
||||
VTKM_CONT_EXPORT PortalType GetPortal();
|
||||
|
||||
/// Const version of GetPortal.
|
||||
///
|
||||
VTKM_CONT_EXPORT PortalConstType GetPortalConst() const;
|
||||
|
||||
/// Frees any resources (i.e. memory) allocated for the exeuction
|
||||
/// environment, if any.
|
||||
///
|
||||
VTKM_CONT_EXPORT void ReleaseResources();
|
||||
};
|
||||
#else // VTKM_DOXGEN_ONLY
|
||||
;
|
||||
#endif // VTKM_DOXYGEN_ONLY
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::internal
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// These includes are intentionally placed here after the declaration of the
|
||||
// ArrayManagerExecution template prototype, which all the implementations
|
||||
// need.
|
||||
|
||||
#if VTKM_DEVICE_ADAPTER == VTKM_DEVICE_ADAPTER_SERIAL
|
||||
#include <vtkm/cont/internal/ArrayManagerExecutionSerial.h>
|
||||
// #elif VTKM_DEVICE_ADAPTER == VTKM_DEVICE_ADAPTER_CUDA
|
||||
// #include <vtkm/cuda/cont/internal/ArrayManagerExecutionCuda.h>
|
||||
// #elif VTKM_DEVICE_ADAPTER == VTKM_DEVICE_ADAPTER_OPENMP
|
||||
// #include <vtkm/openmp/cont/internal/ArrayManagerExecutionOpenMP.h>
|
||||
// #elif VTKM_DEVICE_ADAPTER == VTKM_DEVICE_ADAPTER_TBB
|
||||
// #include <vtkm/tbb/cont/internal/ArrayManagerExecutionTBB.h>
|
||||
#endif
|
||||
|
||||
#endif //vtkm_cont_internal_ArrayManagerExecution_h
|
49
vtkm/cont/internal/ArrayManagerExecutionSerial.h
Normal file
49
vtkm/cont/internal/ArrayManagerExecutionSerial.h
Normal file
@ -0,0 +1,49 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_internal_ArrayManagerExecutionSerial_h
|
||||
#define vtkm_cont_internal_ArrayManagerExecutionSerial_h
|
||||
|
||||
#include <vtkm/cont/internal/ArrayManagerExecution.h>
|
||||
#include <vtkm/cont/internal/ArrayManagerExecutionShareWithControl.h>
|
||||
#include <vtkm/cont/internal/DeviceAdapterTagSerial.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
namespace internal {
|
||||
|
||||
template <typename T, class ArrayContainerControlTag>
|
||||
class ArrayManagerExecution
|
||||
<T, ArrayContainerControlTag, vtkm::cont::DeviceAdapterTagSerial>
|
||||
: public vtkm::cont::internal::ArrayManagerExecutionShareWithControl
|
||||
<T, ArrayContainerControlTag>
|
||||
{
|
||||
public:
|
||||
typedef vtkm::cont::internal::ArrayManagerExecutionShareWithControl
|
||||
<T, ArrayContainerControlTag> Superclass;
|
||||
typedef typename Superclass::ValueType ValueType;
|
||||
typedef typename Superclass::PortalType PortalType;
|
||||
typedef typename Superclass::PortalConstType PortalConstType;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::internal
|
||||
|
||||
#endif //vtkm_cont_internal_ArrayManagerExecutionSerial_h
|
176
vtkm/cont/internal/ArrayManagerExecutionShareWithControl.h
Normal file
176
vtkm/cont/internal/ArrayManagerExecutionShareWithControl.h
Normal file
@ -0,0 +1,176 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_internal_ArrayManagerExecutionShareWithControl_h
|
||||
#define vtkm_cont_internal_ArrayManagerExecutionShareWithControl_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
#include <vtkm/cont/Assert.h>
|
||||
#include <vtkm/cont/ArrayContainerControl.h>
|
||||
#include <vtkm/cont/internal/ArrayPortalShrink.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
namespace internal {
|
||||
|
||||
/// \c ArrayManagerExecutionShareWithControl provides an implementation for a
|
||||
/// \c ArrayManagerExecution class for a device adapter when the execution
|
||||
/// and control environments share memory. This class basically defers all its
|
||||
/// calls to an \c ArrayContainerControl class and uses the array allocated
|
||||
/// there.
|
||||
///
|
||||
template<typename T, class ArrayContainerControlTag>
|
||||
class ArrayManagerExecutionShareWithControl
|
||||
{
|
||||
public:
|
||||
typedef T ValueType;
|
||||
typedef vtkm::cont::internal
|
||||
::ArrayContainerControl<ValueType, ArrayContainerControlTag>
|
||||
ContainerType;
|
||||
typedef vtkm::cont::internal::ArrayPortalShrink<
|
||||
typename ContainerType::PortalType> PortalType;
|
||||
typedef vtkm::cont::internal::ArrayPortalShrink<
|
||||
typename ContainerType::PortalConstType> PortalConstType;
|
||||
|
||||
VTKM_CONT_EXPORT ArrayManagerExecutionShareWithControl()
|
||||
: PortalValid(false), ConstPortalValid(false) { }
|
||||
|
||||
/// Returns the size of the saved portal.
|
||||
///
|
||||
VTKM_CONT_EXPORT vtkm::Id GetNumberOfValues() const {
|
||||
VTKM_ASSERT_CONT(this->ConstPortalValid);
|
||||
return this->ConstPortal.GetNumberOfValues();
|
||||
}
|
||||
|
||||
/// Saves the given iterators to be returned later.
|
||||
///
|
||||
VTKM_CONT_EXPORT void LoadDataForInput(PortalConstType portal)
|
||||
{
|
||||
this->ConstPortal = portal;
|
||||
this->ConstPortalValid = true;
|
||||
|
||||
// Non-const versions not defined.
|
||||
this->PortalValid = false;
|
||||
}
|
||||
|
||||
/// Saves the given iterators to be returned later.
|
||||
///
|
||||
VTKM_CONT_EXPORT void LoadDataForInPlace(PortalType portal)
|
||||
{
|
||||
// This only works if there is a valid cast from non-const to const
|
||||
// iterator.
|
||||
this->LoadDataForInput(portal);
|
||||
|
||||
this->Portal = portal;
|
||||
this->PortalValid = true;
|
||||
}
|
||||
|
||||
/// Actually just allocates memory in the given \p controlArray.
|
||||
///
|
||||
VTKM_CONT_EXPORT void AllocateArrayForOutput(ContainerType &controlArray,
|
||||
vtkm::Id numberOfValues)
|
||||
{
|
||||
controlArray.Allocate(numberOfValues);
|
||||
|
||||
this->Portal = controlArray.GetPortal();
|
||||
this->PortalValid = true;
|
||||
|
||||
this->ConstPortal = controlArray.GetPortalConst();
|
||||
this->ConstPortalValid = true;
|
||||
}
|
||||
|
||||
/// This method is a no-op (except for a few checks). Any data written to
|
||||
/// this class's iterators should already be written to the given \c
|
||||
/// controlArray (under correct operation).
|
||||
///
|
||||
VTKM_CONT_EXPORT void RetrieveOutputData(ContainerType &controlArray) const
|
||||
{
|
||||
VTKM_ASSERT_CONT(this->ConstPortalValid);
|
||||
VTKM_ASSERT_CONT(controlArray.GetPortalConst().GetIteratorBegin() ==
|
||||
this->ConstPortal.GetIteratorBegin());
|
||||
controlArray.Shrink(this->ConstPortal.GetNumberOfValues());
|
||||
}
|
||||
|
||||
/// This methods copies data from the execution array into the given
|
||||
/// iterator.
|
||||
///
|
||||
template <class IteratorTypeControl>
|
||||
VTKM_CONT_EXPORT void CopyInto(IteratorTypeControl dest) const
|
||||
{
|
||||
VTKM_ASSERT_CONT(this->ConstPortalValid);
|
||||
std::copy(this->ConstPortal.GetIteratorBegin(),
|
||||
this->ConstPortal.GetIteratorEnd(),
|
||||
dest);
|
||||
}
|
||||
|
||||
/// Adjusts saved end iterators to resize array.
|
||||
///
|
||||
VTKM_CONT_EXPORT void Shrink(vtkm::Id numberOfValues)
|
||||
{
|
||||
VTKM_ASSERT_CONT(this->ConstPortalValid);
|
||||
this->ConstPortal.Shrink(numberOfValues);
|
||||
|
||||
if (this->PortalValid)
|
||||
{
|
||||
this->Portal.Shrink(numberOfValues);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the portal previously saved from an \c ArrayContainerControl.
|
||||
///
|
||||
VTKM_CONT_EXPORT PortalType GetPortal()
|
||||
{
|
||||
VTKM_ASSERT_CONT(this->PortalValid);
|
||||
return this->Portal;
|
||||
}
|
||||
|
||||
/// Const version of GetPortal.
|
||||
///
|
||||
VTKM_CONT_EXPORT PortalConstType GetPortalConst() const
|
||||
{
|
||||
VTKM_ASSERT_CONT(this->ConstPortalValid);
|
||||
return this->ConstPortal;
|
||||
}
|
||||
|
||||
/// A no-op.
|
||||
///
|
||||
VTKM_CONT_EXPORT void ReleaseResources() { }
|
||||
|
||||
private:
|
||||
// Not implemented.
|
||||
ArrayManagerExecutionShareWithControl(
|
||||
ArrayManagerExecutionShareWithControl<T, ArrayContainerControlTag> &);
|
||||
void operator=(
|
||||
ArrayManagerExecutionShareWithControl<T, ArrayContainerControlTag> &);
|
||||
|
||||
PortalType Portal;
|
||||
bool PortalValid;
|
||||
|
||||
PortalConstType ConstPortal;
|
||||
bool ConstPortalValid;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::internal
|
||||
|
||||
#endif //vtkm_cont_internal_ArrayManagerExecutionShareWithControl_h
|
101
vtkm/cont/internal/ArrayPortalFromIterators.h
Normal file
101
vtkm/cont/internal/ArrayPortalFromIterators.h
Normal file
@ -0,0 +1,101 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_internal_ArrayPortalFromIterators_h
|
||||
#define vtkm_cont_internal_ArrayPortalFromIterators_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/cont/ArrayPortal.h>
|
||||
#include <vtkm/cont/Assert.h>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
namespace internal {
|
||||
|
||||
/// This templated implementation of an ArrayPortal allows you to adapt a pair
|
||||
/// of begin/end iterators to an ArrayPortal interface.
|
||||
///
|
||||
template<class IteratorT>
|
||||
class ArrayPortalFromIterators
|
||||
{
|
||||
public:
|
||||
typedef IteratorT IteratorType;
|
||||
typedef typename std::iterator_traits<IteratorType>::value_type ValueType;
|
||||
|
||||
VTKM_CONT_EXPORT ArrayPortalFromIterators() { }
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
ArrayPortalFromIterators(IteratorType begin, IteratorType end)
|
||||
: BeginIterator(begin), EndIterator(end)
|
||||
{
|
||||
VTKM_ASSERT_CONT(this->GetNumberOfValues() >= 0);
|
||||
}
|
||||
|
||||
/// Copy constructor for any other ArrayPortalFromIterators 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 OtherIteratorT>
|
||||
VTKM_CONT_EXPORT
|
||||
ArrayPortalFromIterators(const ArrayPortalFromIterators<OtherIteratorT> &src)
|
||||
: BeginIterator(src.GetIteratorBegin()),
|
||||
EndIterator(src.GetIteratorEnd())
|
||||
{ }
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
vtkm::Id GetNumberOfValues() const {
|
||||
return std::distance(this->BeginIterator, this->EndIterator);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
ValueType Get(vtkm::Id index) const {
|
||||
return *this->IteratorAt(index);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void Set(vtkm::Id index, ValueType value) const {
|
||||
*this->IteratorAt(index) = value;
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorBegin() const { return this->BeginIterator; }
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorEnd() const { return this->EndIterator; }
|
||||
|
||||
private:
|
||||
IteratorType BeginIterator;
|
||||
IteratorType EndIterator;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType IteratorAt(vtkm::Id index) const {
|
||||
VTKM_ASSERT_CONT(index >= 0);
|
||||
VTKM_ASSERT_CONT(index < this->GetNumberOfValues());
|
||||
|
||||
return this->BeginIterator + index;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::internal
|
||||
|
||||
#endif //vtkm_cont_internal_ArrayPortalFromIterators_h
|
121
vtkm/cont/internal/ArrayPortalShrink.h
Normal file
121
vtkm/cont/internal/ArrayPortalShrink.h
Normal file
@ -0,0 +1,121 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_internal_ArrayPortalShrink_h
|
||||
#define vtkm_cont_internal_ArrayPortalShrink_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/cont/ArrayPortal.h>
|
||||
#include <vtkm/cont/Assert.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
namespace internal {
|
||||
|
||||
/// This ArrayPortal adapter is a utility that allows you to shrink the
|
||||
/// (reported) array size without actually modifying the underlying allocation.
|
||||
///
|
||||
template<class PortalT>
|
||||
class ArrayPortalShrink
|
||||
{
|
||||
public:
|
||||
typedef PortalT DelegatePortalType;
|
||||
|
||||
typedef typename DelegatePortalType::ValueType ValueType;
|
||||
typedef typename DelegatePortalType::IteratorType IteratorType;
|
||||
|
||||
VTKM_CONT_EXPORT ArrayPortalShrink() : NumberOfValues(0) { }
|
||||
|
||||
VTKM_CONT_EXPORT ArrayPortalShrink(const DelegatePortalType &delegatePortal)
|
||||
: DelegatePortal(delegatePortal),
|
||||
NumberOfValues(delegatePortal.GetNumberOfValues())
|
||||
{ }
|
||||
|
||||
VTKM_CONT_EXPORT ArrayPortalShrink(const DelegatePortalType &delegatePortal,
|
||||
vtkm::Id numberOfValues)
|
||||
: DelegatePortal(delegatePortal), NumberOfValues(numberOfValues)
|
||||
{
|
||||
VTKM_ASSERT_CONT(numberOfValues <= delegatePortal.GetNumberOfValues());
|
||||
}
|
||||
|
||||
/// Copy constructor for any other ArrayPortalShrink with a delegate type
|
||||
/// that can be copied to this type. This allows us to do any type casting
|
||||
/// the delegates can do (like the non-const to const cast).
|
||||
///
|
||||
template<class OtherDelegateType>
|
||||
VTKM_CONT_EXPORT
|
||||
ArrayPortalShrink(const ArrayPortalShrink<OtherDelegateType> &src)
|
||||
: DelegatePortal(src.GetDelegatePortal()),
|
||||
NumberOfValues(src.GetNumberOfValues())
|
||||
{ }
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
vtkm::Id GetNumberOfValues() const { return this->NumberOfValues; }
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
ValueType Get(vtkm::Id index) const {
|
||||
VTKM_ASSERT_CONT(index >= 0);
|
||||
VTKM_ASSERT_CONT(index < this->GetNumberOfValues());
|
||||
return this->DelegatePortal.Get(index);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void Set(vtkm::Id index, ValueType value) const {
|
||||
VTKM_ASSERT_CONT(index >= 0);
|
||||
VTKM_ASSERT_CONT(index < this->GetNumberOfValues());
|
||||
this->DelegatePortal.Set(index, value);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorBegin() const {
|
||||
return this->DelegatePortal.GetIteratorBegin();
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorEnd() const {
|
||||
IteratorType iterator = this->DelegatePortal.GetIteratorBegin();
|
||||
std::advance(iterator, this->GetNumberOfValues());
|
||||
return iterator;
|
||||
}
|
||||
|
||||
/// Special method in this ArrayPortal that allows you to shrink the
|
||||
/// (exposed) array.
|
||||
///
|
||||
VTKM_CONT_EXPORT
|
||||
void Shrink(vtkm::Id numberOfValues) {
|
||||
VTKM_ASSERT_CONT(numberOfValues < this->GetNumberOfValues());
|
||||
this->NumberOfValues = numberOfValues;
|
||||
}
|
||||
|
||||
/// Get a copy of the delegate portal. Although safe, this is probably only
|
||||
/// useful internally. (It is exposed as public for the templated copy
|
||||
/// constructor.)
|
||||
///
|
||||
DelegatePortalType GetDelegatePortal() const { return this->DelegatePortal; }
|
||||
|
||||
private:
|
||||
DelegatePortalType DelegatePortal;
|
||||
vtkm::Id NumberOfValues;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::internal
|
||||
|
||||
#endif //vtkm_cont_internal_ArrayPortalShrink_h
|
193
vtkm/cont/internal/ArrayTransfer.h
Normal file
193
vtkm/cont/internal/ArrayTransfer.h
Normal file
@ -0,0 +1,193 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_internal_ArrayTransfer_h
|
||||
#define vtkm_cont_internal_ArrayTransfer_h
|
||||
|
||||
#include <vtkm/cont/ArrayContainerControl.h>
|
||||
#include <vtkm/cont/internal/ArrayManagerExecution.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
namespace internal {
|
||||
|
||||
/// \brief Class that manages the transfer of data between control and execution.
|
||||
///
|
||||
/// This templated class provides a mechanism (used by the ArrayHandle) to
|
||||
/// transfer data from the control environment to the execution environment and
|
||||
/// back. The interface for ArrayTransfer is nearly identical to that of
|
||||
/// ArrayManagerExecution and the default implementation simply delegates all
|
||||
/// calls to that class.
|
||||
///
|
||||
/// The primary motivation for having a separate class is that the
|
||||
/// ArrayManagerExecution is meant to be specialized for each device adapter
|
||||
/// whee as the ArrayTransfer is meant to be specialized for each array
|
||||
/// container (or specific combination of container and device adapter). Thus,
|
||||
/// transfers for most containers will be delegated through the
|
||||
/// ArrayManagerExecution, but some containers, like implicit containers, will
|
||||
/// be specialized to transfer through a different path.
|
||||
///
|
||||
template<typename T, class ArrayContainerControlTag, class DeviceAdapterTag>
|
||||
class ArrayTransfer
|
||||
{
|
||||
private:
|
||||
typedef vtkm::cont::internal::ArrayContainerControl<T,ArrayContainerControlTag>
|
||||
ContainerType;
|
||||
typedef vtkm::cont::internal::ArrayManagerExecution<
|
||||
T,ArrayContainerControlTag,DeviceAdapterTag> ArrayManagerType;
|
||||
|
||||
public:
|
||||
/// The type of value held in the array (vtkm::Scalar, vtkm::Vector3, etc.)
|
||||
///
|
||||
typedef T ValueType;
|
||||
|
||||
/// An array portal that can be used in the control environment.
|
||||
///
|
||||
typedef typename ContainerType::PortalType PortalControl;
|
||||
typedef typename ContainerType::PortalConstType PortalConstControl;
|
||||
|
||||
/// An array portal that can be used in the execution environment.
|
||||
///
|
||||
typedef typename ArrayManagerType::PortalType PortalExecution;
|
||||
typedef typename ArrayManagerType::PortalConstType PortalConstExecution;
|
||||
|
||||
|
||||
/// Returns the number of values stored in the array. Results are undefined
|
||||
/// if data has not been loaded or allocated.
|
||||
///
|
||||
VTKM_CONT_EXPORT vtkm::Id GetNumberOfValues() const
|
||||
{
|
||||
return this->ArrayManager.GetNumberOfValues();
|
||||
}
|
||||
|
||||
/// Allocates a large enough array in the execution environment and copies
|
||||
/// the given data to that array. The allocated array can later be accessed
|
||||
/// via the GetPortalConstExecution method. If control and execution share
|
||||
/// arrays, then this method may save the iterators to be returned in the \c
|
||||
/// GetPortalConst methods.
|
||||
///
|
||||
VTKM_CONT_EXPORT void LoadDataForInput(PortalConstControl portal)
|
||||
{
|
||||
this->ArrayManager.LoadDataForInput(portal);
|
||||
}
|
||||
|
||||
/// Allocates a large enough array in the execution environment and copies
|
||||
/// the given data to that array. The allocated array can later be accessed
|
||||
/// via the GetPortalConstExecution method. If control and execution share
|
||||
/// arrays, then this method may save the iterators to be returned in the \c
|
||||
/// GetPortalConst methods.
|
||||
///
|
||||
VTKM_CONT_EXPORT void LoadDataForInput(const ContainerType &controlArray)
|
||||
{
|
||||
this->ArrayManager.LoadDataForInput(controlArray.GetPortalConst());
|
||||
}
|
||||
|
||||
/// Allocates a large enough array in the execution environment and copies
|
||||
/// the given data to that array. The allocated array can later be accessed
|
||||
/// via the GetPortalExection method. If control and execution share arrays,
|
||||
/// then this method may save the iterators of the container to be returned
|
||||
/// in the \c GetPortal* methods.
|
||||
///
|
||||
VTKM_CONT_EXPORT void LoadDataForInPlace(ContainerType &controlArray)
|
||||
{
|
||||
this->ArrayManager.LoadDataForInPlace(controlArray.GetPortal());
|
||||
}
|
||||
|
||||
/// Allocates an array in the execution environment of the specified size.
|
||||
/// If control and execution share arrays, then this class can allocate
|
||||
/// data using the given ArrayContainerExecution and remember its iterators
|
||||
/// so that it can be used directly in the execution environment.
|
||||
///
|
||||
VTKM_CONT_EXPORT void AllocateArrayForOutput(ContainerType &controlArray,
|
||||
vtkm::Id numberOfValues)
|
||||
{
|
||||
this->ArrayManager.AllocateArrayForOutput(controlArray, numberOfValues);
|
||||
}
|
||||
|
||||
/// Allocates data in the given ArrayContainerControl and copies data held
|
||||
/// in the execution environment (managed by this class) into the control
|
||||
/// array. If control and execution share arrays, this can be no operation.
|
||||
/// This method should only be called after AllocateArrayForOutput is
|
||||
/// called.
|
||||
///
|
||||
VTKM_CONT_EXPORT void RetrieveOutputData(ContainerType &controlArray) const
|
||||
{
|
||||
this->ArrayManager.RetrieveOutputData(controlArray);
|
||||
}
|
||||
|
||||
/// Similar to RetrieveOutputData except that instead of writing to the
|
||||
/// controlArray itself, it writes to the given control environment
|
||||
/// iterator. This allows the user to retrieve data without necessarily
|
||||
/// allocating an array in the ArrayContainerControl (assuming that control
|
||||
/// and exeuction have seperate memory spaces).
|
||||
///
|
||||
template <class IteratorTypeControl>
|
||||
VTKM_CONT_EXPORT void CopyInto(IteratorTypeControl dest) const
|
||||
{
|
||||
this->ArrayManager.CopyInto(dest);
|
||||
}
|
||||
|
||||
/// \brief Reduces the size of the array without changing its values.
|
||||
///
|
||||
/// This method allows you to resize the array without reallocating it. The
|
||||
/// number of entries in the array is changed to \c numberOfValues. The data
|
||||
/// in the array (from indices 0 to \c numberOfValues - 1) are the same, but
|
||||
/// \c numberOfValues must be equal or less than the preexisting size
|
||||
/// (returned from GetNumberOfValues). That is, this method can only be used
|
||||
/// to shorten the array, not lengthen.
|
||||
///
|
||||
VTKM_CONT_EXPORT void Shrink(vtkm::Id numberOfValues)
|
||||
{
|
||||
this->ArrayManager.Shrink(numberOfValues);
|
||||
}
|
||||
|
||||
/// Returns an array portal that can be used in the execution environment.
|
||||
/// This portal was defined in either LoadDataForInput or
|
||||
/// AllocateArrayForOutput. If control and environment share memory space,
|
||||
/// this class may return the iterator from the \c controlArray.
|
||||
///
|
||||
VTKM_CONT_EXPORT PortalExecution GetPortalExecution()
|
||||
{
|
||||
return this->ArrayManager.GetPortal();
|
||||
}
|
||||
|
||||
/// Const version of GetPortal.
|
||||
///
|
||||
VTKM_CONT_EXPORT PortalConstExecution GetPortalConstExecution() const
|
||||
{
|
||||
return this->ArrayManager.GetPortalConst();
|
||||
}
|
||||
|
||||
/// Frees any resources (i.e. memory) allocated for the exeuction
|
||||
/// environment, if any.
|
||||
///
|
||||
VTKM_CONT_EXPORT void ReleaseResources()
|
||||
{
|
||||
this->ArrayManager.ReleaseResources();
|
||||
}
|
||||
|
||||
private:
|
||||
ArrayManagerType ArrayManager;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::internal
|
||||
|
||||
#endif //vtkm_cont_internal_ArrayTransfer_h
|
38
vtkm/cont/internal/CMakeLists.txt
Normal file
38
vtkm/cont/internal/CMakeLists.txt
Normal file
@ -0,0 +1,38 @@
|
||||
##============================================================================
|
||||
## 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.
|
||||
##============================================================================
|
||||
|
||||
set(headers
|
||||
ArrayHandleExecutionManager.h
|
||||
ArrayManagerExecution.h
|
||||
ArrayManagerExecutionSerial.h
|
||||
ArrayManagerExecutionShareWithControl.h
|
||||
ArrayPortalFromIterators.h
|
||||
ArrayPortalShrink.h
|
||||
ArrayTransfer.h
|
||||
)
|
||||
|
||||
vtkm_declare_headers(${headers})
|
||||
|
||||
# These source files are actually compiled in the parent directory.
|
||||
# They are in a separate directory to highlight which objects are
|
||||
# internal and which are part of the external interface.
|
||||
#add_custom_target(vtkmContInternal ALL DEPENDS vtkmCont)
|
||||
|
||||
add_subdirectory(testing)
|
107
vtkm/cont/internal/DeviceAdapterTag.h
Normal file
107
vtkm/cont/internal/DeviceAdapterTag.h
Normal file
@ -0,0 +1,107 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_internal_DeviceAdapterTag_h
|
||||
#define vtkm_cont_internal_DeviceAdapterTag_h
|
||||
|
||||
#include <vtkm/internal/Configure.h>
|
||||
#include <vtkm/internal/ExportMacros.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
#define VTKM_DEVICE_ADAPTER_ERROR -1
|
||||
#define VTKM_DEVICE_ADAPTER_UNDEFINED 0
|
||||
#define VTKM_DEVICE_ADAPTER_SERIAL 1
|
||||
|
||||
#ifndef VTKM_DEVICE_ADAPTER
|
||||
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_SERIAL
|
||||
#endif // VTKM_DEVICE_ADAPTER
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
namespace internal {
|
||||
|
||||
typedef std::string DeviceAdapterId;
|
||||
|
||||
template<typename DeviceAdapter>
|
||||
struct DeviceAdapterTraits;
|
||||
|
||||
template<typename DeviceAdapter>
|
||||
struct DeviceAdapterTagCheck
|
||||
{
|
||||
static const bool Valid = false;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a tag named vtkm::cont::DeviceAdapterTagName and associated MPL
|
||||
/// structures to use this tag. Always use this macro (in the base namespace)
|
||||
/// when creating a device adapter.
|
||||
#define VTKM_CREATE_DEVICE_ADAPTER(Name) \
|
||||
namespace vtkm { \
|
||||
namespace cont { \
|
||||
struct DeviceAdapterTag##Name { }; \
|
||||
namespace internal { \
|
||||
template<> \
|
||||
struct DeviceAdapterTraits<vtkm::cont::DeviceAdapterTag##Name> { \
|
||||
static DeviceAdapterId GetId() { \
|
||||
return DeviceAdapterId(#Name); \
|
||||
} \
|
||||
}; \
|
||||
template<> \
|
||||
struct DeviceAdapterTagCheck<vtkm::cont::DeviceAdapterTag##Name> { \
|
||||
static const bool Valid = true; \
|
||||
}; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
/// Checks that the argument is a proper device adapter tag. This is a handy
|
||||
/// concept check for functions and classes to make sure that a template
|
||||
/// argument is actually a device adapter tag. (You can get weird errors
|
||||
/// elsewhere in the code when a mistake is made.)
|
||||
#define VTKM_IS_DEVICE_ADAPTER_TAG(tag) \
|
||||
BOOST_STATIC_ASSERT_MSG( \
|
||||
::vtkm::cont::internal::DeviceAdapterTagCheck<tag>::Valid, \
|
||||
"Provided type is not a valid VTKm device adapter tag.")
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
#if VTKM_DEVICE_ADAPTER == VTKM_DEVICE_ADAPTER_SERIAL
|
||||
|
||||
#include <vtkm/cont/internal/DeviceAdapterTagSerial.h>
|
||||
#define VTKM_DEFAULT_DEVICE_ADAPTER_TAG ::vtkm::cont::DeviceAdapterTagSerial
|
||||
|
||||
#elif (VTKM_DEVICE_ADAPTER == VTKM_DEVICE_ADAPTER_UNDEFINED) || !defined(VTKM_DEVICE_ADAPTER)
|
||||
|
||||
#ifndef VTKM_DEFAULT_DEVICE_ADAPTER_TAG
|
||||
#warning If device adapter is undefined, VTKM_DEFAULT_DEVICE_ADAPTER_TAG must be defined.
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#warning Unrecognized device adapter given.
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif //vtkm_cont_internal_DeviceAdapterTag_h
|
27
vtkm/cont/internal/DeviceAdapterTagSerial.h
Normal file
27
vtkm/cont/internal/DeviceAdapterTagSerial.h
Normal file
@ -0,0 +1,27 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_internal_DeviceAdapterTagSerial_h
|
||||
#define vtkm_cont_internal_DeviceAdapterTagSerial_h
|
||||
|
||||
#include <vtkm/cont/internal/DeviceAdapterTag.h>
|
||||
|
||||
VTKM_CREATE_DEVICE_ADAPTER(Serial);
|
||||
|
||||
#endif //vtkm_cont_internal_DeviceAdapterTagSerial_h
|
187
vtkm/cont/internal/IteratorFromArrayPortal.h
Normal file
187
vtkm/cont/internal/IteratorFromArrayPortal.h
Normal file
@ -0,0 +1,187 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_internal_IteratorFromArrayPortal_h
|
||||
#define vtkm_cont_internal_IteratorFromArrayPortal_h
|
||||
|
||||
#include <vtkm/cont/ArrayPortal.h>
|
||||
|
||||
#include <vtkm/cont/Assert.h>
|
||||
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
namespace internal {
|
||||
namespace detail {
|
||||
|
||||
template<class ArrayPortalType>
|
||||
struct IteratorFromArrayPortalValue {
|
||||
typedef typename ArrayPortalType::ValueType ValueType;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorFromArrayPortalValue(const ArrayPortalType &portal, vtkm::Id index)
|
||||
: Portal(portal), Index(index) { }
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void Swap( IteratorFromArrayPortalValue<ArrayPortalType> &rhs ) throw()
|
||||
{
|
||||
//we need use the explicit type not a proxy temp object
|
||||
//A proxy temp object would point to the same underlying data structure
|
||||
//and would not hold the old value of *this once *this was set to rhs.
|
||||
const ValueType aValue = *this;
|
||||
*this = rhs;
|
||||
rhs = aValue;
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorFromArrayPortalValue<ArrayPortalType> &operator=(
|
||||
const IteratorFromArrayPortalValue<ArrayPortalType> &rhs)
|
||||
{
|
||||
this->Portal.Set(this->Index, rhs.Portal.Get(rhs.Index));
|
||||
return *this;
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
ValueType operator=(ValueType value) {
|
||||
this->Portal.Set(this->Index, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
operator ValueType(void) const {
|
||||
return this->Portal.Get(this->Index);
|
||||
}
|
||||
|
||||
const ArrayPortalType& Portal;
|
||||
vtkm::Id Index;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class ArrayPortalType>
|
||||
class IteratorFromArrayPortal : public
|
||||
boost::iterator_facade<
|
||||
IteratorFromArrayPortal<ArrayPortalType>,
|
||||
typename ArrayPortalType::ValueType,
|
||||
boost::random_access_traversal_tag,
|
||||
detail::IteratorFromArrayPortalValue<ArrayPortalType>,
|
||||
vtkm::Id>
|
||||
{
|
||||
public:
|
||||
IteratorFromArrayPortal()
|
||||
: Portal(), Index(0) { }
|
||||
|
||||
explicit IteratorFromArrayPortal(const ArrayPortalType &portal,
|
||||
vtkm::Id index = 0)
|
||||
: Portal(portal), Index(index) { }
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
detail::IteratorFromArrayPortalValue<ArrayPortalType>
|
||||
operator[](int idx) const
|
||||
{
|
||||
return detail::IteratorFromArrayPortalValue<ArrayPortalType>(this->Portal,
|
||||
idx);
|
||||
}
|
||||
|
||||
private:
|
||||
ArrayPortalType Portal;
|
||||
vtkm::Id Index;
|
||||
|
||||
// Implementation for boost iterator_facade
|
||||
friend class boost::iterator_core_access;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
detail::IteratorFromArrayPortalValue<ArrayPortalType> dereference() const {
|
||||
return detail::IteratorFromArrayPortalValue<ArrayPortalType>(this->Portal,
|
||||
this->Index);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
bool equal(const IteratorFromArrayPortal<ArrayPortalType> &other) const {
|
||||
// Technically, we should probably check that the portals are the same,
|
||||
// but the portal interface does not specify an equal operator. It is
|
||||
// by its nature undefined what happens when comparing iterators from
|
||||
// different portals anyway.
|
||||
return (this->Index == other.Index);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void increment() {
|
||||
this->Index++;
|
||||
VTKM_ASSERT_CONT(this->Index >= 0);
|
||||
VTKM_ASSERT_CONT(this->Index <= this->Portal.GetNumberOfValues());
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void decrement() {
|
||||
this->Index--;
|
||||
VTKM_ASSERT_CONT(this->Index >= 0);
|
||||
VTKM_ASSERT_CONT(this->Index <= this->Portal.GetNumberOfValues());
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void advance(vtkm::Id delta) {
|
||||
this->Index += delta;
|
||||
VTKM_ASSERT_CONT(this->Index >= 0);
|
||||
VTKM_ASSERT_CONT(this->Index <= this->Portal.GetNumberOfValues());
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
vtkm::Id
|
||||
distance_to(const IteratorFromArrayPortal<ArrayPortalType> &other) const {
|
||||
// Technically, we should probably check that the portals are the same,
|
||||
// but the portal interface does not specify an equal operator. It is
|
||||
// by its nature undefined what happens when comparing iterators from
|
||||
// different portals anyway.
|
||||
return other.Index - this->Index;
|
||||
}
|
||||
};
|
||||
|
||||
template<class ArrayPortalType>
|
||||
IteratorFromArrayPortal<ArrayPortalType> make_IteratorBegin(
|
||||
const ArrayPortalType &portal)
|
||||
{
|
||||
return IteratorFromArrayPortal<ArrayPortalType>(portal, 0);
|
||||
}
|
||||
|
||||
template<class ArrayPortalType>
|
||||
IteratorFromArrayPortal<ArrayPortalType> make_IteratorEnd(
|
||||
const ArrayPortalType &portal)
|
||||
{
|
||||
return IteratorFromArrayPortal<ArrayPortalType>(portal,
|
||||
portal.GetNumberOfValues());
|
||||
}
|
||||
|
||||
|
||||
//implementat a custom swap function, since the std::swap won't work
|
||||
//since we return RValues instead of Lvalues
|
||||
template<typename T>
|
||||
void swap( vtkm::cont::internal::detail::IteratorFromArrayPortalValue<T> a,
|
||||
vtkm::cont::internal::detail::IteratorFromArrayPortalValue<T> b)
|
||||
{
|
||||
a.Swap(b);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::internal
|
||||
|
||||
#endif //vtkm_cont_internal_IteratorFromArrayPortal_h
|
27
vtkm/cont/internal/testing/CMakeLists.txt
Normal file
27
vtkm/cont/internal/testing/CMakeLists.txt
Normal file
@ -0,0 +1,27 @@
|
||||
##============================================================================
|
||||
## 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.
|
||||
##============================================================================
|
||||
|
||||
|
||||
set(unit_tests
|
||||
UnitTestArrayManagerExecutionShareWithControl.cxx
|
||||
UnitTestArrayPortalFromIterators.cxx
|
||||
# UnitTestIteratorFromArrayPortal.cxx
|
||||
)
|
||||
vtkm_unit_tests(SOURCES ${unit_tests})
|
@ -0,0 +1,177 @@
|
||||
//============================================================================
|
||||
// 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/cont/internal/ArrayManagerExecutionShareWithControl.h>
|
||||
|
||||
#include <vtkm/cont/ArrayContainerControlBasic.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
const vtkm::Id ARRAY_SIZE = 10;
|
||||
|
||||
template <typename T>
|
||||
struct TemplatedTests
|
||||
{
|
||||
typedef vtkm::cont::internal::ArrayManagerExecutionShareWithControl
|
||||
<T, vtkm::cont::ArrayContainerControlTagBasic>
|
||||
ArrayManagerType;
|
||||
typedef typename ArrayManagerType::ValueType ValueType;
|
||||
typedef vtkm::cont::internal::ArrayContainerControl<
|
||||
T, vtkm::cont::ArrayContainerControlTagBasic> ArrayContainerType;
|
||||
|
||||
void SetContainer(ArrayContainerType &array, ValueType value)
|
||||
{
|
||||
std::fill(array.GetPortal().GetIteratorBegin(),
|
||||
array.GetPortal().GetIteratorEnd(),
|
||||
value);
|
||||
}
|
||||
|
||||
template <class IteratorType>
|
||||
bool CheckArray(IteratorType begin, IteratorType end, ValueType value)
|
||||
{
|
||||
for (IteratorType iter = begin; iter != end; iter++)
|
||||
{
|
||||
if (!test_equal(*iter, value)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CheckContainer(ArrayContainerType &array, ValueType value)
|
||||
{
|
||||
return CheckArray(array.GetPortalConst().GetIteratorBegin(),
|
||||
array.GetPortalConst().GetIteratorEnd(),
|
||||
value);
|
||||
}
|
||||
|
||||
void InputData()
|
||||
{
|
||||
const ValueType INPUT_VALUE(4145);
|
||||
|
||||
ArrayContainerType controlArray;
|
||||
controlArray.Allocate(ARRAY_SIZE);
|
||||
SetContainer(controlArray, INPUT_VALUE);
|
||||
|
||||
ArrayManagerType executionArray;
|
||||
executionArray.LoadDataForInput(controlArray.GetPortalConst());
|
||||
|
||||
// Although the ArrayManagerExecutionShareWithControl class wraps the
|
||||
// control array portal in a different array portal, it should still
|
||||
// give the same iterator (to avoid any unnecessary indirection).
|
||||
VTKM_TEST_ASSERT(
|
||||
controlArray.GetPortalConst().GetIteratorBegin() ==
|
||||
executionArray.GetPortalConst().GetIteratorBegin(),
|
||||
"Execution array manager not holding control array iterators.");
|
||||
|
||||
std::vector<ValueType> copyBack(ARRAY_SIZE);
|
||||
executionArray.CopyInto(copyBack.begin());
|
||||
|
||||
VTKM_TEST_ASSERT(CheckArray(copyBack.begin(), copyBack.end(), INPUT_VALUE),
|
||||
"Did not get correct array back.");
|
||||
}
|
||||
|
||||
void InPlaceData()
|
||||
{
|
||||
const ValueType INPUT_VALUE(2350);
|
||||
|
||||
ArrayContainerType controlArray;
|
||||
controlArray.Allocate(ARRAY_SIZE);
|
||||
SetContainer(controlArray, INPUT_VALUE);
|
||||
|
||||
ArrayManagerType executionArray;
|
||||
executionArray.LoadDataForInPlace(controlArray.GetPortal());
|
||||
|
||||
// Although the ArrayManagerExecutionShareWithControl class wraps the
|
||||
// control array portal in a different array portal, it should still
|
||||
// give the same iterator (to avoid any unnecessary indirection).
|
||||
VTKM_TEST_ASSERT(
|
||||
controlArray.GetPortal().GetIteratorBegin() ==
|
||||
executionArray.GetPortal().GetIteratorBegin(),
|
||||
"Execution array manager not holding control array iterators.");
|
||||
VTKM_TEST_ASSERT(
|
||||
controlArray.GetPortalConst().GetIteratorBegin() ==
|
||||
executionArray.GetPortalConst().GetIteratorBegin(),
|
||||
"Execution array manager not holding control array iterators.");
|
||||
|
||||
std::vector<ValueType> copyBack(ARRAY_SIZE);
|
||||
executionArray.CopyInto(copyBack.begin());
|
||||
|
||||
VTKM_TEST_ASSERT(CheckArray(copyBack.begin(), copyBack.end(), INPUT_VALUE),
|
||||
"Did not get correct array back.");
|
||||
}
|
||||
|
||||
void OutputData()
|
||||
{
|
||||
const ValueType OUTPUT_VALUE(6712);
|
||||
|
||||
ArrayContainerType controlArray;
|
||||
|
||||
ArrayManagerType executionArray;
|
||||
executionArray.AllocateArrayForOutput(controlArray, ARRAY_SIZE);
|
||||
|
||||
std::fill(executionArray.GetPortal().GetIteratorBegin(),
|
||||
executionArray.GetPortal().GetIteratorEnd(),
|
||||
OUTPUT_VALUE);
|
||||
|
||||
std::vector<ValueType> copyBack(ARRAY_SIZE);
|
||||
executionArray.CopyInto(copyBack.begin());
|
||||
|
||||
VTKM_TEST_ASSERT(CheckArray(copyBack.begin(), copyBack.end(), OUTPUT_VALUE),
|
||||
"Did not get correct array back.");
|
||||
|
||||
executionArray.RetrieveOutputData(controlArray);
|
||||
|
||||
VTKM_TEST_ASSERT(CheckContainer(controlArray, OUTPUT_VALUE),
|
||||
"Did not get the right value in the control container.");
|
||||
}
|
||||
|
||||
void operator()() {
|
||||
|
||||
InputData();
|
||||
InPlaceData();
|
||||
OutputData();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
struct TestFunctor
|
||||
{
|
||||
template <typename T>
|
||||
void operator()(T)
|
||||
{
|
||||
TemplatedTests<T> tests;
|
||||
tests();
|
||||
}
|
||||
};
|
||||
|
||||
void TestArrayManagerShare()
|
||||
{
|
||||
vtkm::testing::Testing::TryAllTypes(TestFunctor());
|
||||
}
|
||||
|
||||
} // Anonymous namespace
|
||||
|
||||
int UnitTestArrayManagerExecutionShareWithControl(int, char *[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestArrayManagerShare);
|
||||
}
|
135
vtkm/cont/internal/testing/UnitTestArrayPortalFromIterators.cxx
Normal file
135
vtkm/cont/internal/testing/UnitTestArrayPortalFromIterators.cxx
Normal file
@ -0,0 +1,135 @@
|
||||
//============================================================================
|
||||
// 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/cont/internal/ArrayPortalFromIterators.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/VectorTraits.h>
|
||||
|
||||
namespace {
|
||||
|
||||
template<typename T>
|
||||
struct TemplatedTests
|
||||
{
|
||||
static const vtkm::Id ARRAY_SIZE = 10;
|
||||
|
||||
typedef T ValueType;
|
||||
typedef typename vtkm::VectorTraits<ValueType>::ComponentType ComponentType;
|
||||
|
||||
ValueType ExpectedValue(vtkm::Id index, ComponentType value) {
|
||||
return ValueType(index + value);
|
||||
}
|
||||
|
||||
template<class IteratorType>
|
||||
void FillIterator(IteratorType begin, IteratorType end, ComponentType value) {
|
||||
vtkm::Id index = 0;
|
||||
for (IteratorType iter = begin; iter != end; iter++)
|
||||
{
|
||||
*iter = ExpectedValue(index, value);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
template<class IteratorType>
|
||||
bool CheckIterator(IteratorType begin,
|
||||
IteratorType end,
|
||||
ComponentType value) {
|
||||
vtkm::Id index = 0;
|
||||
for (IteratorType iter = begin; iter != end; iter++)
|
||||
{
|
||||
if (*iter != ExpectedValue(index, value)) return false;
|
||||
index++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
ValueType array[ARRAY_SIZE];
|
||||
|
||||
static const ComponentType ORIGINAL_VALUE = 239;
|
||||
FillIterator(array, array+ARRAY_SIZE, ORIGINAL_VALUE);
|
||||
|
||||
::vtkm::cont::internal::ArrayPortalFromIterators<ValueType *>
|
||||
portal(array, array+ARRAY_SIZE);
|
||||
::vtkm::cont::internal::ArrayPortalFromIterators<const ValueType *>
|
||||
const_portal(array, array+ARRAY_SIZE);
|
||||
|
||||
VTKM_TEST_ASSERT(portal.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"Portal array size wrong.");
|
||||
VTKM_TEST_ASSERT(const_portal.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"Const portal array size wrong.");
|
||||
|
||||
std::cout << " Check inital value." << std::endl;
|
||||
VTKM_TEST_ASSERT(CheckIterator(portal.GetIteratorBegin(),
|
||||
portal.GetIteratorEnd(),
|
||||
ORIGINAL_VALUE),
|
||||
"Portal iterator has bad value.");
|
||||
VTKM_TEST_ASSERT(CheckIterator(const_portal.GetIteratorBegin(),
|
||||
const_portal.GetIteratorEnd(),
|
||||
ORIGINAL_VALUE),
|
||||
"Const portal iterator has bad value.");
|
||||
|
||||
static const ComponentType SET_VALUE = 562;
|
||||
|
||||
std::cout << " Check get/set methods." << std::endl;
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
||||
{
|
||||
VTKM_TEST_ASSERT(portal.Get(index)
|
||||
== ExpectedValue(index, ORIGINAL_VALUE),
|
||||
"Bad portal value.");
|
||||
VTKM_TEST_ASSERT(const_portal.Get(index)
|
||||
== ExpectedValue(index, ORIGINAL_VALUE),
|
||||
"Bad const portal value.");
|
||||
|
||||
portal.Set(index, ExpectedValue(index, SET_VALUE));
|
||||
}
|
||||
|
||||
std::cout << " Make sure set has correct value." << std::endl;
|
||||
VTKM_TEST_ASSERT(CheckIterator(portal.GetIteratorBegin(),
|
||||
portal.GetIteratorEnd(),
|
||||
SET_VALUE),
|
||||
"Portal iterator has bad value.");
|
||||
VTKM_TEST_ASSERT(CheckIterator(array, array+ARRAY_SIZE, SET_VALUE),
|
||||
"Array has bad value.");
|
||||
}
|
||||
};
|
||||
|
||||
struct TestFunctor
|
||||
{
|
||||
template<typename T>
|
||||
void operator()(T)
|
||||
{
|
||||
TemplatedTests<T> tests;
|
||||
tests();
|
||||
}
|
||||
};
|
||||
|
||||
void TestArrayPortalFromIterators()
|
||||
{
|
||||
vtkm::testing::Testing::TryAllTypes(TestFunctor());
|
||||
}
|
||||
|
||||
} // Anonymous namespace
|
||||
|
||||
int UnitTestArrayPortalFromIterators(int, char *[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestArrayPortalFromIterators);
|
||||
}
|
162
vtkm/cont/internal/testing/UnitTestIteratorFromArrayPortal.cxx
Normal file
162
vtkm/cont/internal/testing/UnitTestIteratorFromArrayPortal.cxx
Normal file
@ -0,0 +1,162 @@
|
||||
//============================================================================
|
||||
// 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/cont/internal/IteratorFromArrayPortal.h>
|
||||
|
||||
#include <vtkm/VectorTraits.h>
|
||||
#include <vtkm/cont/internal/ArrayPortalFromIterators.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
namespace {
|
||||
|
||||
template<typename T>
|
||||
struct TemplatedTests
|
||||
{
|
||||
static const vtkm::Id ARRAY_SIZE = 10;
|
||||
|
||||
typedef T ValueType;
|
||||
typedef typename vtkm::VectorTraits<ValueType>::ComponentType ComponentType;
|
||||
|
||||
ValueType ExpectedValue(vtkm::Id index, ComponentType value) {
|
||||
return ValueType(index + value);
|
||||
}
|
||||
|
||||
template<class IteratorType>
|
||||
void FillIterator(IteratorType begin, IteratorType end, ComponentType value) {
|
||||
vtkm::Id index = 0;
|
||||
for (IteratorType iter = begin; iter != end; iter++)
|
||||
{
|
||||
*iter = ExpectedValue(index, value);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
template<class IteratorType>
|
||||
bool CheckIterator(IteratorType begin,
|
||||
IteratorType end,
|
||||
ComponentType value) {
|
||||
vtkm::Id index = 0;
|
||||
for (IteratorType iter = begin; iter != end; iter++)
|
||||
{
|
||||
if (ValueType(*iter) != ExpectedValue(index, value)) return false;
|
||||
index++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ComponentType ORIGINAL_VALUE() { return 239; }
|
||||
|
||||
template<class ArrayPortalType>
|
||||
void TestIteratorRead(ArrayPortalType portal)
|
||||
{
|
||||
typedef vtkm::cont::internal::IteratorFromArrayPortal<ArrayPortalType> IteratorType;
|
||||
|
||||
IteratorType begin = vtkm::cont::internal::make_IteratorBegin(portal);
|
||||
IteratorType end = vtkm::cont::internal::make_IteratorEnd(portal);
|
||||
VTKM_TEST_ASSERT(std::distance(begin, end) == ARRAY_SIZE,
|
||||
"Distance between begin and end incorrect.");
|
||||
|
||||
std::cout << " Check forward iteration." << std::endl;
|
||||
VTKM_TEST_ASSERT(CheckIterator(begin, end, ORIGINAL_VALUE()),
|
||||
"Forward iteration wrong");
|
||||
|
||||
std::cout << " Check backward iteration." << std::endl;
|
||||
IteratorType middle = end;
|
||||
for (vtkm::Id index = portal.GetNumberOfValues()-1; index >= 0; index--)
|
||||
{
|
||||
middle--;
|
||||
ValueType value = *middle;
|
||||
VTKM_TEST_ASSERT(value == ExpectedValue(index, ORIGINAL_VALUE()),
|
||||
"Backward iteration wrong");
|
||||
}
|
||||
|
||||
std::cout << " Check advance" << std::endl;
|
||||
middle = begin + ARRAY_SIZE/2;
|
||||
VTKM_TEST_ASSERT(std::distance(begin, middle) == ARRAY_SIZE/2,
|
||||
"Bad distance to middle.");
|
||||
VTKM_TEST_ASSERT(
|
||||
ValueType(*middle) == ExpectedValue(ARRAY_SIZE/2, ORIGINAL_VALUE()),
|
||||
"Bad value at middle.");
|
||||
}
|
||||
|
||||
template<class ArrayPortalType>
|
||||
void TestIteratorWrite(ArrayPortalType portal)
|
||||
{
|
||||
typedef vtkm::cont::internal::IteratorFromArrayPortal<ArrayPortalType> IteratorType;
|
||||
|
||||
IteratorType begin = vtkm::cont::internal::make_IteratorBegin(portal);
|
||||
IteratorType end = vtkm::cont::internal::make_IteratorEnd(portal);
|
||||
|
||||
static const ComponentType WRITE_VALUE = 873;
|
||||
|
||||
std::cout << " Write values to iterator." << std::endl;
|
||||
FillIterator(begin, end, WRITE_VALUE);
|
||||
|
||||
std::cout << " Check values in portal." << std::endl;
|
||||
VTKM_TEST_ASSERT(CheckIterator(portal.GetIteratorBegin(),
|
||||
portal.GetIteratorEnd(),
|
||||
WRITE_VALUE),
|
||||
"Did not get correct values when writing to iterator.");
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
ValueType array[ARRAY_SIZE];
|
||||
|
||||
FillIterator(array, array+ARRAY_SIZE, ORIGINAL_VALUE());
|
||||
|
||||
::vtkm::cont::internal::ArrayPortalFromIterators<ValueType *>
|
||||
portal(array, array+ARRAY_SIZE);
|
||||
::vtkm::cont::internal::ArrayPortalFromIterators<const ValueType *>
|
||||
const_portal(array, array+ARRAY_SIZE);
|
||||
|
||||
std::cout << " Test read from iterator." << std::endl;
|
||||
TestIteratorRead(portal);
|
||||
|
||||
std::cout << " Test read from const iterator." << std::endl;
|
||||
TestIteratorRead(const_portal);
|
||||
|
||||
std::cout << " Test write to iterator." << std::endl;
|
||||
TestIteratorWrite(portal);
|
||||
}
|
||||
};
|
||||
|
||||
struct TestFunctor
|
||||
{
|
||||
template<typename T>
|
||||
void operator()(T)
|
||||
{
|
||||
TemplatedTests<T> tests;
|
||||
tests();
|
||||
}
|
||||
};
|
||||
|
||||
void TestArrayIteratorFromArrayPortal()
|
||||
{
|
||||
vtkm::testing::Testing::TryAllTypes(TestFunctor());
|
||||
}
|
||||
|
||||
} // Anonymous namespace
|
||||
|
||||
int UnitTestIteratorFromArrayPortal(int, char *[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestArrayIteratorFromArrayPortal);
|
||||
}
|
35
vtkm/cont/testing/CMakeLists.txt
Normal file
35
vtkm/cont/testing/CMakeLists.txt
Normal file
@ -0,0 +1,35 @@
|
||||
##============================================================================
|
||||
## 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.
|
||||
##============================================================================
|
||||
|
||||
set(headers
|
||||
Testing.h
|
||||
)
|
||||
|
||||
vtkm_declare_headers(${headers})
|
||||
|
||||
set(unit_tests
|
||||
UnitTestArrayContainerControlBasic.cxx
|
||||
UnitTestArrayContainerControlImplicit.cxx
|
||||
UnitTestArrayHandle.cxx
|
||||
UnitTestContTesting.cxx
|
||||
)
|
||||
|
||||
vtkm_unit_tests(SOURCES ${unit_tests})
|
||||
|
67
vtkm/cont/testing/Testing.h
Normal file
67
vtkm/cont/testing/Testing.h
Normal file
@ -0,0 +1,67 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_cont_testing_Testing_h
|
||||
#define vtkm_cont_testing_Testing_h
|
||||
|
||||
#include <vtkm/cont/Error.h>
|
||||
|
||||
#include <vtkm/testing/Testing.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
namespace testing {
|
||||
|
||||
struct Testing
|
||||
{
|
||||
public:
|
||||
template<class Func>
|
||||
static VTKM_CONT_EXPORT int Run(Func function)
|
||||
{
|
||||
try
|
||||
{
|
||||
function();
|
||||
}
|
||||
catch (vtkm::testing::Testing::TestFailure error)
|
||||
{
|
||||
std::cout << "***** Test failed @ "
|
||||
<< error.GetFile() << ":" << error.GetLine() << std::endl
|
||||
<< error.GetMessage() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
catch (vtkm::cont::Error error)
|
||||
{
|
||||
std::cout << "***** Uncaught VTKm exception thrown." << std::endl
|
||||
<< error.GetMessage() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << "***** Unidentified exception thrown." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::testing
|
||||
|
||||
#endif //vtkm_cont_internal_Testing_h
|
168
vtkm/cont/testing/UnitTestArrayContainerControlBasic.cxx
Normal file
168
vtkm/cont/testing/UnitTestArrayContainerControlBasic.cxx
Normal file
@ -0,0 +1,168 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
#define VTKM_ARRAY_CONTAINER_CONTROL VTKM_ARRAY_CONTAINER_CONTROL_ERROR
|
||||
|
||||
#include <vtkm/cont/ArrayContainerControlBasic.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/VectorTraits.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
const vtkm::Id ARRAY_SIZE = 10;
|
||||
|
||||
template <typename T>
|
||||
struct TemplatedTests
|
||||
{
|
||||
typedef vtkm::cont::internal::ArrayContainerControl<
|
||||
T, vtkm::cont::ArrayContainerControlTagBasic> ArrayContainerType;
|
||||
typedef typename ArrayContainerType::ValueType ValueType;
|
||||
typedef typename ArrayContainerType::PortalType PortalType;
|
||||
typedef typename PortalType::IteratorType IteratorType;
|
||||
|
||||
void SetContainer(ArrayContainerType &array, ValueType value)
|
||||
{
|
||||
for (IteratorType iter = array.GetPortal().GetIteratorBegin();
|
||||
iter != array.GetPortal().GetIteratorEnd();
|
||||
iter ++)
|
||||
{
|
||||
*iter = value;
|
||||
}
|
||||
}
|
||||
|
||||
bool CheckContainer(ArrayContainerType &array, ValueType value)
|
||||
{
|
||||
for (IteratorType iter = array.GetPortal().GetIteratorBegin();
|
||||
iter != array.GetPortal().GetIteratorEnd();
|
||||
iter ++)
|
||||
{
|
||||
if (!test_equal(*iter, value)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
typename vtkm::VectorTraits<ValueType>::ComponentType STOLEN_ARRAY_VALUE() {
|
||||
return 4529;
|
||||
}
|
||||
|
||||
/// Returned value should later be passed to StealArray2. It is best to
|
||||
/// put as much between the two test parts to maximize the chance of a
|
||||
/// deallocated array being overridden (and thus detected).
|
||||
ValueType *StealArray1()
|
||||
{
|
||||
ValueType *stolenArray;
|
||||
|
||||
ValueType stolenArrayValue = ValueType(STOLEN_ARRAY_VALUE());
|
||||
|
||||
ArrayContainerType stealMyArray;
|
||||
stealMyArray.Allocate(ARRAY_SIZE);
|
||||
SetContainer(stealMyArray, stolenArrayValue);
|
||||
|
||||
VTKM_TEST_ASSERT(stealMyArray.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"Array not properly allocated.");
|
||||
// This call steals the array and prevents deallocation.
|
||||
stolenArray = stealMyArray.StealArray();
|
||||
VTKM_TEST_ASSERT(stealMyArray.GetNumberOfValues() == 0,
|
||||
"StealArray did not let go of array.");
|
||||
|
||||
return stolenArray;
|
||||
}
|
||||
void StealArray2(ValueType *stolenArray)
|
||||
{
|
||||
ValueType stolenArrayValue = ValueType(STOLEN_ARRAY_VALUE());
|
||||
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
||||
{
|
||||
VTKM_TEST_ASSERT(test_equal(stolenArray[index], stolenArrayValue),
|
||||
"Stolen array did not retain values.");
|
||||
}
|
||||
delete[] stolenArray;
|
||||
}
|
||||
|
||||
void BasicAllocation()
|
||||
{
|
||||
ArrayContainerType arrayContainer;
|
||||
VTKM_TEST_ASSERT(arrayContainer.GetNumberOfValues() == 0,
|
||||
"New array container not zero sized.");
|
||||
|
||||
arrayContainer.Allocate(ARRAY_SIZE);
|
||||
VTKM_TEST_ASSERT(arrayContainer.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"Array not properly allocated.");
|
||||
|
||||
const ValueType BASIC_ALLOC_VALUE = ValueType(548);
|
||||
SetContainer(arrayContainer, BASIC_ALLOC_VALUE);
|
||||
VTKM_TEST_ASSERT(CheckContainer(arrayContainer, BASIC_ALLOC_VALUE),
|
||||
"Array not holding value.");
|
||||
|
||||
arrayContainer.Allocate(ARRAY_SIZE * 2);
|
||||
VTKM_TEST_ASSERT(arrayContainer.GetNumberOfValues() == ARRAY_SIZE * 2,
|
||||
"Array not reallocated correctly.");
|
||||
|
||||
arrayContainer.Shrink(ARRAY_SIZE);
|
||||
VTKM_TEST_ASSERT(arrayContainer.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"Array Shrnk failed to resize.");
|
||||
|
||||
arrayContainer.ReleaseResources();
|
||||
VTKM_TEST_ASSERT(arrayContainer.GetNumberOfValues() == 0,
|
||||
"Array not released correctly.");
|
||||
|
||||
try
|
||||
{
|
||||
arrayContainer.Shrink(ARRAY_SIZE);
|
||||
VTKM_TEST_ASSERT(true==false,
|
||||
"Array shrink do a larger size was possible. This can't be allowed.");
|
||||
}
|
||||
catch(vtkm::cont::ErrorControlBadValue){}
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
ValueType *stolenArray = StealArray1();
|
||||
|
||||
BasicAllocation();
|
||||
|
||||
StealArray2(stolenArray);
|
||||
}
|
||||
};
|
||||
|
||||
struct TestFunctor
|
||||
{
|
||||
template <typename T>
|
||||
void operator()(T)
|
||||
{
|
||||
TemplatedTests<T> tests;
|
||||
tests();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
void TestArrayContainerControlBasic()
|
||||
{
|
||||
vtkm::testing::Testing::TryAllTypes(TestFunctor());
|
||||
}
|
||||
|
||||
} // Anonymous namespace
|
||||
|
||||
int UnitTestArrayContainerControlBasic(int, char *[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestArrayContainerControlBasic);
|
||||
}
|
157
vtkm/cont/testing/UnitTestArrayContainerControlImplicit.cxx
Normal file
157
vtkm/cont/testing/UnitTestArrayContainerControlImplicit.cxx
Normal file
@ -0,0 +1,157 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
#define VTKM_ARRAY_CONTAINER_CONTROL VTKM_ARRAY_CONTAINER_CONTROL_ERROR
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/cont/ArrayContainerControlImplicit.h>
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/internal/IteratorFromArrayPortal.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <vtkm/VectorTraits.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
struct TestImplicitContainer
|
||||
{
|
||||
typedef T ValueType;
|
||||
ValueType Temp;
|
||||
typedef vtkm::cont::internal::IteratorFromArrayPortal<
|
||||
TestImplicitContainer<T> > IteratorType;
|
||||
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
TestImplicitContainer(): Temp(1) { }
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Id GetNumberOfValues() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
ValueType Get(vtkm::Id vtkmNotUsed(index)) const
|
||||
{
|
||||
return Temp;
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorBegin() const {
|
||||
return IteratorType(*this);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorEnd() const {
|
||||
return IteratorType(*this, this->GetNumberOfValues());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const vtkm::Id ARRAY_SIZE = 1;
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct TemplatedTests
|
||||
{
|
||||
typedef vtkm::cont::ArrayContainerControlTagImplicit<
|
||||
TestImplicitContainer<T> > ContainerTagType;
|
||||
typedef vtkm::cont::internal::ArrayContainerControl<
|
||||
T, ContainerTagType > ArrayContainerType;
|
||||
|
||||
typedef typename ArrayContainerType::ValueType ValueType;
|
||||
typedef typename ArrayContainerType::PortalType PortalType;
|
||||
typedef typename PortalType::IteratorType IteratorType;
|
||||
|
||||
void BasicAllocation()
|
||||
{
|
||||
ArrayContainerType arrayContainer;
|
||||
|
||||
try{ arrayContainer.GetNumberOfValues();
|
||||
VTKM_TEST_ASSERT(false == true,
|
||||
"Implicit Container GetNumberOfValues method didn't throw error.");
|
||||
}
|
||||
catch(vtkm::cont::ErrorControlBadValue e){}
|
||||
|
||||
try{ arrayContainer.Allocate(ARRAY_SIZE);
|
||||
VTKM_TEST_ASSERT(false == true,
|
||||
"Implicit Container Allocate method didn't throw error.");
|
||||
}
|
||||
catch(vtkm::cont::ErrorControlBadValue e){}
|
||||
|
||||
try
|
||||
{
|
||||
arrayContainer.Shrink(ARRAY_SIZE);
|
||||
VTKM_TEST_ASSERT(true==false,
|
||||
"Array shrink do a larger size was possible. This can't be allowed.");
|
||||
}
|
||||
catch(vtkm::cont::ErrorControlBadValue){}
|
||||
|
||||
try
|
||||
{
|
||||
arrayContainer.ReleaseResources();
|
||||
VTKM_TEST_ASSERT(true==false,
|
||||
"Can't Release an implicit array");
|
||||
}
|
||||
catch(vtkm::cont::ErrorControlBadValue){}
|
||||
}
|
||||
|
||||
void BasicAccess()
|
||||
{
|
||||
TestImplicitContainer<T> portal;
|
||||
vtkm::cont::ArrayHandle<T,ContainerTagType> implictHandle(portal);
|
||||
VTKM_TEST_ASSERT(implictHandle.GetNumberOfValues() == 1,
|
||||
"handle should have size 1");
|
||||
VTKM_TEST_ASSERT(implictHandle.GetPortalConstControl().Get(0) == T(1),
|
||||
"portals first values should be 1");
|
||||
;
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
BasicAllocation();
|
||||
BasicAccess();
|
||||
}
|
||||
};
|
||||
|
||||
struct TestFunctor
|
||||
{
|
||||
template <typename T>
|
||||
void operator()(T)
|
||||
{
|
||||
TemplatedTests<T> tests;
|
||||
tests();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
void TestArrayContainerControlBasic()
|
||||
{
|
||||
vtkm::testing::Testing::TryAllTypes(TestFunctor());
|
||||
}
|
||||
|
||||
} // Anonymous namespace
|
||||
|
||||
int UnitTestArrayContainerControlImplicit(int, char *[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestArrayContainerControlBasic);
|
||||
}
|
164
vtkm/cont/testing/UnitTestArrayHandle.cxx
Normal file
164
vtkm/cont/testing/UnitTestArrayHandle.cxx
Normal file
@ -0,0 +1,164 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
//This sets up the ArrayHandle semantics to allocate pointers and share memory
|
||||
//between control and execution.
|
||||
#define VTKM_ARRAY_CONTAINER_CONTROL VTKM_ARRAY_CONTAINER_CONTROL_BASIC
|
||||
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_SERIAL
|
||||
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace
|
||||
{
|
||||
const vtkm::Id ARRAY_SIZE = 10;
|
||||
|
||||
vtkm::Scalar TestValue(vtkm::Id index)
|
||||
{
|
||||
return static_cast<vtkm::Scalar>(10.0*index + 0.01*(index+1));
|
||||
}
|
||||
|
||||
template<class IteratorType>
|
||||
bool CheckValues(IteratorType begin, IteratorType end)
|
||||
{
|
||||
vtkm::Id index = 0;
|
||||
for (IteratorType iter = begin; iter != end; iter++)
|
||||
{
|
||||
if (!test_equal(*iter, TestValue(index))) return false;
|
||||
index++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool CheckValues(const vtkm::cont::ArrayHandle<T> &handle)
|
||||
{
|
||||
return CheckValues(handle.GetPortalConstControl().GetIteratorBegin(),
|
||||
handle.GetPortalConstControl().GetIteratorEnd());
|
||||
}
|
||||
|
||||
void TestArrayHandle()
|
||||
{
|
||||
std::cout << "Create array handle." << std::endl;
|
||||
vtkm::Scalar array[ARRAY_SIZE];
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
||||
{
|
||||
array[index] = TestValue(index);
|
||||
}
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Scalar>::PortalControl arrayPortal(
|
||||
&array[0], &array[ARRAY_SIZE]);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Scalar>
|
||||
arrayHandle(arrayPortal);
|
||||
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"ArrayHandle has wrong number of entries.");
|
||||
|
||||
std::cout << "Check basic array." << std::endl;
|
||||
VTKM_TEST_ASSERT(CheckValues(arrayHandle),
|
||||
"Array values not set correctly.");
|
||||
|
||||
std::cout << "Check out execution array behavior." << std::endl;
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Scalar>::
|
||||
ExecutionTypes<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>::PortalConst
|
||||
executionPortal;
|
||||
executionPortal =
|
||||
arrayHandle.PrepareForInput(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
VTKM_TEST_ASSERT(CheckValues(executionPortal.GetIteratorBegin(),
|
||||
executionPortal.GetIteratorEnd()),
|
||||
"Array not copied to execution correctly.");
|
||||
}
|
||||
|
||||
{
|
||||
bool gotException = false;
|
||||
try
|
||||
{
|
||||
arrayHandle.PrepareForInPlace(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
}
|
||||
catch (vtkm::cont::Error &error)
|
||||
{
|
||||
std::cout << "Got expected error: " << error.GetMessage() << std::endl;
|
||||
gotException = true;
|
||||
}
|
||||
VTKM_TEST_ASSERT(gotException,
|
||||
"PrepareForInPlace did not fail for const array.");
|
||||
}
|
||||
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Scalar>::
|
||||
ExecutionTypes<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>::Portal executionPortal;
|
||||
executionPortal =
|
||||
arrayHandle.PrepareForOutput(ARRAY_SIZE*2,
|
||||
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
vtkm::Id index = 0;
|
||||
for (vtkm::Scalar *iter = executionPortal.GetIteratorBegin();
|
||||
iter != executionPortal.GetIteratorEnd();
|
||||
iter++)
|
||||
{
|
||||
*iter = TestValue(index);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE*2,
|
||||
"Array not allocated correctly.");
|
||||
VTKM_TEST_ASSERT(CheckValues(arrayHandle),
|
||||
"Array values not retrieved from execution.");
|
||||
|
||||
std::cout << "Try shrinking the array." << std::endl;
|
||||
arrayHandle.Shrink(ARRAY_SIZE);
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"Array size did not shrink correctly.");
|
||||
VTKM_TEST_ASSERT(CheckValues(arrayHandle),
|
||||
"Array values not retrieved from execution.");
|
||||
|
||||
std::cout << "Try in place operation." << std::endl;
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Scalar>::
|
||||
ExecutionTypes<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>::Portal executionPortal;
|
||||
executionPortal =
|
||||
arrayHandle.PrepareForInPlace(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
for (vtkm::Scalar *iter = executionPortal.GetIteratorBegin();
|
||||
iter != executionPortal.GetIteratorEnd();
|
||||
iter++)
|
||||
{
|
||||
*iter += 1;
|
||||
}
|
||||
}
|
||||
vtkm::cont::ArrayHandle<vtkm::Scalar>::PortalConstControl controlPortal =
|
||||
arrayHandle.GetPortalConstControl();
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
||||
{
|
||||
VTKM_TEST_ASSERT(test_equal(controlPortal.Get(index), TestValue(index) + 1),
|
||||
"Did not get result from in place operation.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int UnitTestArrayHandle(int, char *[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestArrayHandle);
|
||||
}
|
85
vtkm/cont/testing/UnitTestContTesting.cxx
Normal file
85
vtkm/cont/testing/UnitTestContTesting.cxx
Normal file
@ -0,0 +1,85 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
// This meta-test makes sure that the testing environment is properly reporting
|
||||
// errors.
|
||||
|
||||
#include <vtkm/cont/Assert.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
namespace {
|
||||
|
||||
void TestFail()
|
||||
{
|
||||
VTKM_TEST_FAIL("I expect this error.");
|
||||
}
|
||||
|
||||
void BadTestAssert()
|
||||
{
|
||||
VTKM_TEST_ASSERT(0 == 1, "I expect this error.");
|
||||
}
|
||||
|
||||
void BadAssert()
|
||||
{
|
||||
VTKM_ASSERT_CONT(0 == 1);
|
||||
}
|
||||
|
||||
void GoodAssert()
|
||||
{
|
||||
VTKM_TEST_ASSERT(1 == 1, "Always true.");
|
||||
VTKM_ASSERT_CONT(1 == 1);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestContTesting(int, char *[])
|
||||
{
|
||||
std::cout << "-------\nThis call should fail." << std::endl;
|
||||
if (vtkm::cont::testing::Testing::Run(TestFail) == 0)
|
||||
{
|
||||
std::cout << "Did not get expected fail!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout << "-------\nThis call should fail." << std::endl;
|
||||
if (vtkm::cont::testing::Testing::Run(BadTestAssert) == 0)
|
||||
{
|
||||
std::cout << "Did not get expected fail!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//VTKM_ASSERT_CONT only is a valid call when you are building with debug
|
||||
#ifndef NDEBUG
|
||||
int expectedResult=0;
|
||||
#else
|
||||
int expectedResult=1;
|
||||
#endif
|
||||
|
||||
std::cout << "-------\nThis call should fail on debug builds." << std::endl;
|
||||
if (vtkm::cont::testing::Testing::Run(BadAssert) == expectedResult)
|
||||
{
|
||||
std::cout << "Did not get expected fail!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "-------\nThis call should pass." << std::endl;
|
||||
// This is what your main function typically looks like.
|
||||
return vtkm::cont::testing::Testing::Run(GoodAssert);
|
||||
}
|
30
vtkm/internal/CMakeLists.txt
Normal file
30
vtkm/internal/CMakeLists.txt
Normal file
@ -0,0 +1,30 @@
|
||||
##============================================================================
|
||||
## 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.
|
||||
##============================================================================
|
||||
|
||||
set(headers
|
||||
ConfigureFor32.h
|
||||
ConfigureFor64.h
|
||||
ExportMacros.h
|
||||
)
|
||||
|
||||
vtkm_declare_headers(${headers})
|
||||
|
||||
add_subdirectory(testing)
|
||||
|
94
vtkm/internal/Configure.h.in
Normal file
94
vtkm/internal/Configure.h.in
Normal file
@ -0,0 +1,94 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_internal_Configure_h
|
||||
#define vtkm_internal_Configure_h
|
||||
|
||||
|
||||
#if !defined(VTKM_USE_DOUBLE_PRECISION) && !defined(VTKM_NO_DOUBLE_PRECISION)
|
||||
#cmakedefine VTKM_USE_DOUBLE_PRECISION
|
||||
#endif
|
||||
|
||||
#if defined(VTKM_USE_DOUBLE_PRECISION) && defined(VTKM_NO_DOUBLE_PRECISION)
|
||||
# error Both VTKM_USE_DOUBLE_PRECISION and VTKM_NO_DOUBLE_PRECISION defined. Do not know what to do.
|
||||
#endif
|
||||
|
||||
#if !defined(VTKM_USE_64BIT_IDS) && !defined(VTKM_NO_64BIT_IDS)
|
||||
#cmakedefine VTKM_USE_64BIT_IDS
|
||||
#endif
|
||||
|
||||
#if defined(VTKM_USE_64BIT_IDS) && defined(VTKM_NO_64BIT_IDS)
|
||||
# error Both VTKM_USE_64BIT_IDS and VTKM_NO_64BIT_IDS defined. Do not know what to do.
|
||||
#endif
|
||||
|
||||
#define VTKM_SIZE_FLOAT @VTKm_SIZE_FLOAT@
|
||||
#define VTKM_SIZE_DOUBLE @VTKm_SIZE_DOUBLE@
|
||||
#define VTKM_SIZE_INT @VTKm_SIZE_INT@
|
||||
#define VTKM_SIZE_LONG @VTKm_SIZE_LONG@
|
||||
#define VTKM_SIZE_LONG_LONG @VTKm_SIZE_LONG_LONG@
|
||||
|
||||
#ifdef VTKM_USE_DOUBLE_PRECISION
|
||||
# ifndef VTKM_SIZE_SCALAR
|
||||
# define VTKM_SIZE_SCALAR VTKM_SIZE_DOUBLE
|
||||
# endif
|
||||
# ifndef VTKM_ALIGNMENT_TWO_SCALAR
|
||||
# define VTKM_ALIGNMENT_TWO_SCALAR 16
|
||||
# endif
|
||||
# ifndef VTKM_ALIGNMENT_FOUR_SCALAR
|
||||
# define VTKM_ALIGNMENT_FOUR_SCALAR 8
|
||||
# endif
|
||||
#else
|
||||
# ifndef VTKM_SIZE_SCALAR
|
||||
# define VTKM_SIZE_SCALAR VTKM_SIZE_FLOAT
|
||||
# define VTKM_ALIGNMENT_SCALAR VTKM_SIZE_SCALAR
|
||||
# endif
|
||||
# ifndef VTKM_ALIGNMENT_TWO_SCALAR
|
||||
# define VTKM_ALIGNMENT_TWO_SCALAR 8
|
||||
# endif
|
||||
# ifndef VTKM_ALIGNMENT_FOUR_SCALAR
|
||||
# define VTKM_ALIGNMENT_FOUR_SCALAR 16
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef VTKM_USE_64BIT_IDS
|
||||
# ifndef VTKM_SIZE_ID
|
||||
# define VTKM_SIZE_ID 8
|
||||
# endif
|
||||
#else
|
||||
# ifndef VTKM_SIZE_ID
|
||||
# define VTKM_SIZE_ID 4
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Determine whether we will use variadic templates (a new feature in C++11).
|
||||
// Currently have VARIADIC_TEMPLATE support off.
|
||||
#cmakedefine VTKM_NO_VARIADIC_TEMPLATE
|
||||
#if !defined(VTKM_USE_VARIADIC_TEMPLATE) && !defined(VTKM_NO_VARIADIC_TEMPLATE)
|
||||
// Currently using Boost to determine support.
|
||||
# include <boost/config.hpp>
|
||||
# if defined(BOOST_HAS_VARIADIC_TMPL)
|
||||
# define VTKM_USE_VARIADIC_TEMPLATE 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(VTKM_USE_VARIADIC_TEMPLATE) && defined(VTKM_NO_VARIADIC_TEMPLATE)
|
||||
# error Both VTKM_USE_VARIADIC_TEMPLATE and VTKM_NO_VARIADIC_TEMPLATE defined. Do not know what to do.
|
||||
#endif
|
||||
|
||||
#endif //vtkm_internal_Configure_h
|
37
vtkm/internal/ConfigureFor32.h
Normal file
37
vtkm/internal/ConfigureFor32.h
Normal file
@ -0,0 +1,37 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
//This header can be used by external application that are consuming VTKm
|
||||
//to define if VTKm should be set to use 32bit data types. If you need to
|
||||
//customize more of the vtkm type system, or what Device Adapters
|
||||
//need to be included look at vtkm/internal/Configure.h for all defines that
|
||||
//you can over-ride.
|
||||
#ifdef vtkm_internal_Configure_h
|
||||
# error Incorrect header order. Include this header before any other VTKm headers.
|
||||
#endif
|
||||
|
||||
#ifndef vtkm_internal_Configure32_h
|
||||
#define vtkm_internal_Configure32_h
|
||||
|
||||
#define VTKM_NO_DOUBLE_PRECISION
|
||||
#define VTKM_NO_64BIT_IDS
|
||||
|
||||
#include <vtkm/internal/Configure.h>
|
||||
|
||||
#endif
|
37
vtkm/internal/ConfigureFor64.h
Normal file
37
vtkm/internal/ConfigureFor64.h
Normal file
@ -0,0 +1,37 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
//This header can be used by external application that are consuming VTKm
|
||||
//to define if VTKm should be set to use 64bit data types. If you need to
|
||||
//customize more of the vtkm type system, or what Device Adapters
|
||||
//need to be included look at vtkm/internal/Configure.h for all defines that
|
||||
//you can over-ride.
|
||||
#ifdef vtkm_internal_Configure_h
|
||||
# error Incorrect header order. Include this header before any other VTKm headers.
|
||||
#endif
|
||||
|
||||
#ifndef vtkm_internal_Configure32_h
|
||||
#define vtkm_internal_Configure32_h
|
||||
|
||||
#define VTKM_USE_DOUBLE_PRECISION
|
||||
#define VTKM_USE_64BIT_IDS
|
||||
|
||||
#include <vtkm/internal/Configure.h>
|
||||
|
||||
#endif
|
78
vtkm/internal/ExportMacros.h
Normal file
78
vtkm/internal/ExportMacros.h
Normal file
@ -0,0 +1,78 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_internal__ExportMacros_h
|
||||
#define vtkm_internal__ExportMacros_h
|
||||
|
||||
/*!
|
||||
* Export macros for various parts of the VTKm library.
|
||||
*/
|
||||
|
||||
#ifdef __CUDACC__
|
||||
#define VTKM_CUDA
|
||||
#endif
|
||||
|
||||
#ifdef _OPENMP
|
||||
#define VTKM_OPENMP
|
||||
#endif
|
||||
|
||||
#ifdef VTKM_CUDA
|
||||
#define VTKM_EXEC_EXPORT inline __device__
|
||||
#define VTKM_EXEC_CONT_EXPORT inline __device__ __host__
|
||||
#define VTKM_EXEC_CONSTANT_EXPORT __device__ __constant__
|
||||
#else
|
||||
#define VTKM_EXEC_EXPORT inline
|
||||
#define VTKM_EXEC_CONT_EXPORT inline
|
||||
#define VTKM_EXEC_CONSTANT_EXPORT
|
||||
#endif
|
||||
|
||||
#define VTKM_CONT_EXPORT inline
|
||||
|
||||
/// Simple macro to identify a parameter as unused. This allows you to name a
|
||||
/// parameter that is not used. There are several instances where you might
|
||||
/// want to do this. For example, when using a parameter to overload or
|
||||
/// template a function but do not actually use the parameter. Another example
|
||||
/// is providing a specialization that does not need that parameter.
|
||||
#define vtkmNotUsed(parameter_name)
|
||||
|
||||
|
||||
// Check boost support under CUDA
|
||||
#ifdef VTKM_CUDA
|
||||
#if !defined(BOOST_SP_DISABLE_THREADS) && !defined(BOOST_SP_USE_SPINLOCK) && !defined(BOOST_SP_USE_PTHREADS)
|
||||
#warning -------------------------------------------------------------------
|
||||
#warning The CUDA compiler (nvcc) has trouble with some of the optimizations
|
||||
#warning boost uses for thread saftey. To get around this, please define
|
||||
#warning one of the following macros to specify the thread handling boost
|
||||
#warning should use:
|
||||
#warning
|
||||
#warning BOOST_SP_DISABLE_THREADS
|
||||
#warning BOOST_SP_USE_SPINLOCK
|
||||
#warning BOOST_SP_USE_PTHREADS
|
||||
#warning
|
||||
#warning Failure to define one of these for a CUDA build will probably cause
|
||||
#warning other annoying warnings and might even cause incorrect code. Note
|
||||
#warning that specifying BOOST_SP_DISABLE_THREADS does not preclude using
|
||||
#warning VTKm with a threaded device (like OpenMP). Specifying one of these
|
||||
#warning modes for boost does not effect the scheduling in VTKm.
|
||||
#warning -------------------------------------------------------------------
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif //vtkm_internal__ExportMacros_h
|
25
vtkm/internal/testing/CMakeLists.txt
Normal file
25
vtkm/internal/testing/CMakeLists.txt
Normal file
@ -0,0 +1,25 @@
|
||||
##============================================================================
|
||||
## 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.
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestConfigureFor32.cxx
|
||||
UnitTestConfigureFor64.cxx
|
||||
)
|
||||
vtkm_unit_tests(SOURCES ${unit_tests})
|
57
vtkm/internal/testing/UnitTestConfigureFor32.cxx
Normal file
57
vtkm/internal/testing/UnitTestConfigureFor32.cxx
Normal file
@ -0,0 +1,57 @@
|
||||
//============================================================================
|
||||
// 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/internal/ConfigureFor32.h>
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
#include <vtkm/testing/Testing.h>
|
||||
|
||||
// Size of 32 bits.
|
||||
#define EXPECTED_SIZE 4
|
||||
|
||||
#if VTKM_SIZE_ID != EXPECTED_SIZE
|
||||
#error VTKM_SIZE_ID an unexpected size.
|
||||
#endif
|
||||
|
||||
#if VTKM_SIZE_SCALAR != EXPECTED_SIZE
|
||||
#error VTKM_SIZE_SCALAR an unexpected size.
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
void TestTypeSizes()
|
||||
{
|
||||
VTKM_TEST_ASSERT(VTKM_SIZE_ID == EXPECTED_SIZE,
|
||||
"VTKM_SIZE_ID an unexpected size.");
|
||||
VTKM_TEST_ASSERT(sizeof(vtkm::Id) == EXPECTED_SIZE,
|
||||
"vtkm::Id an unexpected size.");
|
||||
VTKM_TEST_ASSERT(VTKM_SIZE_SCALAR == EXPECTED_SIZE,
|
||||
"VTKM_SIZE_SCALAR an unexpected size.");
|
||||
VTKM_TEST_ASSERT(sizeof(vtkm::Scalar) == EXPECTED_SIZE,
|
||||
"vtkm::Scalar an unexpected size.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int UnitTestConfigureFor32(int, char *[])
|
||||
{
|
||||
return vtkm::testing::Testing::Run(TestTypeSizes);
|
||||
}
|
57
vtkm/internal/testing/UnitTestConfigureFor64.cxx
Normal file
57
vtkm/internal/testing/UnitTestConfigureFor64.cxx
Normal file
@ -0,0 +1,57 @@
|
||||
//============================================================================
|
||||
// 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/internal/ConfigureFor64.h>
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
#include <vtkm/testing/Testing.h>
|
||||
|
||||
// Size of 64 bits.
|
||||
#define EXPECTED_SIZE 8
|
||||
|
||||
#if VTKM_SIZE_ID != EXPECTED_SIZE
|
||||
#error VTKM_SIZE_ID an unexpected size.
|
||||
#endif
|
||||
|
||||
#if VTKM_SIZE_SCALAR != EXPECTED_SIZE
|
||||
#error VTKM_SIZE_SCALAR an unexpected size.
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
void TestTypeSizes()
|
||||
{
|
||||
VTKM_TEST_ASSERT(VTKM_SIZE_ID == EXPECTED_SIZE,
|
||||
"VTKM_SIZE_ID an unexpected size.");
|
||||
VTKM_TEST_ASSERT(sizeof(vtkm::Id) == EXPECTED_SIZE,
|
||||
"vtkm::Id an unexpected size.");
|
||||
VTKM_TEST_ASSERT(VTKM_SIZE_SCALAR == EXPECTED_SIZE,
|
||||
"VTKM_SIZE_SCALAR an unexpected size.");
|
||||
VTKM_TEST_ASSERT(sizeof(vtkm::Scalar) == EXPECTED_SIZE,
|
||||
"vtkm::Scalar an unexpected size.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int UnitTestConfigureFor64(int, char *[])
|
||||
{
|
||||
return vtkm::testing::Testing::Run(TestTypeSizes);
|
||||
}
|
34
vtkm/testing/CMakeLists.txt
Normal file
34
vtkm/testing/CMakeLists.txt
Normal file
@ -0,0 +1,34 @@
|
||||
##============================================================================
|
||||
## 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.
|
||||
##============================================================================
|
||||
|
||||
set(headers
|
||||
Testing.h
|
||||
OptionParser.h
|
||||
)
|
||||
|
||||
VTKM_declare_headers(${headers})
|
||||
|
||||
set(unit_tests
|
||||
UnitTestTesting.cxx
|
||||
UnitTestTypes.cxx
|
||||
UnitTestTypeTraits.cxx
|
||||
)
|
||||
|
||||
VTKM_unit_tests(SOURCES ${unit_tests})
|
2821
vtkm/testing/OptionParser.h
Normal file
2821
vtkm/testing/OptionParser.h
Normal file
File diff suppressed because it is too large
Load Diff
329
vtkm/testing/Testing.h
Normal file
329
vtkm/testing/Testing.h
Normal file
@ -0,0 +1,329 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtkm_testing_Testing_h
|
||||
#define vtkm_testing_Testing_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/TypeTraits.h>
|
||||
#include <vtkm/VectorTraits.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
// Try to enforce using the correct testing version. (Those that include the
|
||||
// control environment have more possible exceptions.) This is not guaranteed
|
||||
// to work. To make it more likely, place the Testing.h include last.
|
||||
#ifdef vtkm_cont_Error_h
|
||||
#ifndef vtkm_cont_testing_Testing_h
|
||||
#error Use vtkm::cont::testing::Testing instead of vtkm::testing::Testing.
|
||||
#else
|
||||
#define VTKM_TESTING_IN_CONT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/// \def VTKM_TEST_ASSERT(condition, message)
|
||||
///
|
||||
/// Asserts a condition for a test to pass. A passing condition is when \a
|
||||
/// condition resolves to true. If \a condition is false, then the test is
|
||||
/// aborted and failure is returned.
|
||||
|
||||
#define VTKM_TEST_ASSERT(condition, message) \
|
||||
::vtkm::testing::Testing::Assert( \
|
||||
condition, __FILE__, __LINE__, message, #condition)
|
||||
|
||||
/// \def VTKM_TEST_FAIL(message)
|
||||
///
|
||||
/// Causes a test to fail with the given \a message.
|
||||
|
||||
#define VTKM_TEST_FAIL(message) \
|
||||
throw ::vtkm::testing::Testing::TestFailure(__FILE__, __LINE__, message)
|
||||
|
||||
namespace vtkm {
|
||||
namespace testing {
|
||||
|
||||
struct Testing
|
||||
{
|
||||
public:
|
||||
class TestFailure
|
||||
{
|
||||
public:
|
||||
VTKM_CONT_EXPORT TestFailure(const std::string &file,
|
||||
vtkm::Id line,
|
||||
const std::string &message)
|
||||
: File(file), Line(line), Message(message) { }
|
||||
|
||||
VTKM_CONT_EXPORT TestFailure(const std::string &file,
|
||||
vtkm::Id line,
|
||||
const std::string &message,
|
||||
const std::string &condition)
|
||||
: File(file), Line(line)
|
||||
{
|
||||
this->Message.append(message);
|
||||
this->Message.append(" (");
|
||||
this->Message.append(condition);
|
||||
this->Message.append(")");
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT const std::string &GetFile() const { return this->File; }
|
||||
VTKM_CONT_EXPORT vtkm::Id GetLine() const { return this->Line; }
|
||||
VTKM_CONT_EXPORT const std::string &GetMessage() const {
|
||||
return this->Message;
|
||||
}
|
||||
private:
|
||||
std::string File;
|
||||
vtkm::Id Line;
|
||||
std::string Message;
|
||||
};
|
||||
|
||||
static VTKM_CONT_EXPORT void Assert(bool condition,
|
||||
const std::string &file,
|
||||
vtkm::Id line,
|
||||
const std::string &message,
|
||||
const std::string &conditionString)
|
||||
{
|
||||
if (condition)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
else
|
||||
{
|
||||
throw TestFailure(file, line, message, conditionString);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef VTKM_TESTING_IN_CONT
|
||||
/// Calls the test function \a function with no arguments. Catches any errors
|
||||
/// generated by VTKM_TEST_ASSERT or VTKM_TEST_FAIL, reports the error, and
|
||||
/// returns "1" (a failure status for a program's main). Returns "0" (a
|
||||
/// success status for a program's main).
|
||||
///
|
||||
/// The intention is to implement a test's main function with this. For
|
||||
/// example, the implementation of UnitTestFoo might look something like
|
||||
/// this.
|
||||
///
|
||||
/// \code
|
||||
/// #include <vtkm/testing/Testing.h>
|
||||
///
|
||||
/// namespace {
|
||||
///
|
||||
/// void TestFoo()
|
||||
/// {
|
||||
/// // Do actual test, which checks in VTKM_TEST_ASSERT or VTKM_TEST_FAIL.
|
||||
/// }
|
||||
///
|
||||
/// } // anonymous namespace
|
||||
///
|
||||
/// int UnitTestFoo(int, char *[])
|
||||
/// {
|
||||
/// return vtkm::testing::Testing::Run(TestFoo);
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
template<class Func>
|
||||
static VTKM_CONT_EXPORT int Run(Func function)
|
||||
{
|
||||
try
|
||||
{
|
||||
function();
|
||||
}
|
||||
catch (TestFailure error)
|
||||
{
|
||||
std::cout << "***** Test failed @ "
|
||||
<< error.GetFile() << ":" << error.GetLine() << std::endl
|
||||
<< error.GetMessage() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << "***** Unidentified exception thrown." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Check functors to be used with the TryAllTypes method.
|
||||
///
|
||||
struct TypeCheckAlwaysTrue {
|
||||
template <typename T, class Functor>
|
||||
void operator()(T t, Functor function) const { function(t); }
|
||||
};
|
||||
struct TypeCheckInteger {
|
||||
template <typename T, class Functor>
|
||||
void operator()(T t, Functor function) const {
|
||||
this->DoInteger(typename vtkm::TypeTraits<T>::NumericTag(), t, function);
|
||||
}
|
||||
private:
|
||||
template <class Tag, typename T, class Functor>
|
||||
void DoInteger(Tag, T, const Functor&) const { }
|
||||
template <typename T, class Functor>
|
||||
void DoInteger(vtkm::TypeTraitsIntegerTag, T t, Functor function) const {
|
||||
function(t);
|
||||
}
|
||||
};
|
||||
struct TypeCheckReal {
|
||||
template <typename T, class Functor>
|
||||
void operator()(T t, Functor function) const {
|
||||
this->DoReal(typename vtkm::TypeTraits<T>::NumericTag(), t, function);
|
||||
}
|
||||
private:
|
||||
template <class Tag, typename T, class Functor>
|
||||
void DoReal(Tag, T, const Functor&) const { }
|
||||
template <typename T, class Functor>
|
||||
void DoReal(vtkm::TypeTraitsRealTag, T t, Functor function) const {
|
||||
function(t);
|
||||
}
|
||||
};
|
||||
struct TypeCheckScalar {
|
||||
template <typename T, class Functor>
|
||||
void operator()(T t, Functor func) const {
|
||||
this->DoScalar(typename vtkm::TypeTraits<T>::DimensionalityTag(), t, func);
|
||||
}
|
||||
private:
|
||||
template <class Tag, typename T, class Functor>
|
||||
void DoScalar(Tag, const T &, const Functor &) const { }
|
||||
template <typename T, class Functor>
|
||||
void DoScalar(vtkm::TypeTraitsScalarTag, T t, Functor function) const {
|
||||
function(t);
|
||||
}
|
||||
};
|
||||
struct TypeCheckVector {
|
||||
template <typename T, class Functor>
|
||||
void operator()(T t, Functor func) const {
|
||||
this->DoVector(typename vtkm::TypeTraits<T>::DimensionalityTag(), t, func);
|
||||
}
|
||||
private:
|
||||
template <class Tag, typename T, class Functor>
|
||||
void DoVector(Tag, const T &, const Functor &) const { }
|
||||
template <typename T, class Functor>
|
||||
void DoVector(vtkm::TypeTraitsVectorTag, T t, Functor function) const {
|
||||
function(t);
|
||||
}
|
||||
};
|
||||
|
||||
template<class FunctionType>
|
||||
struct InternalPrintOnInvoke {
|
||||
InternalPrintOnInvoke(FunctionType function, std::string toprint)
|
||||
: Function(function), ToPrint(toprint) { }
|
||||
template <typename T> void operator()(T t) {
|
||||
std::cout << this->ToPrint << std::endl;
|
||||
this->Function(t);
|
||||
}
|
||||
private:
|
||||
FunctionType Function;
|
||||
std::string ToPrint;
|
||||
};
|
||||
|
||||
/// Runs templated \p function on all the basic types defined in VTKm. This is
|
||||
/// helpful to test templated functions that should work on all types. If the
|
||||
/// function is supposed to work on some subset of types, then \p check can
|
||||
/// be set to restrict the types used. This Testing class contains several
|
||||
/// helpful check functors.
|
||||
///
|
||||
template<class FunctionType, class CheckType>
|
||||
static void TryAllTypes(FunctionType function, CheckType check)
|
||||
{
|
||||
vtkm::Id id = 0;
|
||||
check(id, InternalPrintOnInvoke<FunctionType>(
|
||||
function, "*** vtkm::Id ***************"));
|
||||
|
||||
vtkm::Id3 id3 = vtkm::make_Id3(0, 0, 0);
|
||||
check(id3, InternalPrintOnInvoke<FunctionType>(
|
||||
function, "*** vtkm::Id3 **************"));
|
||||
|
||||
vtkm::Scalar scalar = 0.0;
|
||||
check(scalar, InternalPrintOnInvoke<FunctionType>(
|
||||
function, "*** vtkm::Scalar ***********"));
|
||||
|
||||
vtkm::Vector2 vector2 = vtkm::make_Vector2(0.0, 0.0);
|
||||
check(vector2, InternalPrintOnInvoke<FunctionType>(
|
||||
function, "*** vtkm::Vector2 **********"));
|
||||
|
||||
vtkm::Vector3 vector3 = vtkm::make_Vector3(0.0, 0.0, 0.0);
|
||||
check(vector3, InternalPrintOnInvoke<FunctionType>(
|
||||
function, "*** vtkm::Vector3 **********"));
|
||||
|
||||
vtkm::Vector4 vector4 = vtkm::make_Vector4(0.0, 0.0, 0.0, 0.0);
|
||||
check(vector4, InternalPrintOnInvoke<FunctionType>(
|
||||
function, "*** vtkm::Vector4 **********"));
|
||||
}
|
||||
template<class FunctionType>
|
||||
static void TryAllTypes(FunctionType function)
|
||||
{
|
||||
TryAllTypes(function, TypeCheckAlwaysTrue());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::internal
|
||||
|
||||
/// Helper function to test two quanitites for equality accounting for slight
|
||||
/// variance due to floating point numerical inaccuracies.
|
||||
///
|
||||
template<typename VectorType>
|
||||
VTKM_EXEC_CONT_EXPORT bool test_equal(VectorType vector1,
|
||||
VectorType vector2,
|
||||
vtkm::Scalar tolerance = 0.0001)
|
||||
{
|
||||
typedef typename vtkm::VectorTraits<VectorType> Traits;
|
||||
for (int component = 0; component < Traits::NUM_COMPONENTS; component++)
|
||||
{
|
||||
vtkm::Scalar value1 = Traits::GetComponent(vector1, component);
|
||||
vtkm::Scalar value2 = Traits::GetComponent(vector2, component);
|
||||
if ((fabs(value1) < 2*tolerance) && (fabs(value2) < 2*tolerance))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
vtkm::Scalar ratio = value1/value2;
|
||||
if ((ratio > vtkm::Scalar(1.0) - tolerance)
|
||||
&& (ratio < vtkm::Scalar(1.0) + tolerance))
|
||||
{
|
||||
// This component is OK. The condition is checked in this way to
|
||||
// correctly handle non-finites that fail all comparisons. Thus, if a
|
||||
// non-finite is encountered, this condition will fail and false will be
|
||||
// returned.
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Helper function for printing out vectors during testing.
|
||||
///
|
||||
template<typename T, int Size>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
std::ostream &operator<<(std::ostream &stream, const vtkm::Tuple<T,Size> &tuple)
|
||||
{
|
||||
stream << "[";
|
||||
for (int component = 0; component < Size-1; component++)
|
||||
{
|
||||
stream << tuple[component] << ",";
|
||||
}
|
||||
return stream << tuple[Size-1] << "]";
|
||||
}
|
||||
|
||||
#endif //vtkm_testing_Testing_h
|
78
vtkm/testing/UnitTestTesting.cxx
Normal file
78
vtkm/testing/UnitTestTesting.cxx
Normal file
@ -0,0 +1,78 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
// This meta-test makes sure that the testing environment is properly reporting
|
||||
// errors.
|
||||
|
||||
#include <vtkm/testing/Testing.h>
|
||||
|
||||
namespace {
|
||||
|
||||
void Fail()
|
||||
{
|
||||
VTKM_TEST_FAIL("I expect this error.");
|
||||
}
|
||||
|
||||
void BadAssert()
|
||||
{
|
||||
VTKM_TEST_ASSERT(0 == 1, "I expect this error.");
|
||||
}
|
||||
|
||||
void GoodAssert()
|
||||
{
|
||||
VTKM_TEST_ASSERT(1 == 1, "Always true.");
|
||||
}
|
||||
|
||||
void TestTestEqual()
|
||||
{
|
||||
VTKM_TEST_ASSERT(test_equal(vtkm::Scalar(2.0), vtkm::Scalar(1.9999999)),
|
||||
"These should be close enough.");
|
||||
VTKM_TEST_ASSERT(!test_equal(vtkm::Scalar(2.0), vtkm::Scalar(1.999)),
|
||||
"These should not be close enough.");
|
||||
}
|
||||
|
||||
// All tests that should not raise a failure.
|
||||
void CleanTests()
|
||||
{
|
||||
GoodAssert();
|
||||
TestTestEqual();
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestTesting(int, char *[])
|
||||
{
|
||||
std::cout << "This call should fail." << std::endl;
|
||||
if (vtkm::testing::Testing::Run(Fail) == 0)
|
||||
{
|
||||
std::cout << "Did not get expected fail!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout << "This call should fail." << std::endl;
|
||||
if (vtkm::testing::Testing::Run(BadAssert) == 0)
|
||||
{
|
||||
std::cout << "Did not get expected fail!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "This call should pass." << std::endl;
|
||||
// This is what your main function typically looks like.
|
||||
return vtkm::testing::Testing::Run(CleanTests);
|
||||
}
|
83
vtkm/testing/UnitTestTypeTraits.cxx
Normal file
83
vtkm/testing/UnitTestTypeTraits.cxx
Normal file
@ -0,0 +1,83 @@
|
||||
//============================================================================
|
||||
// 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/TypeTraits.h>
|
||||
|
||||
#include <vtkm/VectorTraits.h>
|
||||
|
||||
#include <vtkm/testing/Testing.h>
|
||||
|
||||
namespace {
|
||||
|
||||
struct TypeTraitTest
|
||||
{
|
||||
template <typename T> void operator()(T t) {
|
||||
// If you get compiler errors here, it could be a TypeTraits instance
|
||||
// has missing or malformed tags.
|
||||
this->TestDimensionality(t, typename vtkm::TypeTraits<T>::DimensionalityTag());
|
||||
this->TestNumeric(t, typename vtkm::TypeTraits<T>::NumericTag());
|
||||
}
|
||||
private:
|
||||
|
||||
template <typename T>
|
||||
void TestDimensionality(T, vtkm::TypeTraitsScalarTag) {
|
||||
std::cout << " scalar" << std::endl;
|
||||
VTKM_TEST_ASSERT(vtkm::VectorTraits<T>::NUM_COMPONENTS == 1,
|
||||
"Scalar type does not have one component.");
|
||||
}
|
||||
template <typename T>
|
||||
void TestDimensionality(T, vtkm::TypeTraitsVectorTag) {
|
||||
std::cout << " vector" << std::endl;
|
||||
VTKM_TEST_ASSERT(vtkm::VectorTraits<T>::NUM_COMPONENTS > 1,
|
||||
"Vector type does not have multiple components.");
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void TestNumeric(T, vtkm::TypeTraitsIntegerTag) {
|
||||
std::cout << " integer" << std::endl;
|
||||
typedef typename vtkm::VectorTraits<T>::ComponentType VT;
|
||||
VT value = VT(2.001);
|
||||
VTKM_TEST_ASSERT(value == 2, "Integer does not round to integer.");
|
||||
}
|
||||
template <typename T>
|
||||
void TestNumeric(T, vtkm::TypeTraitsRealTag) {
|
||||
std::cout << " real" << std::endl;
|
||||
typedef typename vtkm::VectorTraits<T>::ComponentType VT;
|
||||
VT value = VT(2.001);
|
||||
VTKM_TEST_ASSERT(test_equal(float(value), float(2.001)),
|
||||
"Real does not hold floaing point number.");
|
||||
}
|
||||
};
|
||||
|
||||
static void TestTypeTraits()
|
||||
{
|
||||
TypeTraitTest test;
|
||||
vtkm::testing::Testing::TryAllTypes(test);
|
||||
std::cout << "vtkm::Tuple<vtkm::Scalar, 5>" << std::endl;
|
||||
test(vtkm::Tuple<vtkm::Scalar, 5>());
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int UnitTestTypeTraits(int, char *[])
|
||||
{
|
||||
return vtkm::testing::Testing::Run(TestTypeTraits);
|
||||
}
|
495
vtkm/testing/UnitTestTypes.cxx
Normal file
495
vtkm/testing/UnitTestTypes.cxx
Normal file
@ -0,0 +1,495 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
//============================================================================
|
||||
// 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/Types.h>
|
||||
|
||||
#include <vtkm/testing/Testing.h>
|
||||
|
||||
namespace {
|
||||
|
||||
//general type test
|
||||
template <typename T> void TypeTest()
|
||||
{
|
||||
//grab the number of elements of T
|
||||
T a, b, c;
|
||||
typename T::ComponentType s(5);
|
||||
|
||||
for(int i=0; i < T::NUM_COMPONENTS; ++i)
|
||||
{
|
||||
a[i]=typename T::ComponentType((i+1)*2);
|
||||
b[i]=typename T::ComponentType(i+1);
|
||||
c[i]=typename T::ComponentType((i+1)*2);
|
||||
}
|
||||
|
||||
//verify prefix and postfix increment and decrement
|
||||
++c[T::NUM_COMPONENTS-1];
|
||||
c[T::NUM_COMPONENTS-1]++;
|
||||
--c[T::NUM_COMPONENTS-1];
|
||||
c[T::NUM_COMPONENTS-1]--;
|
||||
|
||||
//make c nearly like a to verify == and != are correct.
|
||||
c[T::NUM_COMPONENTS-1]=(c[T::NUM_COMPONENTS-1]-1);
|
||||
|
||||
T plus = a + b;
|
||||
T correct_plus;
|
||||
for(int i=0; i < T::NUM_COMPONENTS; ++i)
|
||||
{ correct_plus[i] = a[i] + b[i]; }
|
||||
VTKM_TEST_ASSERT(test_equal(plus, correct_plus),"Tuples not added correctly.");
|
||||
|
||||
T minus = a - b;
|
||||
T correct_minus;
|
||||
for(int i=0; i < T::NUM_COMPONENTS; ++i)
|
||||
{ correct_minus[i] = a[i] - b[i]; }
|
||||
VTKM_TEST_ASSERT(test_equal(minus, correct_minus),"Tuples not subtracted correctly.");
|
||||
|
||||
|
||||
T mult = a * b;
|
||||
T correct_mult;
|
||||
for(int i=0; i < T::NUM_COMPONENTS; ++i)
|
||||
{ correct_mult[i] = a[i] * b[i]; }
|
||||
VTKM_TEST_ASSERT(test_equal(mult, correct_mult),"Tuples not multiplied correctly.");
|
||||
|
||||
T div = a / b;
|
||||
T correct_div;
|
||||
for(int i=0; i < T::NUM_COMPONENTS; ++i)
|
||||
{ correct_div[i] = a[i] / b[i]; }
|
||||
VTKM_TEST_ASSERT(test_equal(div,correct_div),"Tuples not divided correctly.");
|
||||
|
||||
mult = s * a;
|
||||
for(int i=0; i < T::NUM_COMPONENTS; ++i)
|
||||
{ correct_mult[i] = s * a[i]; }
|
||||
VTKM_TEST_ASSERT(test_equal(mult, correct_mult),
|
||||
"Scalar and Tuple did not multiply correctly.");
|
||||
|
||||
mult = a * s;
|
||||
VTKM_TEST_ASSERT(test_equal(mult, correct_mult),
|
||||
"Tuple and Scalar to not multiply correctly.");
|
||||
|
||||
typename T::ComponentType d = vtkm::dot(a, b);
|
||||
typename T::ComponentType correct_d = 0;
|
||||
for(int i=0; i < T::NUM_COMPONENTS; ++i)
|
||||
{correct_d += a[i] * b[i]; }
|
||||
VTKM_TEST_ASSERT(test_equal(d, correct_d), "dot(Tuple) wrong");
|
||||
|
||||
VTKM_TEST_ASSERT(!(a < b), "operator< wrong");
|
||||
VTKM_TEST_ASSERT((b < a), "operator< wrong");
|
||||
VTKM_TEST_ASSERT(!(a < a), "operator< wrong");
|
||||
VTKM_TEST_ASSERT((a < plus), "operator< wrong");
|
||||
VTKM_TEST_ASSERT((minus < plus), "operator< wrong");
|
||||
VTKM_TEST_ASSERT((c < a), "operator< wrong");
|
||||
|
||||
VTKM_TEST_ASSERT(!(a == b), "operator== wrong");
|
||||
VTKM_TEST_ASSERT((a == a), "operator== wrong");
|
||||
|
||||
VTKM_TEST_ASSERT((a != b), "operator!= wrong");
|
||||
VTKM_TEST_ASSERT(!(a != a), "operator!= wrong");
|
||||
|
||||
//test against a tuple that shares some values
|
||||
VTKM_TEST_ASSERT( !(c == a), "operator == wrong");
|
||||
VTKM_TEST_ASSERT( !(a == c), "operator == wrong");
|
||||
|
||||
VTKM_TEST_ASSERT( (c != a), "operator != wrong");
|
||||
VTKM_TEST_ASSERT( (a != c), "operator != wrong");
|
||||
}
|
||||
|
||||
template<> void TypeTest<vtkm::Vector2>()
|
||||
{
|
||||
vtkm::Vector2 a = vtkm::make_Vector2(2, 4);
|
||||
vtkm::Vector2 b = vtkm::make_Vector2(1, 2);
|
||||
vtkm::Scalar s = 5;
|
||||
|
||||
vtkm::Vector2 plus = a + b;
|
||||
VTKM_TEST_ASSERT(test_equal(plus, vtkm::make_Vector2(3, 6)),
|
||||
"Vectors do not add correctly.");
|
||||
|
||||
vtkm::Vector2 minus = a - b;
|
||||
VTKM_TEST_ASSERT(test_equal(minus, vtkm::make_Vector2(1, 2)),
|
||||
"Vectors to not subtract correctly.");
|
||||
|
||||
vtkm::Vector2 mult = a * b;
|
||||
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector2(2, 8)),
|
||||
"Vectors to not multiply correctly.");
|
||||
|
||||
vtkm::Vector2 div = a / b;
|
||||
VTKM_TEST_ASSERT(test_equal(div, vtkm::make_Vector2(2, 2)),
|
||||
"Vectors to not divide correctly.");
|
||||
|
||||
mult = s * a;
|
||||
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector2(10, 20)),
|
||||
"Vector and scalar to not multiply correctly.");
|
||||
|
||||
mult = a * s;
|
||||
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector2(10, 20)),
|
||||
"Vector and scalar to not multiply correctly.");
|
||||
|
||||
vtkm::Scalar d = vtkm::dot(a, b);
|
||||
VTKM_TEST_ASSERT(test_equal(d, vtkm::Scalar(10)), "dot(Vector2) wrong");
|
||||
|
||||
VTKM_TEST_ASSERT(!(a < b), "operator< wrong");
|
||||
VTKM_TEST_ASSERT((b < a), "operator< wrong");
|
||||
VTKM_TEST_ASSERT(!(a < a), "operator< wrong");
|
||||
VTKM_TEST_ASSERT((a < plus), "operator< wrong");
|
||||
VTKM_TEST_ASSERT((minus < plus), "operator< wrong");
|
||||
|
||||
VTKM_TEST_ASSERT(!(a == b), "operator== wrong");
|
||||
VTKM_TEST_ASSERT((a == a), "operator== wrong");
|
||||
|
||||
VTKM_TEST_ASSERT((a != b), "operator!= wrong");
|
||||
VTKM_TEST_ASSERT(!(a != a), "operator!= wrong");
|
||||
|
||||
//test against a tuple that shares some values
|
||||
const vtkm::Vector2 c = vtkm::make_Vector2(2,3);
|
||||
VTKM_TEST_ASSERT((c < a), "operator< wrong");
|
||||
|
||||
VTKM_TEST_ASSERT( !(c == a), "operator == wrong");
|
||||
VTKM_TEST_ASSERT( !(a == c), "operator == wrong");
|
||||
|
||||
VTKM_TEST_ASSERT( (c != a), "operator != wrong");
|
||||
VTKM_TEST_ASSERT( (a != c), "operator != wrong");
|
||||
}
|
||||
|
||||
template<> void TypeTest<vtkm::Vector3>()
|
||||
{
|
||||
vtkm::Vector3 a = vtkm::make_Vector3(2, 4, 6);
|
||||
vtkm::Vector3 b = vtkm::make_Vector3(1, 2, 3);
|
||||
vtkm::Scalar s = 5;
|
||||
|
||||
vtkm::Vector3 plus = a + b;
|
||||
VTKM_TEST_ASSERT(test_equal(plus, vtkm::make_Vector3(3, 6, 9)),
|
||||
"Vectors do not add correctly.");
|
||||
|
||||
vtkm::Vector3 minus = a - b;
|
||||
VTKM_TEST_ASSERT(test_equal(minus, vtkm::make_Vector3(1, 2, 3)),
|
||||
"Vectors to not subtract correctly.");
|
||||
|
||||
vtkm::Vector3 mult = a * b;
|
||||
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector3(2, 8, 18)),
|
||||
"Vectors to not multiply correctly.");
|
||||
|
||||
vtkm::Vector3 div = a / b;
|
||||
VTKM_TEST_ASSERT(test_equal(div, vtkm::make_Vector3(2, 2, 2)),
|
||||
"Vectors to not divide correctly.");
|
||||
|
||||
mult = s * a;
|
||||
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector3(10, 20, 30)),
|
||||
"Vector and scalar to not multiply correctly.");
|
||||
|
||||
mult = a * s;
|
||||
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector3(10, 20, 30)),
|
||||
"Vector and scalar to not multiply correctly.");
|
||||
|
||||
vtkm::Scalar d = vtkm::dot(a, b);
|
||||
VTKM_TEST_ASSERT(test_equal(d, vtkm::Scalar(28)), "dot(Vector3) wrong");
|
||||
|
||||
VTKM_TEST_ASSERT(!(a < b), "operator< wrong");
|
||||
VTKM_TEST_ASSERT((b < a), "operator< wrong");
|
||||
VTKM_TEST_ASSERT(!(a < a), "operator< wrong");
|
||||
VTKM_TEST_ASSERT((a < plus), "operator< wrong");
|
||||
VTKM_TEST_ASSERT((minus < plus), "operator< wrong");
|
||||
|
||||
VTKM_TEST_ASSERT(!(a == b), "operator== wrong");
|
||||
VTKM_TEST_ASSERT((a == a), "operator== wrong");
|
||||
|
||||
VTKM_TEST_ASSERT((a != b), "operator!= wrong");
|
||||
VTKM_TEST_ASSERT(!(a != a), "operator!= wrong");
|
||||
|
||||
//test against a tuple that shares some values
|
||||
const vtkm::Vector3 c = vtkm::make_Vector3(2,4,5);
|
||||
VTKM_TEST_ASSERT((c < a), "operator< wrong");
|
||||
|
||||
VTKM_TEST_ASSERT( !(c == a), "operator == wrong");
|
||||
VTKM_TEST_ASSERT( !(a == c), "operator == wrong");
|
||||
|
||||
VTKM_TEST_ASSERT( (c != a), "operator != wrong");
|
||||
VTKM_TEST_ASSERT( (a != c), "operator != wrong");
|
||||
}
|
||||
|
||||
template<> void TypeTest<vtkm::Vector4>()
|
||||
{
|
||||
vtkm::Vector4 a = vtkm::make_Vector4(2, 4, 6, 8);
|
||||
vtkm::Vector4 b = vtkm::make_Vector4(1, 2, 3, 4);
|
||||
vtkm::Scalar s = 5;
|
||||
|
||||
vtkm::Vector4 plus = a + b;
|
||||
VTKM_TEST_ASSERT(test_equal(plus, vtkm::make_Vector4(3, 6, 9, 12)),
|
||||
"Vectors do not add correctly.");
|
||||
|
||||
vtkm::Vector4 minus = a - b;
|
||||
VTKM_TEST_ASSERT(test_equal(minus, vtkm::make_Vector4(1, 2, 3, 4)),
|
||||
"Vectors to not subtract correctly.");
|
||||
|
||||
vtkm::Vector4 mult = a * b;
|
||||
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector4(2, 8, 18, 32)),
|
||||
"Vectors to not multiply correctly.");
|
||||
|
||||
vtkm::Vector4 div = a / b;
|
||||
VTKM_TEST_ASSERT(test_equal(div, vtkm::make_Vector4(2, 2, 2, 2)),
|
||||
"Vectors to not divide correctly.");
|
||||
|
||||
mult = s * a;
|
||||
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector4(10, 20, 30, 40)),
|
||||
"Vector and scalar to not multiply correctly.");
|
||||
|
||||
mult = a * s;
|
||||
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector4(10, 20, 30, 40)),
|
||||
"Vector and scalar to not multiply correctly.");
|
||||
|
||||
vtkm::Scalar d = vtkm::dot(a, b);
|
||||
VTKM_TEST_ASSERT(test_equal(d, vtkm::Scalar(60)), "dot(Vector4) wrong");
|
||||
|
||||
|
||||
VTKM_TEST_ASSERT(!(a < b), "operator< wrong");
|
||||
VTKM_TEST_ASSERT((b < a), "operator< wrong");
|
||||
VTKM_TEST_ASSERT(!(a < a), "operator< wrong");
|
||||
VTKM_TEST_ASSERT((a < plus), "operator< wrong");
|
||||
VTKM_TEST_ASSERT((minus < plus), "operator< wrong");
|
||||
|
||||
VTKM_TEST_ASSERT(!(a == b), "operator== wrong");
|
||||
VTKM_TEST_ASSERT((a == a), "operator== wrong");
|
||||
|
||||
VTKM_TEST_ASSERT((a != b), "operator!= wrong");
|
||||
VTKM_TEST_ASSERT(!(a != a), "operator!= wrong");
|
||||
|
||||
//test against a tuple that shares some values
|
||||
const vtkm::Vector4 c = vtkm::make_Vector4(2,4,6,7);
|
||||
VTKM_TEST_ASSERT((c < a), "operator< wrong");
|
||||
|
||||
VTKM_TEST_ASSERT( !(c == a), "operator == wrong");
|
||||
VTKM_TEST_ASSERT( !(a == c), "operator == wrong");
|
||||
|
||||
VTKM_TEST_ASSERT( (c != a), "operator != wrong");
|
||||
VTKM_TEST_ASSERT( (a != c), "operator != wrong");
|
||||
}
|
||||
|
||||
template<> void TypeTest<vtkm::Id3>()
|
||||
{
|
||||
vtkm::Id3 a = vtkm::make_Id3(2, 4, 6);
|
||||
vtkm::Id3 b = vtkm::make_Id3(1, 2, 3);
|
||||
vtkm::Id s = 5;
|
||||
|
||||
vtkm::Id3 plus = a + b;
|
||||
if ((plus[0] != 3) || (plus[1] != 6) || (plus[2] != 9))
|
||||
{
|
||||
VTKM_TEST_FAIL("Vectors do not add correctly.");
|
||||
}
|
||||
|
||||
vtkm::Id3 minus = a - b;
|
||||
if ((minus[0] != 1) || (minus[1] != 2) || (minus[2] != 3))
|
||||
{
|
||||
VTKM_TEST_FAIL("Vectors to not subtract correctly.");
|
||||
}
|
||||
|
||||
vtkm::Id3 mult = a * b;
|
||||
if ((mult[0] != 2) || (mult[1] != 8) || (mult[2] != 18))
|
||||
{
|
||||
VTKM_TEST_FAIL("Vectors to not multiply correctly.");
|
||||
}
|
||||
|
||||
vtkm::Id3 div = a / b;
|
||||
if ((div[0] != 2) || (div[1] != 2) || (div[2] != 2))
|
||||
{
|
||||
VTKM_TEST_FAIL("Vectors to not divide correctly.");
|
||||
}
|
||||
|
||||
mult = s * a;
|
||||
if ((mult[0] != 10) || (mult[1] != 20) || (mult[2] != 30))
|
||||
{
|
||||
VTKM_TEST_FAIL("Vector and scalar to not multiply correctly.");
|
||||
}
|
||||
|
||||
mult = a * s;
|
||||
if ((mult[0] != 10) || (mult[1] != 20) || (mult[2] != 30))
|
||||
{
|
||||
VTKM_TEST_FAIL("Vector and scalar to not multiply correctly.");
|
||||
}
|
||||
|
||||
if (vtkm::dot(a, b) != 28)
|
||||
{
|
||||
VTKM_TEST_FAIL("dot(Id3) wrong");
|
||||
}
|
||||
|
||||
VTKM_TEST_ASSERT(!(a < b), "operator< wrong");
|
||||
VTKM_TEST_ASSERT((b < a), "operator< wrong");
|
||||
VTKM_TEST_ASSERT(!(a < a), "operator< wrong");
|
||||
VTKM_TEST_ASSERT((a < plus), "operator< wrong");
|
||||
VTKM_TEST_ASSERT((minus < plus), "operator< wrong");
|
||||
|
||||
if (a == b)
|
||||
{
|
||||
VTKM_TEST_FAIL("operator== wrong");
|
||||
}
|
||||
if (!(a == a))
|
||||
{
|
||||
VTKM_TEST_FAIL("operator== wrong");
|
||||
}
|
||||
|
||||
if (!(a != b))
|
||||
{
|
||||
VTKM_TEST_FAIL("operator!= wrong");
|
||||
}
|
||||
if (a != a)
|
||||
{
|
||||
VTKM_TEST_FAIL("operator!= wrong");
|
||||
}
|
||||
|
||||
//test against a tuple that shares some values
|
||||
const vtkm::Id3 c = vtkm::make_Id3(2,4,5);
|
||||
VTKM_TEST_ASSERT((c < a), "operator< wrong");
|
||||
|
||||
if (c == a) { VTKM_TEST_FAIL("operator== wrong"); }
|
||||
if (a == c) { VTKM_TEST_FAIL("operator== wrong"); }
|
||||
|
||||
if (!(c != a)) { VTKM_TEST_FAIL("operator!= wrong"); }
|
||||
if (!(a != c)) { VTKM_TEST_FAIL("operator!= wrong"); }
|
||||
}
|
||||
|
||||
template<> void TypeTest<vtkm::Scalar>()
|
||||
{
|
||||
vtkm::Scalar a = 4;
|
||||
vtkm::Scalar b = 2;
|
||||
|
||||
vtkm::Scalar plus = a + b;
|
||||
if (plus != 6)
|
||||
{
|
||||
VTKM_TEST_FAIL("Scalars do not add correctly.");
|
||||
}
|
||||
|
||||
vtkm::Scalar minus = a - b;
|
||||
if (minus != 2)
|
||||
{
|
||||
VTKM_TEST_FAIL("Scalars to not subtract correctly.");
|
||||
}
|
||||
|
||||
vtkm::Scalar mult = a * b;
|
||||
if (mult != 8)
|
||||
{
|
||||
VTKM_TEST_FAIL("Scalars to not multiply correctly.");
|
||||
}
|
||||
|
||||
vtkm::Scalar div = a / b;
|
||||
if (div != 2)
|
||||
{
|
||||
VTKM_TEST_FAIL("Scalars to not divide correctly.");
|
||||
}
|
||||
|
||||
if (a == b)
|
||||
{
|
||||
VTKM_TEST_FAIL("operator== wrong");
|
||||
}
|
||||
if (!(a != b))
|
||||
{
|
||||
VTKM_TEST_FAIL("operator!= wrong");
|
||||
}
|
||||
|
||||
if (vtkm::dot(a, b) != 8)
|
||||
{
|
||||
VTKM_TEST_FAIL("dot(Scalar) wrong");
|
||||
}
|
||||
}
|
||||
|
||||
template<> void TypeTest<vtkm::Id>()
|
||||
{
|
||||
vtkm::Id a = 4;
|
||||
vtkm::Id b = 2;
|
||||
|
||||
vtkm::Id plus = a + b;
|
||||
if (plus != 6)
|
||||
{
|
||||
VTKM_TEST_FAIL("Scalars do not add correctly.");
|
||||
}
|
||||
|
||||
vtkm::Id minus = a - b;
|
||||
if (minus != 2)
|
||||
{
|
||||
VTKM_TEST_FAIL("Scalars to not subtract correctly.");
|
||||
}
|
||||
|
||||
vtkm::Id mult = a * b;
|
||||
if (mult != 8)
|
||||
{
|
||||
VTKM_TEST_FAIL("Scalars to not multiply correctly.");
|
||||
}
|
||||
|
||||
vtkm::Id div = a / b;
|
||||
if (div != 2)
|
||||
{
|
||||
VTKM_TEST_FAIL("Scalars to not divide correctly.");
|
||||
}
|
||||
|
||||
if (a == b)
|
||||
{
|
||||
VTKM_TEST_FAIL("operator== wrong");
|
||||
}
|
||||
if (!(a != b))
|
||||
{
|
||||
VTKM_TEST_FAIL("operator!= wrong");
|
||||
}
|
||||
|
||||
if (vtkm::dot(a, b) != 8)
|
||||
{
|
||||
VTKM_TEST_FAIL("dot(Id) wrong");
|
||||
}
|
||||
}
|
||||
|
||||
struct TypeTestFunctor
|
||||
{
|
||||
template <typename T> void operator()(const T&) const {
|
||||
TypeTest<T>();
|
||||
}
|
||||
};
|
||||
|
||||
void TestTypes()
|
||||
{
|
||||
vtkm::testing::Testing::TryAllTypes(TypeTestFunctor());
|
||||
|
||||
//try with some custom tuple types
|
||||
TypeTestFunctor()( vtkm::Tuple<vtkm::Scalar,6>() );
|
||||
TypeTestFunctor()( vtkm::Tuple<vtkm::Id,4>() );
|
||||
TypeTestFunctor()( vtkm::Tuple<unsigned char,4>() );
|
||||
TypeTestFunctor()( vtkm::Tuple<vtkm::Id,1>() );
|
||||
TypeTestFunctor()( vtkm::Tuple<vtkm::Scalar,1>() );
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int UnitTestTypes(int, char *[])
|
||||
{
|
||||
return vtkm::testing::Testing::Run(TestTypes);
|
||||
}
|
Loading…
Reference in New Issue
Block a user