Monte Carlo eXtreme (MCX)
|
Python interface using Pybind11 for MCX. More...
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <iostream>
#include <string>
#include "mcx_utils.h"
#include "mcx_core.h"
#include "mcx_const.h"
#include "mcx_shapes.h"
#include <pybind11/iostream.h>
Macros | |
#define | PYBIND11_DETAILED_ERROR_MESSAGES |
#define | RAND_WORD_LEN 4 |
#define | GET_SCALAR_FIELD(src_pydict, dst_mcx_config, property, py_type) |
#define | GET_VEC3_FIELD(src, dst, prop, type) |
#define | GET_VEC4_FIELD(src, dst, prop, type) |
#define | GET_VEC34_FIELD(src, dst, prop, type) |
Functions | |
pybind11::PYBIND11_RUNTIME_EXCEPTION (runtime_error, PyExc_RuntimeError) | |
void | parseVolume (const py::dict &user_cfg, Config &mcx_config) |
void | parse_config (const py::dict &user_cfg, Config &mcx_config) |
void | cleanup_configs (MCXGPUInfo *&gpu_info, MCXConfig &mcx_config) |
py::dict | pmcx_interface (const py::dict &user_cfg) |
int | mcx_throw_exception (const int id, const char *msg, const char *filename, const int linenum) |
Error reporting function in PMCX, equivalent to mcx_error in binary mode. More... | |
void | print_mcx_usage () |
void | mcx_python_flush () |
Force matlab refresh the command window to print all buffered messages. | |
py::dict | pmcx_interface_wargs (py::args args, const py::kwargs &kwargs) |
py::str | print_version () |
py::list | get_GPU_info () |
PYBIND11_MODULE (_pmcx, m) | |
Variables | |
float * | det_ps = nullptr |
int | dim_det_ps [2] = {0, 0} |
buffer to receive data from cfg.detphotons field | |
int | seed_byte = 0 |
dimensions of the cfg.detphotons array | |
Python interface using Pybind11 for MCX.
#define GET_SCALAR_FIELD | ( | src_pydict, | |
dst_mcx_config, | |||
property, | |||
py_type | |||
) |
Macro to find and extract a scalar property from a source Python dictionary configuration and assign it in a destination MCX Config. The scalar is cast to the python type before assignment.
#define GET_VEC34_FIELD | ( | src, | |
dst, | |||
prop, | |||
type | |||
) |
#define GET_VEC3_FIELD | ( | src, | |
dst, | |||
prop, | |||
type | |||
) |
#define GET_VEC4_FIELD | ( | src, | |
dst, | |||
prop, | |||
type | |||
) |
#define RAND_WORD_LEN 4 |
number of Words per RNG state
|
inline |
Function that's called to cleanup any memory/configs allocated by PMCX. It is used in both normal and exceptional termination of the application
gpu_info | reference to an array of MCXGPUInfo data structure |
mcx_config | reference to MCXConfig data structure |
py::list get_GPU_info | ( | ) |
mcxconfig: structure to store all simulation parameters
gpuinfo: structure to store GPU information
int mcx_throw_exception | ( | const int | id, |
const char * | msg, | ||
const char * | filename, | ||
const int | linenum | ||
) |
Error reporting function in PMCX, equivalent to mcx_error in binary mode.
[in] | id | a single integer for the types of the error |
[in] | msg | the error message string |
[in] | filename | the unit file name where this error is raised |
[in] | linenum | the line number in the file where this error is raised |
void parseVolume | ( | const py::dict & | user_cfg, |
Config & | mcx_config | ||
) |
Determines the type of volume passed to the interface and decides how to copy it to MCXConfig.
user_cfg | |
mcx_config |
float to half conversion https://stackoverflow.com/questions/3026441/float32-to-float16/5587983#5587983 https://gamedev.stackexchange.com/a/17410 (for denorms)
py::dict pmcx_interface | ( | const py::dict & | user_cfg | ) |
gpuInfo: structure to store GPU information
activeDev: count of total active GPUs to be used
The next step, we identify gpu number and query all GPU info
Validate all input fields, and warn incompatible inputs
One must define the domain and properties
Initialize all buffers necessary to store the output variables
Start multiple threads, one thread to run portion of the simulation on one CUDA GPU, all in parallel
Enclose all simulation calls inside a try/catch construct for exception handling
Call the main simulation host function to start the simulation
If error is detected, gracefully terminate the mex and return back to Python
return the final optical properties for polarized MCX simulation
Clear up simulation data structures by calling the destructors
py::str print_version | ( | ) |
mcxconfig: structure to store all simulation parameters