forked from ashwin/gStar4D
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2722cf9
Showing
35 changed files
with
16,597 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 10.00 | ||
# Visual Studio 2008 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GDelaunay", "GDelaunay\GDelaunay.vcproj", "{9E3ECF35-A6F3-4278-B396-0A686D8B720D}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Win32 = Debug|Win32 | ||
Release|Win32 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{9E3ECF35-A6F3-4278-B396-0A686D8B720D}.Debug|Win32.ActiveCfg = Debug|Win32 | ||
{9E3ECF35-A6F3-4278-B396-0A686D8B720D}.Debug|Win32.Build.0 = Debug|Win32 | ||
{9E3ECF35-A6F3-4278-B396-0A686D8B720D}.Release|Win32.ActiveCfg = Release|Win32 | ||
{9E3ECF35-A6F3-4278-B396-0A686D8B720D}.Release|Win32.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
Author: Ashwin Nanjappa | ||
Filename: Config.h | ||
Copyright (c) 2013, School of Computing, National University of Singapore. | ||
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 name of the National University of University nor the names of its contributors | ||
may be used to endorse or promote products derived from this software without specific | ||
prior written permission from the National University of Singapore. | ||
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 OWNER 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. | ||
*/ | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Configuration | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#pragma once | ||
|
||
#include "STLWrapper.h" | ||
|
||
enum Distribution | ||
{ | ||
UniformDistribution, | ||
GaussianDistribution, | ||
BallDistribution, | ||
SphereDistribution, | ||
GridDistribution, | ||
}; | ||
|
||
const std::string DistStr[] = | ||
{ | ||
"Uniform", | ||
"Gaussian", | ||
"Ball", | ||
"Sphere", | ||
"Grid" | ||
}; | ||
|
||
class Config | ||
{ | ||
public: | ||
int _seed; | ||
int _runNum; | ||
int _gridSize; | ||
int _pointNum; | ||
Distribution _dist; | ||
int _facetMax; | ||
bool _logVerbose; | ||
bool _logStats; | ||
bool _logTiming; | ||
bool _doCheck; | ||
bool _inFile; | ||
string _inFilename; | ||
int _predThreadNum; | ||
int _predBlockNum; | ||
bool _doSorting; | ||
bool _outFile; | ||
string _outFilename; | ||
}; | ||
|
||
Config& getConfig(); | ||
|
||
//////////////////////////////////////////////////////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/* | ||
Author: Ashwin Nanjappa | ||
Filename: CudaWrapper.h | ||
Copyright (c) 2013, School of Computing, National University of Singapore. | ||
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 name of the National University of University nor the names of its contributors | ||
may be used to endorse or promote products derived from this software without specific | ||
prior written permission from the National University of Singapore. | ||
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 OWNER 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. | ||
*/ | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// CUDA Wrapper | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#pragma once | ||
|
||
#include <cuda_runtime.h> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
// Define this to enable error checking | ||
#define CUDA_CHECK_ERROR | ||
|
||
#define CudaSafeCall( err ) __cudaSafeCall( err, __FILE__, __LINE__ ) | ||
#define CudaCheckError() __cudaCheckError( __FILE__, __LINE__ ) | ||
|
||
inline void __cudaSafeCall( cudaError err, const char *file, const int line ) | ||
{ | ||
#ifdef CUDA_CHECK_ERROR | ||
|
||
#pragma warning( push ) | ||
#pragma warning( disable: 4127 ) // Prevent warning on do-while(0); | ||
|
||
do | ||
{ | ||
if ( cudaSuccess != err ) | ||
{ | ||
fprintf( stderr, "cudaSafeCall() failed at %s:%i : %s\n", | ||
file, line, cudaGetErrorString( err ) ); | ||
exit( -1 ); | ||
} | ||
} while ( 0 ); | ||
|
||
#pragma warning( pop ) | ||
|
||
#endif // CUDA_CHECK_ERROR | ||
|
||
return; | ||
} | ||
|
||
inline void __cudaCheckError( const char *file, const int line ) | ||
{ | ||
#ifdef CUDA_CHECK_ERROR | ||
|
||
#pragma warning( push ) | ||
#pragma warning( disable: 4127 ) // Prevent warning on do-while(0); | ||
|
||
do | ||
{ | ||
cudaError err = cudaGetLastError(); | ||
if ( cudaSuccess != err ) | ||
{ | ||
fprintf( stderr, "cudaCheckError() failed at %s:%i : %s\n", | ||
file, line, cudaGetErrorString( err ) ); | ||
exit( -1 ); | ||
} | ||
|
||
// More careful checking. However, this will affect performance. | ||
// Comment away if needed. | ||
err = cudaDeviceSynchronize(); | ||
if( cudaSuccess != err ) | ||
{ | ||
fprintf( stderr, "cudaCheckError() with sync failed at %s:%i : %s\n", | ||
file, line, cudaGetErrorString( err ) ); | ||
exit( -1 ); | ||
} | ||
} while ( 0 ); | ||
|
||
#pragma warning( pop ) | ||
|
||
#endif // CUDA_CHECK_ERROR | ||
|
||
return; | ||
} | ||
|
||
#if __CUDA_ARCH__ >= 200 && defined( CUDA_CHECK_ERROR ) | ||
#define CudaAssert(X) \ | ||
if ( !(X) ) \ | ||
{ \ | ||
printf( "!!!Thread %d:%d failed assert at %s:%d!!!\n", \ | ||
blockIdx.x, threadIdx.x, __FILE__, __LINE__ ); \ | ||
} | ||
#else | ||
#define CudaAssert(X) | ||
#endif | ||
|
||
template< typename T > | ||
T* cuNew( int num ) | ||
{ | ||
T* loc = NULL; | ||
const size_t space = num * sizeof( T ); | ||
CudaSafeCall( cudaMalloc( &loc, space ) ); | ||
|
||
return loc; | ||
} | ||
|
||
template< typename T > | ||
void cuDelete( T** loc ) | ||
{ | ||
CudaSafeCall( cudaFree( *loc ) ); | ||
*loc = NULL; | ||
return; | ||
} | ||
|
||
inline void cuPrintMemory( const char* inStr ) | ||
{ | ||
const int MegaByte = ( 1 << 20 ); | ||
|
||
size_t free; | ||
size_t total; | ||
CudaSafeCall( cudaMemGetInfo( &free, &total ) ); | ||
|
||
printf( "[%s] Memory used: %d MB\n", inStr, ( total - free ) / MegaByte ); | ||
|
||
return; | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
Author: Ashwin Nanjappa and Cao Thanh Tung | ||
Filename: DtRandom.cpp | ||
Copyright (c) 2013, School of Computing, National University of Singapore. | ||
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 name of the National University of University nor the names of its contributors | ||
may be used to endorse or promote products derived from this software without specific | ||
prior written permission from the National University of Singapore. | ||
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 OWNER 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. | ||
*/ | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Random Number Generator | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
// Self | ||
#include "DtRandom.h" | ||
|
||
// External | ||
#include <climits> | ||
#include <cmath> | ||
|
||
void DtRandom::init( int seed, int minVal, int maxVal ) | ||
{ | ||
_min = ( float ) minVal; | ||
_max = ( float ) maxVal; | ||
|
||
// Seeds | ||
_z = seed; | ||
_w = seed; | ||
_jsr = seed; | ||
_jcong = seed; | ||
|
||
return; | ||
} | ||
|
||
unsigned long DtRandom::znew() | ||
{ return (_z = 36969 * (_z & 0xfffful) + (_z >> 16)); }; | ||
|
||
unsigned long DtRandom::wnew() | ||
{ return (_w = 18000 * (_w & 0xfffful) + (_w >> 16)); }; | ||
|
||
unsigned long DtRandom::MWC() | ||
{ return ((znew() << 16) + wnew()); }; | ||
|
||
unsigned long DtRandom::SHR3() | ||
{ _jsr ^= (_jsr << 17); _jsr ^= (_jsr >> 13); return (_jsr ^= (_jsr << 5)); }; | ||
|
||
unsigned long DtRandom::CONG() | ||
{ return (_jcong = 69069 * _jcong + 1234567); }; | ||
|
||
unsigned long DtRandom::rand_int() // [0,2^32-1] | ||
{ return ((MWC() ^ CONG()) + SHR3()); }; | ||
|
||
float DtRandom::random() // [0,1) | ||
{ return ((float) rand_int() / (float(ULONG_MAX)+1)); }; | ||
|
||
float DtRandom::getNext() | ||
{ | ||
const float val = _min + ( _max - _min) * random(); | ||
return val; | ||
} | ||
|
||
void DtRandom::nextGaussian(float &x, float &y, float &z) | ||
{ | ||
float x1, x2, x3, w; | ||
float tx, ty, tz; | ||
|
||
do { | ||
do { | ||
x1 = 2.0f * random() - 1.0f; | ||
x2 = 2.0f * random() - 1.0f; | ||
x3 = 2.0f * random() - 1.0f; | ||
w = x1 * x1 + x2 * x2 + x3 * x3; | ||
} while ( w >= 1.0 ); | ||
|
||
w = sqrt( (-2.0f * log( w ) ) / w ); | ||
tx = x1 * w; | ||
ty = x2 * w; | ||
tz = x3 * w; | ||
} while (tx < -3 || tx >= 3 || ty < -3 || ty >= 3 || tz < -3 || tz >= 3); | ||
|
||
x = _min + (_max - _min) * ( (tx + 3.0f) / 6.0f ); | ||
y = _min + (_max - _min) * ( (ty + 3.0f) / 6.0f ); | ||
z = _min + (_max - _min) * ( (tz + 3.0f) / 6.0f ); | ||
|
||
return; | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// |
Oops, something went wrong.