Skip to content

Commit

Permalink
[feat] test zipped mesh in json, migrate from float3 to FLOAT3, add b…
Browse files Browse the repository at this point in the history
…enchmark
  • Loading branch information
fangq committed Mar 9, 2024
1 parent cc3f362 commit efc4101
Show file tree
Hide file tree
Showing 15 changed files with 498 additions and 342 deletions.
2 changes: 1 addition & 1 deletion commons/Makefile_common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ pretty:
--suffix=none \
--formatted \
--break-blocks \
--exclude=mmc_bench.h \
--exclude=mmc_bench.c \
"*.c" "*.h" "*.cpp" "*.cu" "*.cl"

.PHONY: regression clean arch makedirs dep $(SUBDIRS)
Expand Down
28 changes: 15 additions & 13 deletions examples/validation/cube2.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
{
"Domain": {
"Session": {
"Photons": 30000000,
"RNGSeed": 27182818,
"ID": "cube2"
},
"Domain" : {
"Media": [
{"mua": 0.00, "mus": 0.0, "g": 1.00, "n": 1.0},
{"mua": 0.005,"mus": 1.0, "g": 0.01, "n": 1.37}
]
},
"Mesh": {
"MeshNode": [
[ 0, 0, 0],
[60, 0, 0],
Expand All @@ -9,25 +20,16 @@
[60, 0,60],
[ 0,60,60],
[60,60,60]
],
],
"MeshElem": [
[1, 2, 8, 4, 1],
[1, 3, 4, 8, 1],
[1, 2, 6, 8, 1],
[1, 5, 8, 6, 1],
[1, 3, 8, 7, 1],
[1, 5, 7, 8, 1]
],
"InitElem": 2,
"Media": [
{"mua": 0.00, "mus": 0.0, "g": 1.00, "n": 1.0},
{"mua": 0.005,"mus": 1.0, "g": 0.01, "n": 1.37}
]
},
"Session": {
"Photons": 30000000,
"RNGSeed": 27182818,
"ID": "cube"
],
"InitElem": 2
},
"Forward": {
"T0": 0.0e+00,
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ROOTDIR = ..
BINARY=mmc

FILES=mmc_rand_xorshift128p mmc_mesh mmc_raytrace mmc_utils mmc_tictoc mmc_host mmc_highorder mmc_cl_utils mmc_cl_host
FILES=mmc_rand_xorshift128p mmc_mesh mmc_raytrace mmc_utils mmc_tictoc mmc_host mmc_highorder mmc_bench mmc_cl_utils mmc_cl_host
CLPROGRAM=mmc_core

ifeq ($(findstring Darwin,$(PLATFORM)), Darwin)
Expand Down
177 changes: 177 additions & 0 deletions src/mmc_bench.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/***************************************************************************//**
** \mainpage Mesh-based Monte Carlo (MMC) - a 3D photon simulator
**
** \author Qianqian Fang <q.fang at neu.edu>
** \copyright Qianqian Fang, 2010-2024
**
** \section sref Reference:
** \li \c (\b Fang2010) Qianqian Fang, <a href="http://www.opticsinfobase.org/abstract.cfm?uri=boe-1-1-165">
** "Mesh-based Monte Carlo Method Using Fast Ray-Tracing
** in Plucker Coordinates,"</a> Biomed. Opt. Express, 1(1) 165-175 (2010).
** \li \c (\b Fang2012) Qianqian Fang and David R. Kaeli,
** <a href="https://www.osapublishing.org/boe/abstract.cfm?uri=boe-3-12-3223">
** "Accelerating mesh-based Monte Carlo method on modern CPU architectures,"</a>
** Biomed. Opt. Express 3(12), 3223-3230 (2012)
** \li \c (\b Yao2016) Ruoyang Yao, Xavier Intes, and Qianqian Fang,
** <a href="https://www.osapublishing.org/boe/abstract.cfm?uri=boe-7-1-171">
** "Generalized mesh-based Monte Carlo for wide-field illumination and detection
** via mesh retessellation,"</a> Biomed. Optics Express, 7(1), 171-184 (2016)
** \li \c (\b Fang2019) Qianqian Fang and Shijie Yan,
** <a href="http://dx.doi.org/10.1117/1.JBO.24.11.115002">
** "Graphics processing unit-accelerated mesh-based Monte Carlo photon transport
** simulations,"</a> J. of Biomedical Optics, 24(11), 115002 (2019)
** \li \c (\b Yuan2021) Yaoshen Yuan, Shijie Yan, and Qianqian Fang,
** <a href="https://www.osapublishing.org/boe/fulltext.cfm?uri=boe-12-1-147">
** "Light transport modeling in highly complex tissues using the implicit
** mesh-based Monte Carlo algorithm,"</a> Biomed. Optics Express, 12(1) 147-161 (2021)
**
** \section slicense License
** GPL v3, see LICENSE.txt for details
*******************************************************************************/

/***************************************************************************//**
\file mmc_bench.c
@brief MMC builtin benchmarks
*******************************************************************************/

#include "mmc_bench.h"

#define MSTR(...) #__VA_ARGS__

const char* benchname[MAX_MCX_BENCH] = {"dmmc-cube60", "dmmc-cube60b", ""};

const char* benchjson[MAX_MCX_BENCH] = {
MSTR(
{
"Session": {
"ID": "dmmc-cube60",
"Photons": 1e6,
"RNGSeed": 1648335518,
"DoMismatch": 0
},
"Domain" : {
"Media": [
{"mua": 0.00, "mus": 0.0, "g": 1.00, "n": 1.0},
{"mua": 0.005,"mus": 1.0, "g": 0.01, "n": 1.37}
]
},
"Mesh": {
"MeshNode": [
[ 0, 0, 0],
[60, 0, 0],
[ 0,60, 0],
[60,60, 0],
[ 0, 0,60],
[60, 0,60],
[ 0,60,60],
[60,60,60]
],
"MeshElem": [
[1, 2, 8, 4, 1],
[1, 3, 4, 8, 1],
[1, 2, 6, 8, 1],
[1, 5, 8, 6, 1],
[1, 3, 8, 7, 1],
[1, 5, 7, 8, 1]
],
"InitElem": 2
},
"Forward": {
"T0": 0.0e+00,
"T1": 5.0e-09,
"Dt": 5.0e-09
},
"Optode": {
"Source": {
"Pos": [30.1, 30.2, 0.0],
"Dir": [0.0, 0.0, 1.0]
},
"Detector": [
{
"Pos": [30.0, 20.0, 0.0],
"R": 1.0
},
{
"Pos": [30.0, 40.0, 0.0],
"R": 1.0
},
{
"Pos": [20.0, 30.0, 0.0],
"R": 1.0
},
{
"Pos": [40.0, 30.0, 0.0],
"R": 1.0
}
]
}
}),

MSTR(
{
"Session": {
"ID": "dmmc-cube60b",
"Photons": 1e6,
"RNGSeed": 1648335518,
"DoMismatch": 1
},
"Domain" : {
"Media": [
{"mua": 0.00, "mus": 0.0, "g": 1.00, "n": 1.0},
{"mua": 0.005,"mus": 1.0, "g": 0.01, "n": 1.37}
]
},
"Mesh": {
"MeshNode": [
[ 0, 0, 0],
[60, 0, 0],
[ 0,60, 0],
[60,60, 0],
[ 0, 0,60],
[60, 0,60],
[ 0,60,60],
[60,60,60]
],
"MeshElem": [
[1, 2, 8, 4, 1],
[1, 3, 4, 8, 1],
[1, 2, 6, 8, 1],
[1, 5, 8, 6, 1],
[1, 3, 8, 7, 1],
[1, 5, 7, 8, 1]
],
"InitElem": 2
},
"Forward": {
"T0": 0.0e+00,
"T1": 5.0e-09,
"Dt": 5.0e-09
},
"Optode": {
"Source": {
"Pos": [30.1, 30.2, 0.0],
"Dir": [0.0, 0.0, 1.0]
},
"Detector": [
{
"Pos": [30.0, 20.0, 0.0],
"R": 1.0
},
{
"Pos": [30.0, 40.0, 0.0],
"R": 1.0
},
{
"Pos": [20.0, 30.0, 0.0],
"R": 1.0
},
{
"Pos": [40.0, 30.0, 0.0],
"R": 1.0
}
]
}
})

};
121 changes: 5 additions & 116 deletions src/mmc_bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,127 +30,16 @@
*******************************************************************************/

/***************************************************************************//**
\file mcx_bench.h
\file mmc_bench.h
@brief MCX builtin benchmarks
@brief MMC builtin benchmarks
*******************************************************************************/

#ifndef _MCEXTREME_BENCHMARK_H
#define _MCEXTREME_BENCHMARK_H

#define MSTR(...) #__VA_ARGS__

const char *benchname[]={"d-cube60","d-cube60b",""};
const char *benchjson[]={
MSTR(
{
"Session": {
"ID": "d-cube60",
"Photons": 1e6,
"RNGSeed": 1648335518,
"DoMismatch": 0
},
"Domain": {
"Dim": [60,60,60],
"OriginType": 1,
"Media": [
{"mua": 0, "mus": 0, "g": 1, "n": 1},
{"mua": 0.005,"mus": 1.0, "g": 0.01, "n": 1.37},
{"mua": 0.002,"mus": 5, "g": 0.90, "n": 1}
]
},
"Shapes": [
{"Name": "cubic60"},
{"Origin": [0,0,0]},
{"Grid": {"Tag":1, "Size":[60,60,60]}}
],
"Forward": {
"T0": 0.0e+00,
"T1": 5.0e-09,
"Dt": 5.0e-09
},
"Optode": {
"Source": {
"Type":"pencil",
"Pos": [29.0, 29.0, 0.0],
"Dir": [0.0, 0.0, 1.0]
},
"Detector": [
{
"Pos": [29.0, 19.0, 0.0],
"R": 1.0
},
{
"Pos": [29.0, 39.0, 0.0],
"R": 1.0
},
{
"Pos": [19.0, 29.0, 0.0],
"R": 1.0
},
{
"Pos": [39.0, 29.0, 0.0],
"R": 1.0
}
]
}
}),


MSTR(
{
"Session": {
"ID": "d-cube60b",
"Photons": 1e6,
"RNGSeed": 1648335518,
"DoMismatch": true
},
"Domain": {
"Dim": [60,60,60],
"OriginType": 1,
"Media": [
{"mua": 0.00, "mus": 0.0, "g": 1.00, "n": 1.0},
{"mua": 0.005,"mus": 1.0, "g": 0.01, "n": 1.37},
{"mua": 0.002,"mus": 5.0, "g": 0.90, "n": 1.0}
]
},
"Shapes": [
{"Name": "cube60b"},
{"Origin": [0,0,0]},
{"Grid": {"Tag":1, "Size":[60,60,60]}}
],
"Forward": {
"T0": 0.0e+00,
"T1": 5.0e-09,
"Dt": 5.0e-09
},
"Optode": {
"Source": {
"Type":"pencil",
"Pos": [29.0, 29.0, 0.0],
"Dir": [0.0, 0.0, 1.0]
},
"Detector": [
{
"Pos": [29.0, 19.0, 0.0],
"R": 1.0
},
{
"Pos": [29.0, 39.0, 0.0],
"R": 1.0
},
{
"Pos": [19.0, 29.0, 0.0],
"R": 1.0
},
{
"Pos": [39.0, 29.0, 0.0],
"R": 1.0
}
]
}
})

};
#define MAX_MCX_BENCH 3 /**< Total number of built-in benchmarks */
extern const char* benchname[MAX_MCX_BENCH]; /**< String list defining the names of each built-in benchmark */
extern const char* benchjson[MAX_MCX_BENCH]; /**< JSON-formatted input configuration for each built-in benchmark */

#endif
2 changes: 1 addition & 1 deletion src/mmc_cl_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void mmc_run_cl(mcconfig* cfg, tetmesh* mesh, raytracer* tracer) {
memcpy(propdet + param.maxpropdet, tracer->n, (param.normbuf << 2)*sizeof(float4));

for (i = 0; i < workdev; i++) {
OCL_ASSERT(((gnode[i] = clCreateBuffer(mcxcontext, RO_MEM, sizeof(float3) * (mesh->nn), mesh->node, &status), status)));
OCL_ASSERT(((gnode[i] = clCreateBuffer(mcxcontext, RO_MEM, sizeof(FLOAT3) * (mesh->nn), mesh->node, &status), status)));
OCL_ASSERT(((gelem[i] = clCreateBuffer(mcxcontext, RO_MEM, sizeof(int4) * (mesh->ne), mesh->elem, &status), status)));
OCL_ASSERT(((gtype[i] = clCreateBuffer(mcxcontext, RO_MEM, sizeof(int) * (mesh->ne), mesh->type, &status), status)));
OCL_ASSERT(((gfacenb[i] = clCreateBuffer(mcxcontext, RO_MEM, sizeof(int4) * (mesh->ne), mesh->facenb, &status), status)));
Expand Down
2 changes: 1 addition & 1 deletion src/mmc_highorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void mesh_10nodetet(tetmesh* mesh, mcconfig* cfg) {
pos = 0;

mesh->nn += edgelist.size();
mesh->node = (float3*)realloc((void*)mesh->node, sizeof(float3) * (mesh->nn));
mesh->node = (FLOAT3*)realloc((void*)mesh->node, sizeof(FLOAT3) * (mesh->nn));
mesh->weight = (double*)realloc((void*)mesh->weight, sizeof(double) * mesh->nn * cfg->maxgate);
memset(mesh->weight, 0, sizeof(double)*mesh->nn * cfg->maxgate); // if mesh->weight is filled, need to allocate a new buffer, and copy the old buffer gate by gate

Expand Down
Loading

0 comments on commit efc4101

Please sign in to comment.