Skip to content

Commit

Permalink
Adding piston_math.h to remove dependence on the NVIDIA GPU Computing…
Browse files Browse the repository at this point in the history
… SDK.

git-svn-id: svn://exponential.lanl.gov/usr/local/repository/piston@333 bcbcb40d-9a20-4f70-b08f-3d659b84208c
  • Loading branch information
csewell committed Feb 10, 2012
1 parent 56c0caa commit 2a4b3f3
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 19 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ set (ENABLE_INTEROP ON CACHE BOOL "Use interop")
if (USE_CUDA)
find_package(CUDA)
include_directories(${CMAKE_SOURCE_DIR})
include_directories(${CUDA_SDK_ROOT_DIR}/common/inc/)
include_directories(${CUDA_TOOLKIT_ROOT_DIR}/include)
else ()
set (THRUST_DIR "" CACHE PATH "Thrust directory")
Expand Down
16 changes: 9 additions & 7 deletions README
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PISTON: A Portable Cross-Platform Data-Parallel Visualization and Analysis Library
Authors: Li-Ta Lo, Chris Sewell, and Jim Ahrens

Version 0.2
Version 0.3

Copyright Notice:

Expand Down Expand Up @@ -39,19 +39,17 @@ OF SUCH DAMAGE.
Instructions for Use:

This project uses CMake. Create a build directory, pointing to this directory as the root of the source directory.
Dependencies include QT4 development, GLUT development, and Xmu development. To run the CUDA backend, installations of NVIDIA's
CUDA toolkit (including the thrust include files) and NVIDIA's GPU Computing SDK are required, and locations for these installations
may be provided in the CMake configuration. To run the demos that load files, VTK must be installed.
Dependencies include QT4 development, GLUT development, and Xmu development. To run the CUDA backend, an installation of NVIDIA's
CUDA toolkit (including the thrust include files) is required, and the location of this installation may be provided in the CMake
configuration. To run the demos that load files, VTK must also be installed.

Note that the CUDA backend used by this project uses NVIDIA's nvcc compiler, which is not compatible with gcc 4.5 and higher. If
your gcc version is 4.5 or newer, and you want to run the CUDA backend, you will also need to install an older version of gcc and
point to this version, either by changing environment variable paths or editing the compiler-bindir in the nvcc.profile file.

If you do not have the nvcc compiler or CUDA toolkit, you can still build the OpenMP examples. Set the USE_CUDA CMake variable to OFF.
You will then need to provide a directory for Thrust in the THRUST_DIR CMake variable, which you may download independently of CUDA
at the Thrust website (http://code.google.com/p/thrust/). You will also need to obtain the cutil_math.h file from NVIDIA's GPU
Computing SDK (http://developer.nvidia.com/gpu-computing-sdk) and place it in the top-level PISTON directory. However, you will
not need to compile or install the NVIDIA GPU Computing SDK.
at the Thrust website (http://code.google.com/p/thrust/).

If you do not have VTK, you can still build the examples in the examples directory (but not the file-loading demos in the demos
directory). Set the BUILD_DEMO CMake variable to OFF.
Expand Down Expand Up @@ -109,3 +107,7 @@ Here are some sample execution commands using the provided data sets:

% Apply the threshold operator to the NorthPacificEddies.vti file within the threshold range -0.25 up to -0.25 to -0.04, running with CUDA
./demoGPU NorthPacificEddies.vti 3 -0.25 -0.04




4 changes: 4 additions & 0 deletions demos/glyphrender.cu
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ void GlyphRender::display()
{
if (true)
{
#ifdef USE_INTEROP
if (useInterop)
{
for (int i=0; i<4; i++) glyphs->vboResources[i] = vboResources[i];
glyphs->minValue = minValue; glyphs->maxValue = maxValue;
}
#endif

(*(glyphs))();

Expand Down Expand Up @@ -225,6 +227,7 @@ void GlyphRender::initGL(bool aAllowInterop)
center_pos.x, center_pos.y, center_pos.z,
camera_up.x, camera_up.y, camera_up.z);

#ifdef USE_INTEROP
if (useInterop)
{
glewInit();
Expand All @@ -244,6 +247,7 @@ void GlyphRender::initGL(bool aAllowInterop)
glBindBuffer(GL_ARRAY_BUFFER, 0);
for (int i=0; i<4; i++) cudaGraphicsGLRegisterBuffer(&(vboResources[i]), vboBuffers[i], cudaGraphicsMapFlagsWriteDiscard);
}
#endif

//printf("Error code: %s\n", cudaGetErrorString(errorCode));
read();
Expand Down
4 changes: 3 additions & 1 deletion demos/glyphrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI

#include <GL/glew.h>
#include <GL/gl.h>
#ifdef USE_INTEROP
#include <cuda_gl_interop.h>
#endif

#include <GL/glut.h>
#include <thrust/host_vector.h>
Expand All @@ -54,7 +56,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
#include <sys/time.h>
#include "piston/util/quaternion.h"

#include <cutil_math.h>
#include <piston/piston_math.h>
#include <piston/choose_container.h>

using namespace piston;
Expand Down
12 changes: 10 additions & 2 deletions demos/isorender.cu
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,14 @@ void IsoRender::display()
if ((includeContours) && ((fabs(isovalue - lastIsovalue) > 0.01) || (animate)))
{
//std::cout << "Generating isovalue " << isovalue << std::endl;
#ifdef USE_INTEROP
if (useInterop)
{
for (int i=0; i<3; i++) contours[dataSetIndex]->vboResources[i] = vboResources[i];
for (int i=0; i<3; i++) contours[dataSetIndex]->vboBuffers[i] = vboBuffers[i];
contours[dataSetIndex]->minIso = minIso; contours[dataSetIndex]->maxIso = maxIso;
}
#endif
float value = isovalue;
if (animate) value += (rand() % 100)/100.0;
contours[dataSetIndex]->set_isovalue(value);
Expand All @@ -188,12 +190,14 @@ void IsoRender::display()

if ((includePlane) && (fabs(planeLevel - lastPlaneLevel) > 0.01))
{
#ifdef USE_INTEROP
if (useInterop)
{
for (int i=0; i<3; i++) planeContours[dataSetIndex]->vboResources[i] = planeResources[i];
for (int i=0; i<3; i++) planeContours[dataSetIndex]->vboBuffers[i] = planeBuffers[i];
planeContours[dataSetIndex]->minIso = minIso; planeContours[dataSetIndex]->maxIso = maxIso; planeContours[dataSetIndex]->colorFlip = useThreshold;
}
#endif
planeContours[dataSetIndex]->set_isovalue(planeLevel);
(*(planeContours[dataSetIndex]))();
lastPlaneLevel = planeLevel;
Expand All @@ -209,12 +213,14 @@ void IsoRender::display()
if ((includeThreshold) && (fabs(threshold - lastThreshold) > 0.01))
{
//std::cout << "Generating threshold " << thresholdFloor << " " << threshold << std::endl;
#ifdef USE_INTEROP
if (useInterop)
{
for (int i=0; i<3; i++) thresholds[dataSetIndex]->vboResources[i] = vboResources[i];
for (int i=0; i<3; i++) thresholds[dataSetIndex]->vboBuffers[i] = vboBuffers[i];
thresholds[dataSetIndex]->minThresholdRange = minThreshold; thresholds[dataSetIndex]->maxThresholdRange = maxThreshold;
}
#endif
thresholds[dataSetIndex]->set_threshold_range(thresholdFloor, threshold);
thresholds[dataSetIndex]->colorFlip = true;
(*(thresholds[dataSetIndex]))();
Expand Down Expand Up @@ -751,7 +757,7 @@ void IsoRender::createOperators()

if ((includePlane) && (planeContours[dataSetIndex] == 0))
{
planeFields[dataSetIndex] = new plane_field<int, float, SPACE>(make_float3((xMax-xMin+1)/2.0, (yMax-yMin+1)/2.0, (zMax-zMin+1))/2.0, plane_normal, xMax-xMin+1, yMax-yMin+1, zMax-zMin+1);
planeFields[dataSetIndex] = new plane_field<int, float, SPACE>(make_float3((xMax-xMin+1)/2.0, (yMax-yMin+1)/2.0, (zMax-zMin+1)/2.0), plane_normal, xMax-xMin+1, yMax-yMin+1, zMax-zMin+1);
planeContours[dataSetIndex] = new marching_cube<plane_field<int, float, SPACE>, vtk_image3d<int, float, SPACE> >(*(planeFields[dataSetIndex]), *(images[dataSetIndex]), isovalue);
planeContours[dataSetIndex]->useInterop = useInterop;
}
Expand All @@ -770,6 +776,7 @@ void IsoRender::createOperators()

if (includeConstantContours)
{
#ifdef USE_INTEROP
if (useInterop)
{
for (int i=0; i<3; i++) if (i != 1) constantContours[dataSetIndex]->vboResources[i] = constantResources[i];
Expand All @@ -778,6 +785,7 @@ void IsoRender::createOperators()
constantContours[dataSetIndex]->vboSize = 0;
constantContours[dataSetIndex]->useInterop = useInterop;
}
#endif
constantContours[dataSetIndex]->discardMinVals = false;
constantContours[dataSetIndex]->set_isovalue(-99999.9);
constantContours[dataSetIndex]->discardMinVals = false;
Expand Down Expand Up @@ -841,7 +849,7 @@ int IsoRender::read(char* aFileName, int aMode)

discardMinVals = true;
plane_normal.x = 0.0; plane_normal.y = 0.0; plane_normal.z = 1.0; planeLevelPct = 0.5;
zoomLevelPctDefault = 0.5; cameraFOV = 36.0; cameraZ = 3.0*max(max(xMax, yMax), zMax);
zoomLevelPctDefault = 0.5; cameraFOV = 36.0; cameraZ = 3.0*std::max(std::max(xMax, yMax), zMax);
zFar = 2.0*cameraZ; zNear = zFar/10.0;
planeMax = (xMax-xMin)*plane_normal.x + (yMax-yMin)*plane_normal.y + (zMax-zMin)*plane_normal.z;

Expand Down
5 changes: 4 additions & 1 deletion demos/isorender.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
#include <GL/gl.h>
#endif

#ifdef USE_INTEROP
#include <cuda_gl_interop.h>
#endif

#include <thrust/host_vector.h>
#include <thrust/functional.h>
#include <thrust/iterator/transform_iterator.h>
Expand All @@ -50,7 +53,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
#include <sys/time.h>
#include "piston/util/quaternion.h"

#include <cutil_math.h>
#include <piston/piston_math.h>
#include <piston/choose_container.h>

using namespace piston;
Expand Down
6 changes: 3 additions & 3 deletions examples/glwindow.cu
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
#include <QtOpenGL>
#include <QObject>

#ifdef USE_INTEROP
#include <cuda_gl_interop.h>
#endif

#include <vtkXMLImageDataReader.h>

#include <cutil_math.h>
#include <piston/piston_math.h>
#include <piston/choose_container.h>

#define SPACE thrust::detail::default_device_space_tag
Expand Down
93 changes: 93 additions & 0 deletions examples/timetest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
Copyright (c) 2011, Los Alamos National Security, LLC
All rights reserved.
Copyright 2011. Los Alamos National Security, LLC. This software was produced under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National Laboratory (LANL),
which is operated by Los Alamos National Security, LLC for the U.S. Department of Energy. The U.S. Government has rights to use, reproduce, and distribute this software.
NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE.
If software is modified to produce derivative works, such modified software should be clearly marked, so as not to confuse it with the version available from LANL.
Additionally, 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 Los Alamos National Security, LLC, Los Alamos National Laboratory, LANL, the U.S. Government, nor the names of its contributors may be used
to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC 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 LOS ALAMOS NATIONAL SECURITY, LLC 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.
*/

#include <piston/choose_container.h>

#define SPACE thrust::detail::default_device_space_tag
using namespace piston;

#include <piston/implicit_function.h>
#include <piston/marching_cube.h>
#include <piston/util/tangle_field.h>
#include <piston/util/plane_field.h>
#include <piston/util/sphere_field.h>
#include <piston/threshold_geometry.h>

#include <sys/time.h>
#include <stdio.h>
#include <math.h>

struct timeval begin, end, diff;
int frame_count = 1;
int grid_size = 256;

tangle_field<int, float, SPACE>* tangle;
marching_cube<tangle_field<int, float, SPACE>, tangle_field<int, float, SPACE> > *isosurface;

plane_field<int, float, SPACE>* plane;
marching_cube<plane_field<int, float, SPACE>, tangle_field<int, float, SPACE> > *cutplane;

sphere_field<int, float, SPACE>* scalar_field;
threshold_geometry<sphere_field<int, float, SPACE> >* threshold;


int main(int argc, char** argv)
{
#ifdef TANGLE
tangle = new tangle_field<int, float, SPACE>(grid_size, grid_size, grid_size);
isosurface = new marching_cube<tangle_field<int, float, SPACE>, tangle_field<int, float, SPACE> >(*tangle, *tangle, 0.2f);
gettimeofday(&begin, 0);
(*isosurface)();
std::cout << "Number of vertices: " << isosurface->numTotalVertices << std::endl;
#endif

#ifdef CUTPLANE
tangle = new tangle_field<int, float, SPACE>(grid_size, grid_size, grid_size);
plane = new plane_field<int, float, SPACE>(make_float3(0.0f, 0.0f, grid_size/2), make_float3(0.0f, 0.0f, 1.0f), grid_size, grid_size, grid_size);
cutplane = new marching_cube<plane_field<int, float, SPACE>, tangle_field<int, float, SPACE> >(*plane, *tangle, 0.2f);
gettimeofday(&begin, 0);
(*cutplane)();
std::cout << "Number of vertices: " << cutplane->numTotalVertices << std::endl;
#endif

#ifdef THRESHOLD
scalar_field = new sphere_field<int, float, SPACE>(grid_size, grid_size, grid_size);
threshold = new threshold_geometry<sphere_field<int, float, SPACE> >(*scalar_field, 4, 1600);
gettimeofday(&begin, 0);
(*threshold)();
std::cout << "Number of vertices: " << threshold->numTotalVertices << std::endl;
#endif

gettimeofday(&end, 0);
timersub(&end, &begin, &diff);
frame_count++;
float seconds = diff.tv_sec + 1.0E-6*diff.tv_usec;
char title[256];
sprintf(title, "Marching Cube, fps: %2.2f", float(frame_count)/seconds);
std::cout << title << std::endl;
seconds = 0.0f;

return 0;
}

13 changes: 11 additions & 2 deletions piston/glyph.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
#include <thrust/iterator/zip_iterator.h>

#include <piston/image3d.h>
#include <cutil_math.h>
#include <piston/piston_math.h>
#include <piston/choose_container.h>


Expand Down Expand Up @@ -76,7 +76,9 @@ class glyph
float3 *normalBufferData;
float4 *colorBufferData;
uint3 *indexBufferData;
#ifdef USE_INTEROP
struct cudaGraphicsResource* vboResources[4];
#endif

glyph(InputPoints inputPoints, InputVectors inputVectors, InputScalars inputScalars, GlyphVertices glyphVertices, GlyphNormals glyphNormals, GlyphIndices glyphIndices,
int nPoints, int nVertices, int nIndices) : inputPoints(inputPoints), inputVectors(inputVectors), inputScalars(inputScalars), glyphVertices(glyphVertices), glyphNormals(glyphNormals),
Expand All @@ -91,6 +93,7 @@ class glyph
scalars.resize(NCells*nVertices);
numIndices = NCells*nIndices;

#ifdef USE_INTEROP
if (useInterop)
{
size_t num_bytes;
Expand Down Expand Up @@ -126,12 +129,14 @@ class glyph
if (vboResources[1]) thrust::transform(scalars.begin(), scalars.end(), thrust::device_ptr<float4>(colorBufferData), color_map<float>(minValue, maxValue));
}
else
#endif
{
thrust::for_each(CountingIterator(0), CountingIterator(0)+NCells, generate_glyphs(inputPoints, inputVectors, inputScalars, glyphVertices, glyphNormals, glyphIndices,
thrust::raw_pointer_cast(&*vertices.begin()), thrust::raw_pointer_cast(&*normals.begin()), thrust::raw_pointer_cast(&*indices.begin()),
thrust::raw_pointer_cast(&*scalars.begin()), nVertices, nIndices));
}

#ifdef USE_INTEROP
if (useInterop)
{
/*thrust::copy(vertices.begin(), vertices_end(), thrust::device_ptr<float3>)
Expand All @@ -145,6 +150,7 @@ class glyph

for (int i=0; i<4; i++) cudaGraphicsUnmapResources(1, &vboResources[i], 0);
}
#endif
}

struct generate_glyphs : public thrust::unary_function<int, void>
Expand Down Expand Up @@ -218,7 +224,10 @@ class glyph
//for (int i=id*(nVertices); i<(id+1)*(nVertices); i++) *(normals+i) = *(glyphNormals+(i%(nVertices)));

uint3 offset; offset.x = offset.y = offset.z = id*nVertices;
for (int i=id*nIndices; i<(id+1)*nIndices; i++) *(indices+i) = *(glyphIndices+(i%nIndices)) + offset;
for (int i=id*nIndices; i<(id+1)*nIndices; i++) *(indices+i) = (uint3)(*(glyphIndices+(i%nIndices))) + offset;
//{
//indices[i].x = glyphIndices[i%nIndices].x + offset.x;
//}
}
};

Expand Down
4 changes: 3 additions & 1 deletion piston/marching_cube.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
#include <thrust/iterator/zip_iterator.h>

#include <piston/image3d.h>
#include <cutil_math.h>
#include <piston/piston_math.h>
#include <piston/choose_container.h>
#include <piston/hsv_color_map.h>

Expand Down Expand Up @@ -96,8 +96,10 @@ class marching_cube
float3 *normalBufferData;
float4 *colorBufferData;
int vboSize;
#ifdef USE_INTEROP
GLuint vboBuffers[3];
struct cudaGraphicsResource* vboResources[3]; // vertex buffers for interop
#endif

VerticesContainer vertices; // output vertices, only valid ones
NormalsContainer normals; // surface normal computed by cross product of triangle edges
Expand Down
Loading

0 comments on commit 2a4b3f3

Please sign in to comment.