7#ifndef nnReconstructor_hpp
8#define nnReconstructor_hpp
12#include <cuda_runtime_api.h>
18#include <mx/improc/eigenCube.hpp>
19#include <mx/improc/eigenImage.hpp>
21#include "../../libMagAOX/libMagAOX.hpp"
22#include "../../magaox_git_version.h"
24using namespace nvinfer1;
27class Logger :
public ILogger {
29 if (
severity <= Severity::kWARNING) {
30 std::cout << msg << std::endl;
39 for (
size_t i = 0; i < num_elements; ++i) {
40 dst[i] = __half2float(src[i]);
45 for (
size_t i = 0; i < num_elements; ++i) {
46 dst[i] = __float2half(src[i]);
56class nnReconstructor :
public MagAOXApp<true>,
public dev::shmimMonitor<nnReconstructor>
149 mx::app::appConfigurator &
_config );
193 std::ifstream file(
filename, std::ios::binary);
195 std::cout <<
"Error opening " <<
filename << std::endl;
198 file.seekg(0, std::ios::end);
201 file.seekg(0, std::ios::beg);
211 std::cout <<
"Failed to createInferRuntime\n";
216 std::cout <<
"Failed to deserialize CUDA engine.\n";
218 std::cout <<
"Deserialized CUDA engine.\n";
225 std::cout <<
"Number of IO Tensors: " <<
numIOTensors << std::endl;
227 auto inputName =
engine->getIOTensorName(0);
228 auto outputName =
engine->getIOTensorName(1);
229 std::cout <<
"Tensor IO names: " << inputName <<
" " << outputName << std::endl;
239 std::cout <<
"Tensor input dimensions: " <<
inputC <<
"x" <<
inputH <<
"x" <<
inputW << std::endl;
240 std::cout <<
"Tensor output dimensions: " <<
outputSize << std::endl;
301 std::cout <<
"setupConfig()" << std::endl;
304 config.add(
"parameters.dataDirs",
306 "parameters.dataDirs",
312 "The path to the directory with the onnx model." );
314 config.add(
"parameters.engineDirs",
316 "parameters.engineDirs",
322 "The path to the directory with the TRT engine." );
324 config.add(
"parameters.onnxFileName",
326 "parameters.onnxFileName",
332 "Name of the Neural Net ONNX file" );
334 config.add(
"parameters.engineName",
336 "parameters.engineName",
342 "Name of the TRT engine." );
343 config.add(
"parameters.rebuildEngine",
345 "parameters.rebuildEngine",
351 "If true the engine will be rebuild." );
353 config.add(
"parameters.imageNorm",
355 "parameters.imageNorm",
361 "Normalization term for the preprocessed images." );
363 config.add(
"parameters.modalNorm",
365 "parameters.modalNorm",
371 "Normalization term for the modal coefficients." );
373 config.add(
"parameters.channel",
375 "parameters.channel",
381 "The output channel." );
383 config.add(
"parameters.m_pupPix",
385 "parameters.m_pupPix",
391 "Number of pixels across a PWFS pupil." );
393 config.add(
"parameters.pup_offset1_x",
395 "parameters.pup_offset1_x",
401 "Horizontal offset to the top left of the closest set op PWFS pupils." );
403 config.add(
"parameters.pup_offset1_y",
405 "parameters.pup_offset1_y",
411 "Vertical offset to the top left of the closest set op PWFS pupils." );
413 config.add(
"parameters.pup_offset2_x",
415 "parameters.pup_offset2_x",
421 "Horizontal offset to the top left of the furthest set op PWFS pupils." );
423 config.add(
"parameters.pup_offset2_y",
425 "parameters.pup_offset2_y",
431 "Vertical offset to the top left of the furthest set op PWFS pupils." );
437 std::cout <<
"loadConfigImpl()" << std::endl;
458 std::cout <<
"Debug configuration loading: " << std::endl;
459 std::cout <<
"dataDirs: " <<
dataDirs << std::endl;
460 std::cout <<
"engineDirs: " <<
engineDirs << std::endl;
461 std::cout <<
"onnxFileName: " <<
onnxFileName << std::endl;
462 std::cout <<
"engineName: " <<
engineName << std::endl;
463 std::cout <<
"rebuildEngine: " <<
rebuildEngine << std::endl;
464 std::cout <<
"imageNorm: " <<
imageNorm << std::endl;
465 std::cout <<
"modalNorm: " <<
modalNorm << std::endl;
468 std::cout <<
"m_pupPix: " <<
m_pupPix << std::endl;
469 std::cout <<
"pup_offset1_x: " <<
pup_offset1_x << std::endl;
470 std::cout <<
"pup_offset1_y: " <<
pup_offset1_y << std::endl;
471 std::cout <<
"pup_offset2_x: " <<
pup_offset2_x << std::endl;
472 std::cout <<
"pup_offset2_y: " <<
pup_offset2_y << std::endl;
540 std::cout <<
"allocate()" << std::endl;
541 static_cast<void>(
dummy );
555 std::cout <<
"Close shmims" << std::endl;
561 std::cout <<
"Open shmims" << std::endl;
573 std::cout <<
"Done!" << std::endl;
593 static_cast<void>(
dummy );
624 std::cout <<
"HOWDY" << std::endl;
void log(Severity severity, const char *msg) noexcept override
stateCodes::stateCodeT state()
Get the current state code.
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
std::mutex m_indiMutex
Mutex for locking INDI communications.
int appStartup()
Startup function.
uint32_t m_width
The width of the images in the stream.
int setupConfig(mx::app::appConfigurator &config)
Setup the configuration system.
int updateINDI()
Update the INDI properties for this device controller.
int appLogic()
Checks the shmimMonitor thread.
uint32_t m_height
The height of the images in the stream.
int appShutdown()
Shuts down the shmimMonitor thread.
int loadConfig(mx::app::appConfigurator &config)
load the configuration system results
float realT
Floating point type in which to do all calculations.
void create_engine_context()
size_t m_pwfsWidth
The width of the image.
void cleanup_engine_memory()
void cleanup_engine_context()
virtual int appStartup()
Startup function.
virtual int appLogic()
Implementation of the FSM for nnReconstructor.
unsigned long frame_counter
virtual int appShutdown()
Shutdown the app.
size_t m_pwfsHeight
The height of the image.
virtual void setupConfig()
nnReconstructor()
Default c'tor.
int loadConfigImpl(mx::app::appConfigurator &_config)
Implementation of loadConfig logic, separated for testing.
int allocate(const dev::shmimT &dummy)
uint32_t m_modevalHeight
The height of the shmim.
uint8_t m_pwfsDataType
The ImageStreamIO type code.
IExecutionContext * context
virtual void loadConfig()
virtual int appStartup()
Startup function.
size_t m_modevalTypeSize
The size of the type, in bytes.
std::string m_modevalChannel
virtual int appLogic()
Implementation of the FSM for nnReconstructor.
void load_engine(const std::string filename)
friend class nnReconstructor_test
int processImage(void *curr_src, const dev::shmimT &dummy)
size_t m_pwfsTypeSize
The size of the type, in bytes.
void prepare_engine_memory()
uint8_t m_modevalDataType
The ImageStreamIO type code.
virtual void loadConfig()
virtual void setupConfig()
std::vector< char > engineData
virtual int appShutdown()
Shutdown the app.
~nnReconstructor() noexcept
D'tor, declared and defined for noexcept.
uint32_t m_modevalWidth
The width of the shmim.
dev::shmimMonitor< nnReconstructor > shmimMonitorT
@ OPERATING
The device is operating, other than homing.
std::unique_lock< std::mutex > lock(m_indiMutex)
void halfToFloatArray(float *dst, const half *src, size_t num_elements)
void floatToHalfArray(half *dst, const float *src, size_t num_elements)