Commit ecd6e368 authored by Robert Maynard's avatar Robert Maynard Committed by Kitware Robot

Merge topic 'correct_issues_found_in_examples'

6e22bb5d Cosmotools exmaples builds again with the change of vtkm::cont::Initialize
ab3d89d4 Simplify the example/demo CMakeLists.txt
028e954b Game Of Life example now supports -d/--device command line argument
e2c61e01 Update the HelloWorld example to use VTK-m runtime device adapter logic
34165c8e Correct crashes in the GameOfLife example
cdbee58c Remove the dynamic_dispatcher example as is a compiler benchmark
7c2c1d5f Interop now works when device adapter isn't known.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !1491
parents d49f1e8b 6e22bb5d
......@@ -28,7 +28,6 @@ add_subdirectory(contour_tree)
add_subdirectory(contour_tree_augmented)
add_subdirectory(cosmotools)
add_subdirectory(demo)
add_subdirectory(dynamic_dispatcher)
add_subdirectory(game_of_life)
add_subdirectory(hello_world)
add_subdirectory(histogram)
......
......@@ -19,7 +19,8 @@
//============================================================================
#include <vtkm/cont/ArrayHandleCast.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/Logging.h>
#include <vtkm/cont/Initialize.h>
#include <vtkm/io/reader/VTKDataSetReader.h>
#include <vtkm/io/writer/VTKDataSetWriter.h>
......
......@@ -19,7 +19,8 @@
//============================================================================
#include <vtkm/cont/ArrayHandleCast.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/Logging.h>
#include <vtkm/cont/Initialize.h>
#include <vtkm/io/reader/VTKDataSetReader.h>
#include <vtkm/io/writer/VTKDataSetWriter.h>
......
......@@ -28,16 +28,12 @@ find_package(VTKm REQUIRED QUIET)
set(srcs Demo.cxx)
if(TARGET vtkm_rendering)
set(backend "VTKM_DEVICE_ADAPTER_SERIAL")
if(TARGET vtkm::cuda)
vtkm_compile_as_cuda(cuda_srcs ${srcs})
set(srcs ${cuda_srcs})
set(backend "VTKM_DEVICE_ADAPTER_CUDA")
elseif(TARGET vtkm::tbb)
set(backend "VTKM_DEVICE_ADAPTER_TBB")
endif()
add_executable(Demo ${srcs})
target_link_libraries(Demo PRIVATE vtkm_rendering)
target_compile_definitions(Demo PRIVATE "VTKM_DEVICE_ADAPTER=${backend}")
endif()
##=============================================================================
##
## Copyright (c) Kitware, Inc.
## All rights reserved.
## See LICENSE.txt for details.
##
## This software is distributed WITHOUT ANY WARRANTY; without even
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
## PURPOSE. See the above copyright notice for more information.
##
## Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
## Copyright 2015 UT-Battelle, LLC.
## Copyright 2015 Los Alamos National Security.
##
## Under the terms of Contract DE-NA0003525 with NTESS,
## 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.
##
##=============================================================================
add_executable(DynamicDispatcherExample main.cxx)
target_link_libraries(DynamicDispatcherExample PRIVATE vtkm_cont)
//============================================================================
// 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 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// 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_DEVICE_ADAPTER
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_SERIAL
#endif
#include <iostream>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/DynamicArrayHandle.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WorkletMapField.h>
struct ExampleFieldWorklet : public vtkm::worklet::WorkletMapField
{
using ControlSignature =
void(FieldIn<>, FieldIn<>, FieldIn<>, FieldOut<>, FieldOut<>, FieldOut<>);
using ExecutionSignature = void(_1, _2, _3, _4, _5, _6);
template <typename T, typename U, typename V>
VTKM_EXEC void operator()(const vtkm::Vec<T, 3>& vec,
const U& scalar1,
const V& scalar2,
vtkm::Vec<T, 3>& out_vec,
U& out_scalar1,
V& out_scalar2) const
{
out_vec = vec * scalar1;
out_scalar1 = static_cast<U>(scalar1 + scalar2);
out_scalar2 = scalar2;
std::cout << "hello world" << std::endl;
}
template <typename T, typename U, typename V, typename W, typename X, typename Y>
VTKM_EXEC void operator()(const T&, const U&, const V&, W&, X&, Y&) const
{
//no-op
}
};
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
std::vector<vtkm::Vec<vtkm::Float32, 3>> inputVec(10);
std::vector<vtkm::Int32> inputScalar1(10);
std::vector<vtkm::Float64> inputScalar2(10);
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32, 3>> handleV =
vtkm::cont::make_ArrayHandle(inputVec);
vtkm::cont::ArrayHandle<vtkm::Int32> handleS1 = vtkm::cont::make_ArrayHandle(inputScalar1);
vtkm::cont::ArrayHandle<vtkm::Float64> handleS2 = vtkm::cont::make_ArrayHandle(inputScalar2);
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32, 3>> handleOV;
vtkm::cont::ArrayHandle<vtkm::Int32> handleOS1;
vtkm::cont::ArrayHandle<vtkm::Float64> handleOS2;
vtkm::cont::DynamicArrayHandle out1(handleOV), out2(handleOS1), out3(handleOS2);
vtkm::worklet::DispatcherMapField<ExampleFieldWorklet> dispatcher;
dispatcher.Invoke(handleV, handleS1, handleS2, out1, out2, out3);
}
......@@ -31,6 +31,7 @@
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/DataSetBuilderUniform.h>
#include <vtkm/cont/Initialize.h>
#include <vtkm/cont/Timer.h>
#include <vtkm/interop/TransferToOpenGL.h>
......@@ -61,17 +62,9 @@
#include "LoadShaders.h"
//This is the list of devices to compile in support for. The order of the
//devices determines the runtime preference.
struct DevicesToTry : vtkm::ListTagBase<vtkm::cont::DeviceAdapterTagCuda,
vtkm::cont::DeviceAdapterTagTBB,
vtkm::cont::DeviceAdapterTagSerial>
{
};
struct GameOfLifePolicy : public vtkm::filter::PolicyBase<GameOfLifePolicy>
{
using DeviceAdapterList = DevicesToTry;
using FieldTypeList = vtkm::ListTagBase<vtkm::UInt8, vtkm::Vec<vtkm::UInt8, 4>>;
};
struct UpdateLifeState : public vtkm::worklet::WorkletPointNeighborhood
......@@ -231,7 +224,7 @@ struct RenderGameOfLife
UploadData task(&this->ColorState,
data.GetField("colors", vtkm::cont::Field::Association::POINTS));
vtkm::cont::TryExecute(task, DevicesToTry());
vtkm::cont::TryExecute(task);
vtkm::Float32 mvp[16] = { 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f,
0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 3.5f };
......@@ -322,6 +315,8 @@ void populate(std::vector<vtkm::UInt8>& input_state,
int main(int argc, char** argv)
{
vtkm::cont::Initialize(argc, argv);
glewExperimental = GL_TRUE;
glutInit(&argc, argv);
......
......@@ -32,19 +32,11 @@ if(TARGET OpenGL::GL AND
set(gl_libs OpenGL::GL GLEW::GLEW GLUT::GLUT)
add_executable(HelloWorld_SERIAL HelloWorld.cxx LoadShaders.h)
target_link_libraries(HelloWorld_SERIAL
PRIVATE vtkm_cont ${gl_libs})
if(TARGET vtkm::tbb)
add_executable(HelloWorld_TBB HelloWorldTBB.cxx LoadShaders.h)
target_link_libraries(HelloWorld_TBB
PRIVATE vtkm_cont ${gl_libs})
endif()
if(TARGET vtkm::cuda)
add_executable(HelloWorld_CUDA HelloWorld.cu LoadShaders.h)
target_link_libraries(HelloWorld_CUDA
PRIVATE vtkm_cont ${gl_libs})
add_executable(HelloWorld HelloWorld.cu LoadShaders.h)
else()
add_executable(HelloWorld HelloWorld.cxx LoadShaders.h)
endif()
target_link_libraries(HelloWorld PRIVATE vtkm_cont ${gl_libs})
endif()
......@@ -18,12 +18,6 @@
// this software.
//============================================================================
//We first check if VTKM_DEVICE_ADAPTER is defined, so that when TBB and CUDA
//includes this file we use the device adapter that they have set.
#ifndef VTKM_DEVICE_ADAPTER
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_SERIAL
#endif
// Must be included before any other GL includes:
#include <GL/glew.h>
......@@ -31,6 +25,7 @@
#include <vtkm/Math.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/Initialize.h>
#include <vtkm/cont/Timer.h>
#include <vtkm/interop/TransferToOpenGL.h>
#include <vtkm/worklet/DispatcherMapField.h>
......@@ -53,7 +48,7 @@
#include "LoadShaders.h"
template <typename DeviceAdapter, typename T>
template <typename T>
struct HelloVTKMInterop
{
vtkm::Vec<vtkm::Int32, 2> Dims;
......@@ -64,7 +59,7 @@ struct HelloVTKMInterop
vtkm::interop::BufferState VBOState;
vtkm::interop::BufferState ColorState;
vtkm::cont::Timer<DeviceAdapter> Timer;
vtkm::cont::Timer<> Timer;
std::vector<vtkm::Vec<T, 3>> InputData;
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> InHandle;
......@@ -172,8 +167,8 @@ struct HelloVTKMInterop
GenerateSurfaceWorklet worklet(t);
DispatcherType(worklet).Invoke(this->InHandle, this->OutCoords, this->OutColors);
vtkm::interop::TransferToOpenGL(this->OutCoords, this->VBOState, DeviceAdapter());
vtkm::interop::TransferToOpenGL(this->OutColors, this->ColorState, DeviceAdapter());
vtkm::interop::TransferToOpenGL(this->OutCoords, this->VBOState);
vtkm::interop::TransferToOpenGL(this->OutColors, this->ColorState);
this->render();
if (t > 10)
{
......@@ -184,8 +179,7 @@ struct HelloVTKMInterop
};
//global static so that glut callback can access it
using DeviceAdapter = VTKM_DEFAULT_DEVICE_ADAPTER_TAG;
HelloVTKMInterop<DeviceAdapter, vtkm::Float32>* helloWorld = nullptr;
HelloVTKMInterop<vtkm::Float32>* helloWorld = nullptr;
// Render the output using simple OpenGL
void run()
......@@ -201,9 +195,8 @@ void idle()
int main(int argc, char** argv)
{
using DeviceAdapterTraits = vtkm::cont::DeviceAdapterTraits<DeviceAdapter>;
std::cout << "Running Hello World example on device adapter: " << DeviceAdapterTraits::GetName()
<< std::endl;
vtkm::cont::Initialize(argc, argv);
std::cout << "Running Hello World example: " << std::endl;
glewExperimental = GL_TRUE;
glutInit(&argc, argv);
......@@ -221,7 +214,7 @@ int main(int argc, char** argv)
std::cout << "glewInit failed\n";
}
HelloVTKMInterop<DeviceAdapter, vtkm::Float32> hw(width, height);
HelloVTKMInterop<vtkm::Float32> hw(width, height);
helloWorld = &hw;
glutDisplayFunc(run);
......
//============================================================================
// 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 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// 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_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_TBB
#include "HelloWorld.cxx"
......@@ -46,7 +46,8 @@ struct TransferToOpenGL
BufferState& state) const
{
vtkm::interop::internal::TransferToOpenGL<ValueType, DeviceAdapterTag> toGL(state);
return toGL.Transfer(handle);
toGL.Transfer(handle);
return true;
}
};
}
......@@ -64,7 +65,7 @@ struct TransferToOpenGL
///
///
template <typename ValueType, class StorageTag, class DeviceAdapterTag>
VTKM_CONT void TransferToOpenGL(vtkm::cont::ArrayHandle<ValueType, StorageTag> handle,
VTKM_CONT void TransferToOpenGL(const vtkm::cont::ArrayHandle<ValueType, StorageTag>& handle,
BufferState& state,
DeviceAdapterTag)
{
......@@ -86,17 +87,17 @@ VTKM_CONT void TransferToOpenGL(vtkm::cont::ArrayHandle<ValueType, StorageTag> h
/// This function will throw exceptions if the transfer wasn't possible
///
template <typename ValueType, typename StorageTag>
VTKM_CONT void TransferToOpenGL(vtkm::cont::ArrayHandle<ValueType, StorageTag> handle,
VTKM_CONT void TransferToOpenGL(const vtkm::cont::ArrayHandle<ValueType, StorageTag>& handle,
BufferState& state)
{
vtkm::cont::DeviceAdapterId devId = handle.GetDeviceAdapterId();
bool success = vtkm::cont::TryExecuteOnDevice(devId, TransferToOpenGL, handle, state);
bool success = vtkm::cont::TryExecuteOnDevice(devId, detail::TransferToOpenGL{}, handle, state);
if (!success)
{
//Generally we are here because the devId is undefined
//or for some reason the last executed device is now disabled
success = vtkm::cont::TryExecute(TransferToOpenGL, handle, state);
success = vtkm::cont::TryExecute(detail::TransferToOpenGL{}, handle, state);
}
if (!success)
{
......
......@@ -24,7 +24,6 @@
#include <vtkm/cont/ErrorExecution.h>
#include <vtkm/cont/cuda/internal/DeviceAdapterTagCuda.h>
#include <vtkm/cont/cuda/internal/MakeThrustIterator.h>
#include <vtkm/interop/internal/TransferToOpenGL.h>
......@@ -157,7 +156,7 @@ public:
}
template <typename StorageTag>
VTKM_CONT void Transfer(vtkm::cont::ArrayHandle<ValueType, StorageTag>& handle) const
VTKM_CONT void Transfer(const vtkm::cont::ArrayHandle<ValueType, StorageTag>& handle) const
{
//make a buffer for the handle if the user has forgotten too
if (!glIsBuffer(*this->State.GetHandle()))
......@@ -192,20 +191,10 @@ public:
this->Resource->Map();
ValueType* beginPointer = this->Resource->GetMappedPoiner<ValueType>(size);
auto deviceMemory = vtkm::cont::make_ArrayHandle(beginPointer, size);
//get the device pointers
auto portal = handle.PrepareForInput(DeviceAdapterTag());
//Copy the data into memory that opengl owns, since we can't
//give memory from cuda to opengl
//Perhaps a direct call to thrust copy should be wrapped in a vtkm
//compatble function
::thrust::copy(ThrustCudaPolicyPerThread,
vtkm::cont::cuda::internal::IteratorBegin(portal),
vtkm::cont::cuda::internal::IteratorEnd(portal),
thrust::cuda::pointer<ValueType>(beginPointer));
cudaStreamSynchronize(cudaStreamPerThread);
//Do a device to device memory copy
vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapterTag>::Copy(handle, deviceMemory);
//unmap the resource
this->Resource->UnMap();
......
......@@ -95,7 +95,7 @@ namespace detail
{
template <class ValueType, class StorageTag, class DeviceAdapterTag>
VTKM_CONT void CopyFromHandle(vtkm::cont::ArrayHandle<ValueType, StorageTag>& handle,
VTKM_CONT void CopyFromHandle(const vtkm::cont::ArrayHandle<ValueType, StorageTag>& handle,
vtkm::interop::BufferState& state,
DeviceAdapterTag)
{
......@@ -145,7 +145,7 @@ VTKM_CONT void CopyFromHandle(vtkm::cont::ArrayHandle<ValueType, StorageTag>& ha
template <class ValueType, class DeviceAdapterTag>
VTKM_CONT void CopyFromHandle(
vtkm::cont::ArrayHandle<ValueType, vtkm::cont::StorageTagBasic>& handle,
const vtkm::cont::ArrayHandle<ValueType, vtkm::cont::StorageTagBasic>& handle,
vtkm::interop::BufferState& state,
DeviceAdapterTag)
{
......@@ -196,7 +196,7 @@ public:
}
template <typename StorageTag>
VTKM_CONT void Transfer(vtkm::cont::ArrayHandle<ValueType, StorageTag>& handle) const
VTKM_CONT void Transfer(const vtkm::cont::ArrayHandle<ValueType, StorageTag>& handle) const
{
//make a buffer for the handle if the user has forgotten too
if (!glIsBuffer(*this->State.GetHandle()))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment