From e919716a7056fea29b65bbd7011c74b182d8e6e6 Mon Sep 17 00:00:00 2001 From: matinraayai Date: Sun, 24 Apr 2022 01:48:36 -0400 Subject: [PATCH] Prints GPU info. --- src/pymcx.cpp | 97 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 74 insertions(+), 23 deletions(-) diff --git a/src/pymcx.cpp b/src/pymcx.cpp index ddb75bdc..9e94d72c 100644 --- a/src/pymcx.cpp +++ b/src/pymcx.cpp @@ -28,35 +28,41 @@ void pyMcxInterface(const py::dict& userCfg) { if (itemKey == "nthread") { mcxConfig.nthread = py::reinterpret_borrow(item.second); } + if (itemKey == "seed") { + mcxConfig.seed = py::reinterpret_borrow(item.second); + } + if (itemKey == "srcpos") { + auto srcPosArray = py::reinterpret_borrow(item.second); + mcxConfig.srcpos = {srcPosArray[0].cast(), + srcPosArray[1].cast(), + srcPosArray[2].cast(), + srcPosArray[3].cast() + }; + } + if (itemKey == "srcdir") { + auto srcPosDir = py::reinterpret_borrow(item.second); + mcxConfig.srcdir = {srcPosDir[0].cast(), + srcPosDir[1].cast(), + srcPosDir[2].cast(), + srcPosDir[3].cast() + }; + } if (itemKey == "vol") { - auto cStyleVolume = py::array_t::ensure(item.second); - if (!cStyleVolume) { - std::cout << "Failed to cast to c!" << std::endl; - auto fStyleVolume = py::array_t::ensure(item.second); - auto bufferInfo = fStyleVolume.request(); - mcxConfig.vol = static_cast(bufferInfo.ptr); - mcxConfig.dim = {static_cast(bufferInfo.shape.at(0)), - static_cast(bufferInfo.shape.at(1)), - static_cast(bufferInfo.shape.at(2))}; - } - else { - std::cout << "Works like a charm converting to f!" << std::endl; - auto fStyleVolume = py::array_t(cStyleVolume); - mcxConfig.vol = static_cast(fStyleVolume.request().ptr); - auto bufferInfo = fStyleVolume.request(); - mcxConfig.dim = {static_cast(bufferInfo.shape.at(0)), - static_cast(bufferInfo.shape.at(1)), - static_cast(bufferInfo.shape.at(2))}; - } - for (int i = 0; i < mcxConfig.dim.x * mcxConfig.dim.y * mcxConfig.dim.z; i++) { - std::cout << mcxConfig.vol[i] << ", " << std::endl; - } + auto fStyleVolume = py::array_t::ensure(item.second); + auto bufferInfo = fStyleVolume.request(); + mcxConfig.vol = static_cast(bufferInfo.ptr); + mcxConfig.dim = {static_cast(bufferInfo.shape.at(0)), + static_cast(bufferInfo.shape.at(1)), + static_cast(bufferInfo.shape.at(2)) + }; } + } /** The next step, we identify gpu number and query all GPU info */ if(!(activeDev = mcx_list_gpu(&mcxConfig, &gpuInfo))) { mcx_error(-1,"No GPU device found\n",__FILE__,__LINE__); } + std::cout << gpuInfo->name << std::endl; //#ifdef _OPENMP // /** @@ -83,10 +89,55 @@ void pyMcxInterface(const py::dict& userCfg) { // return a pointer to the MCX output, wrapped in a std::vector } + +void printMCXUsage() { + std::cout << "PyMCX v2021.2\nUsage:\n flux, detphoton, vol, seeds = pymcx.mcx(cfg);\n\nRun 'help(pymcx.mcx)' for more details.\n"; +} + + +py::list getGPUInfo() { + Config mcxConfig; /** mcxconfig: structure to store all simulation parameters */ + GPUInfo *gpuInfo = nullptr; /** gpuinfo: structure to store GPU information */ + mcx_initcfg(&mcxConfig); + mcxConfig.isgpuinfo = 3; + py::list output; + if(!(mcx_list_gpu(&mcxConfig,&gpuInfo))){ + std::cerr << "No CUDA-capable device was found." << std::endl; + return output; + } + + for (int i = 0; i < gpuInfo[0].devcount; i++) { + py::dict currentDeviceInfo; + currentDeviceInfo["name"] = gpuInfo[i].name; + currentDeviceInfo["id"] = gpuInfo[i].id; + currentDeviceInfo["devcount"] = gpuInfo[i].devcount; + currentDeviceInfo["major"] = gpuInfo[i].major; + currentDeviceInfo["minor"] = gpuInfo[i].minor; + currentDeviceInfo["globalmem"] = gpuInfo[i].globalmem; + currentDeviceInfo["constmem"] = gpuInfo[i].constmem; + currentDeviceInfo["sharedmem"] = gpuInfo[i].sharedmem; + currentDeviceInfo["regcount"] = gpuInfo[i].regcount; + currentDeviceInfo["clock"] = gpuInfo[i].clock; + currentDeviceInfo["sm"] = gpuInfo[i].sm; + currentDeviceInfo["core"] = gpuInfo[i].core; + currentDeviceInfo["autoblock"] = gpuInfo[i].autoblock; + currentDeviceInfo["autothread"] = gpuInfo[i].autothread; + currentDeviceInfo["maxgate"] = gpuInfo[i].maxgate; + output.append(currentDeviceInfo); + } + mcx_cleargpuinfo(&gpuInfo); + mcx_clearcfg(&mcxConfig); + return output; +} + + + PYBIND11_MODULE(pymcx, m) { - m.doc() = "Monte Carlo eXtreme Python Interface www.mcx.space"; // optional module docstring + m.doc() = "PyMCX: Monte Carlo eXtreme Python Interface, www.mcx.space."; m.def("mcx", &pyMcxInterface, "Runs MCX"); + m.def("mcx", &printMCXUsage, ""); + m.def("gpu_info", &getGPUInfo, "Prints out the list of CUDA-capable devices attached to this system."); }