inputfileparser
This commit is contained in:
@ -17,7 +17,7 @@ builddir = "./build_linux64"
|
||||
doinstall = True #copies the build_output to the install dir when finished
|
||||
cc = "nvcc" #compiler
|
||||
cflags = "-dc --compiler-options '-fPIC -O3'"
|
||||
libraries = "-l{} -lamsculib3.linux64 -lpthread".format(libname)
|
||||
libraries = "-l{} -lamsculib3.linux64 -lamsstring4.linux64 -lamsmathutil25.linux64 -lpthread".format(libname)
|
||||
libdirs = "-L{} -L{}/lib -L{}/lib".format(builddir,commondir,depdir)
|
||||
linkerflags = " -Xlinker=-rpath,."
|
||||
srcexts = [".c",".cpp",".cu"]
|
||||
|
||||
33
build_linux64/default.inp
Normal file
33
build_linux64/default.inp
Normal file
@ -0,0 +1,33 @@
|
||||
#A default input file
|
||||
|
||||
//comments are either c or python style
|
||||
|
||||
avariable = bla
|
||||
|
||||
anothervar = 1.2,1.3, 1.5 //this is a comment
|
||||
|
||||
operatingmode = 1
|
||||
//1 - STL output
|
||||
//2 - count triangles
|
||||
//3 - count area
|
||||
|
||||
verbosity = 0
|
||||
|
||||
//domain
|
||||
xyz_min = -1.2,-1.2,-1.2
|
||||
xyz_max = 1.2,1.2,1.2
|
||||
Nx = 32
|
||||
Ny = 32
|
||||
Nz = 32
|
||||
|
||||
//execution parallelism pars
|
||||
nblockdiv = 32
|
||||
nthreads = 256
|
||||
|
||||
//function specific parameters
|
||||
//not all pars apply to all functions
|
||||
|
||||
isjulia = 0
|
||||
juliac = 0.0, 0.0, 0.0
|
||||
exponent = 8.0
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
build_linux64/objstore/amscufracls_parseinputfile.o
Normal file
BIN
build_linux64/objstore/amscufracls_parseinputfile.o
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
14
include/amscudafractallevelset/amscfls_functiondefs.cuh
Normal file
14
include/amscudafractallevelset/amscfls_functiondefs.cuh
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef __AMSCLFLS_FUNCTIONDEFS_CUH__
|
||||
#define __AMSCLFLS_FUNCTIONDEFS_CUH__
|
||||
|
||||
#ifdef AMSCLS_MANDELBROT
|
||||
struct main_functionpars
|
||||
{
|
||||
public:
|
||||
int fractaliter;
|
||||
float threshold;
|
||||
float freezethresh;
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
43
include/amscudafractallevelset/amscfls_parseinput.cuh
Normal file
43
include/amscudafractallevelset/amscfls_parseinput.cuh
Normal file
@ -0,0 +1,43 @@
|
||||
#ifndef __AMSCFLS_PARSEINPUT_CUH__
|
||||
#define __AMSCFLS_PARSEINPUT_CUH__
|
||||
|
||||
namespace amscuda
|
||||
{
|
||||
namespace fractallevelset
|
||||
{
|
||||
|
||||
struct inputpars
|
||||
{
|
||||
public:
|
||||
cuvec3f xyz_min;
|
||||
cuvec3f xyz_max;
|
||||
int Nx;
|
||||
int Ny;
|
||||
int Nz;
|
||||
int nblockdiv;
|
||||
int nthreads;
|
||||
|
||||
bool isjulia;
|
||||
cuvec3f juliac;
|
||||
float exponent;
|
||||
|
||||
|
||||
|
||||
int operatingmode;
|
||||
int verbosity;
|
||||
|
||||
__host__ __device__ inputpars();
|
||||
};
|
||||
|
||||
int parse_input(const char *fname, inputpars *pars);
|
||||
|
||||
void inputmain(int argc, char *argv[]);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};//end namespaces
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -38,6 +38,11 @@ class cuvec4f;
|
||||
// #define AMSCU_CONST
|
||||
// #endif
|
||||
|
||||
#define AMSCLS_MANDELBROT
|
||||
//#define AMSCLS_JULIA
|
||||
//#define AMSCLS_PPKFRACTAL
|
||||
|
||||
|
||||
namespace amscuda
|
||||
{
|
||||
namespace fractallevelset
|
||||
@ -45,18 +50,10 @@ namespace fractallevelset
|
||||
|
||||
__device__ __host__ int isignf(float f);
|
||||
|
||||
struct main_functionpars
|
||||
{
|
||||
public:
|
||||
int fractaliter;
|
||||
float threshold;
|
||||
float freezethresh;
|
||||
};
|
||||
#include <amscudafractallevelset/amscfls_functiondefs.cuh>
|
||||
|
||||
__host__ __device__ float main_function(cuvec3f pos, main_functionpars &pars);
|
||||
|
||||
|
||||
|
||||
class bagoftriangles
|
||||
{
|
||||
public:
|
||||
@ -160,18 +157,26 @@ struct marchingtet_pars
|
||||
__device__ __host__ marchingtet_pars();
|
||||
};
|
||||
|
||||
}; //end namespaces
|
||||
};
|
||||
|
||||
#include <amscudafractallevelset/amscfls_parseinput.cuh>
|
||||
|
||||
namespace amscuda
|
||||
{
|
||||
namespace fractallevelset
|
||||
{
|
||||
///////////
|
||||
// Tests //
|
||||
///////////
|
||||
void test_tetorientation();
|
||||
void test_mtcube_triangulation();
|
||||
void test_marchingtets();
|
||||
void hausdorff_test();
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
};//end namespaces
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -18,5 +18,5 @@ for o in obj_list:
|
||||
os.remove('{}'.format(o))
|
||||
|
||||
os.chdir('./build_linux64')
|
||||
callproc('./test')
|
||||
callproc('./test ./default.inp')
|
||||
os.chdir('..')
|
||||
|
||||
@ -6,16 +6,61 @@ namespace fractallevelset
|
||||
{
|
||||
|
||||
|
||||
// __host__ __device__ float main_function(cuvec3f pos, main_functionpars &pars)
|
||||
// {
|
||||
// float ret = 0.0f;
|
||||
|
||||
// ret = pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2]-pars.threshold;
|
||||
|
||||
// return -ret;
|
||||
// };
|
||||
|
||||
#ifdef AMSCLS_MANDELBROT
|
||||
__host__ __device__ float main_function(cuvec3f pos, main_functionpars &pars)
|
||||
{
|
||||
float ret = 0.0f;
|
||||
float wr,wtheta,wphi;
|
||||
cuvec3f w;
|
||||
int I;
|
||||
|
||||
w = pos;
|
||||
|
||||
for(I=0;I<pars.fractaliter;I++)
|
||||
{
|
||||
wr = cuvec3f_norm(w);
|
||||
wtheta = ::acos(w.y/wr);
|
||||
wphi = ::atan2(w.x,w.z);
|
||||
if(wr>pars.freezethresh) break;
|
||||
wr = ::pow(wr,8.0f);
|
||||
wtheta = wtheta*8.0f;
|
||||
wphi = wphi*8.0f;
|
||||
w = cuvec3f(wr*sin(wtheta)*sin(wphi),wr*cos(wtheta),wr*sin(wtheta)*cos(wphi));
|
||||
w = w + pos;
|
||||
}
|
||||
|
||||
ret = cuvec3f_norm(w)-pars.threshold;
|
||||
|
||||
return ret;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef AMSCLS_JULIA
|
||||
__host__ __device__ float main_function(cuvec3f pos, main_functionpars &pars)
|
||||
{
|
||||
float ret = 0.0f;
|
||||
|
||||
ret = pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2]-pars.threshold;
|
||||
|
||||
return -ret;
|
||||
return ret;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef AMSCLS_PPKFRACTAL
|
||||
__host__ __device__ float main_function(cuvec3f pos, main_functionpars &pars)
|
||||
{
|
||||
float ret = 0.0f;
|
||||
|
||||
return ret;
|
||||
};
|
||||
#endif
|
||||
|
||||
};//end namespace fractallevelset
|
||||
};// end namespace amscuda
|
||||
|
||||
@ -298,7 +298,7 @@ namespace fractallevelset
|
||||
}
|
||||
|
||||
marchingtets_gpu_areacount<<<nblocks,nthreads>>>(mtpars,dareabuffer);
|
||||
printf("debug: launching marchingtets_gpu_areacount with <%d,%d>\n",nblocks,nthreads);
|
||||
//printf("debug: launching marchingtets_gpu_areacount with <%d,%d>\n",nblocks,nthreads);
|
||||
cudaError_t err = cudaSuccess;
|
||||
cudaDeviceSynchronize();
|
||||
err = cudaGetLastError();
|
||||
@ -355,11 +355,11 @@ namespace fractallevelset
|
||||
|
||||
void test_marchingtets()
|
||||
{
|
||||
const char *fnameout = "./testout.stl";
|
||||
const char *fnameout = "./testout2.stl";
|
||||
bagoftriangles mesh;
|
||||
main_functionpars fpars;
|
||||
fpars.fractaliter = 64;
|
||||
fpars.threshold = 0.5f;
|
||||
fpars.threshold = 2.0f;
|
||||
fpars.freezethresh = 10.0f;
|
||||
|
||||
marchingtet_pars mtpars;
|
||||
@ -389,5 +389,64 @@ namespace fractallevelset
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void hausdorff_test1a(int fractaliter, int N, float &deltat, float &area, float &narea)
|
||||
{
|
||||
main_functionpars fpars;
|
||||
fpars.fractaliter = fractaliter;
|
||||
fpars.threshold = 2.0f;
|
||||
fpars.freezethresh = 10.0f;
|
||||
|
||||
marchingtet_pars mtpars;
|
||||
mtpars.xyz_min = cuvec3f(-1.2,-1.2,-1.2);
|
||||
mtpars.xyz_max = cuvec3f(1.2,1.2,1.2);
|
||||
mtpars.Nx = N;
|
||||
mtpars.Ny = N;
|
||||
mtpars.Nz = N;
|
||||
|
||||
mtpars.pars = fpars;
|
||||
|
||||
float t0,t1;
|
||||
|
||||
float dx = (mtpars.xyz_max[0]-mtpars.xyz_min[0])/((float)N);
|
||||
|
||||
//printf("debug: dA=%1.3f\n",dx*dx);
|
||||
|
||||
t0 = util::time_msec();
|
||||
area = marchingtets_area_gpu(mtpars);
|
||||
t1 = util::time_msec();
|
||||
narea = area/dx/dx;
|
||||
|
||||
deltat=t1-t0;
|
||||
|
||||
// printf("marchingtets_area_gpu: %1.3f msec runtime %d psize\n",t1-t0,mtpars.Nx*mtpars.Ny*mtpars.Nz);
|
||||
// printf("area=%1.3f, area/4pi=%1.3f\n",area,area/4.0f/pif);
|
||||
}
|
||||
|
||||
void hausdorff_test()
|
||||
{
|
||||
int fiters[] = {32,64,128,256};
|
||||
//int fiter;
|
||||
int N = 32;
|
||||
|
||||
int I,J;
|
||||
|
||||
float deltat,area,narea;
|
||||
|
||||
for(I=0;I<4;I++)
|
||||
{
|
||||
N=32;
|
||||
for(J=0;J<5;J++)
|
||||
{
|
||||
hausdorff_test1a(fiters[I],N,deltat,area,narea);
|
||||
printf("%d,%d,%1.6g,%1.6g,%1.6g\n",fiters[I],N,deltat,area,narea);
|
||||
N*=2;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};//end namespace fractallevelset
|
||||
};// end namespace amscuda
|
||||
|
||||
236
src/amscudafractallevelset/amscufracls_parseinputfile.cu
Normal file
236
src/amscudafractallevelset/amscufracls_parseinputfile.cu
Normal file
@ -0,0 +1,236 @@
|
||||
#include <amscudafractallevelset/amscudafractallevelset.cuh>
|
||||
#include <amsmathutil25/amsmathutil25.hpp>
|
||||
#include <amsstring4/amsstring4.hpp>
|
||||
|
||||
using namespace ams;
|
||||
|
||||
namespace amscuda
|
||||
{
|
||||
namespace fractallevelset
|
||||
{
|
||||
|
||||
static const int omode_stloutput = 1;
|
||||
static const int omode_counttriangles = 2;
|
||||
static const int omode_countarea = 3;
|
||||
|
||||
|
||||
|
||||
inputpars::inputpars()
|
||||
{
|
||||
xyz_min = cuvec3f(-1.2,-1.2,-1.2);
|
||||
xyz_max = cuvec3f(1.2,1.2,1.2);
|
||||
|
||||
Nx = 32;
|
||||
Ny = 32;
|
||||
Nz = 32;
|
||||
|
||||
nblockdiv = 32;
|
||||
nthreads = 256;
|
||||
|
||||
isjulia = 0;
|
||||
juliac = cuvec3f(0,0,0);
|
||||
exponent = 8.0f;
|
||||
|
||||
operatingmode = omode_stloutput;
|
||||
verbosity = 0; //0 silent, 1
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int load_inputfile(const char *fname, amsarray<amsarray<amsstring>> *stringpars)
|
||||
{
|
||||
int ret = 1;
|
||||
int res;
|
||||
amsstring ftxt,ln;
|
||||
amsarray<amsstring> lns;
|
||||
amsarray<amsstring> pair;
|
||||
int I;
|
||||
|
||||
if(stringpars==NULL)
|
||||
{
|
||||
printf("parse_input error: stringpars is NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
stringpars->resize(0);
|
||||
|
||||
res = readtextfile(fname,&ftxt);
|
||||
if(res<0)
|
||||
{
|
||||
printf("parse_input error: could not open %s for reading.\n",fname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
lns = ftxt.splitlines();
|
||||
for(I=0;I<lns.length;I++)
|
||||
{
|
||||
ln = lns[I].splitfirst("#")[0];
|
||||
ln = ln.splitfirst("//")[0];
|
||||
if(ln.length>0)
|
||||
{
|
||||
pair = ln.splitfirst("=");
|
||||
if(pair[0].length>0 && pair[1].length>0)
|
||||
{
|
||||
pair[0] = pair[0].stripwhitespace();
|
||||
pair[1] = pair[1].stripwhitespace();
|
||||
stringpars->append(pair);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// printf("debug: parfile pars:\n");
|
||||
// for(I=0;I<stringpars->length;I++)
|
||||
// {
|
||||
// printf("%d:\t'%s'\t'%s'\n",I,stringpars->at(I)[0].cstring,stringpars->at(I)[1].cstring);
|
||||
// }
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
cuvec3f parse_as_cuvec3f(amsstring s)
|
||||
{
|
||||
int I;
|
||||
cuvec3f ret;
|
||||
amsarray<amsstring> alphanums;
|
||||
|
||||
alphanums = s.splitalphanum();
|
||||
for(I=0;I<alphanums.length&&I<3;I++)
|
||||
{
|
||||
ret[I] = (float)(alphanums[I].strtonum());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void parsearch_cuvec3f(amsstring varname, amsarray<amsarray<amsstring>> *stringpars, cuvec3f *val)
|
||||
{
|
||||
int I;
|
||||
for(I=0;I<stringpars->length;I++)
|
||||
{
|
||||
if(varname==stringpars->at(I)[0])
|
||||
{
|
||||
*val = parse_as_cuvec3f(stringpars->at(I)[1]);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void parsearch_float(amsstring varname, amsarray<amsarray<amsstring>> *stringpars, float *val)
|
||||
{
|
||||
int I;
|
||||
for(I=0;I<stringpars->length;I++)
|
||||
{
|
||||
if(varname==stringpars->at(I)[0])
|
||||
{
|
||||
*val = (float) stringpars->at(I)[1].strtonum();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void parsearch_int(amsstring varname, amsarray<amsarray<amsstring>> *stringpars, int *val)
|
||||
{
|
||||
int I;
|
||||
for(I=0;I<stringpars->length;I++)
|
||||
{
|
||||
if(varname==stringpars->at(I)[0])
|
||||
{
|
||||
*val = (int) stringpars->at(I)[1].strtonum();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void parsearch_bool(amsstring varname, amsarray<amsarray<amsstring>> *stringpars, bool *val)
|
||||
{
|
||||
int I;
|
||||
for(I=0;I<stringpars->length;I++)
|
||||
{
|
||||
if(varname==stringpars->at(I)[0])
|
||||
{
|
||||
*val = (bool) stringpars->at(I)[1].strtonum();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int parse_input(const char *fname, inputpars *pars)
|
||||
{
|
||||
int ret = 1;
|
||||
int res;
|
||||
amsarray<amsarray<amsstring>> stringpars;
|
||||
res = load_inputfile(fname,&stringpars);
|
||||
|
||||
parsearch_cuvec3f("xyz_min",&stringpars,&(pars->xyz_min));
|
||||
parsearch_cuvec3f("xyz_max",&stringpars,&(pars->xyz_max));
|
||||
parsearch_int("Nx",&stringpars,&(pars->Nx));
|
||||
parsearch_int("Ny",&stringpars,&(pars->Ny));
|
||||
parsearch_int("Nz",&stringpars,&(pars->Nz));
|
||||
parsearch_int("nblockdiv",&stringpars,&(pars->nblockdiv));
|
||||
parsearch_int("nthreads",&stringpars,&(pars->nthreads));
|
||||
parsearch_bool("juliac",&stringpars,&(pars->isjulia));
|
||||
parsearch_int("operatingmode",&stringpars,&(pars->operatingmode));
|
||||
parsearch_int("verbosity",&stringpars,&(pars->verbosity));
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void inputmain(int argc, char *argv[])
|
||||
{
|
||||
int res;
|
||||
amsstring fnameout;
|
||||
inputpars pars;
|
||||
marchingtet_pars mtpars;
|
||||
main_functionpars mfpars;
|
||||
|
||||
if(argc<3)
|
||||
{
|
||||
fnameout = "./output.stl";
|
||||
}
|
||||
else
|
||||
{
|
||||
fnameout = argv[2];
|
||||
}
|
||||
|
||||
if(argc<2)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
res = parse_input(argv[1],&pars);
|
||||
if(res<0) return;
|
||||
}
|
||||
|
||||
//Fill operatingstructs
|
||||
mtpars.xyz_min = pars.xyz_min;
|
||||
mtpars.xyz_max = pars.xyz_max;
|
||||
mtpars.Nx = pars.Nx;
|
||||
mtpars.Ny = pars.Ny;
|
||||
mtpars.Nz = pars.Nz;
|
||||
mtpars.pars = mfpars;
|
||||
|
||||
//execute model based on operatingmode
|
||||
if(pars.operatingmode==omode_stloutput)
|
||||
{
|
||||
|
||||
}
|
||||
else if(pars.operatingmode==omode_counttriangles)
|
||||
{
|
||||
|
||||
}
|
||||
else if(pars.operatingmode==omode_countarea)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
};//end namespace fractallevelset
|
||||
};// end namespace amscuda
|
||||
@ -12,8 +12,10 @@ int main(int argc, char* argv[])
|
||||
//test_tetorientation();
|
||||
//test_mtcube_triangulation();
|
||||
|
||||
test_marchingtets();
|
||||
//test_marchingtets();
|
||||
//hausdorff_test();
|
||||
|
||||
inputmain(argc,argv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user