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;
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]);
170 mx::app::appConfigurator &
_config
271 std::ifstream file(
filename, std::ios::binary);
273 std::cout <<
"Error opening " <<
filename << std::endl;
276 file.seekg(0, std::ios::end);
279 file.seekg(0, std::ios::beg);
289 std::cout <<
"Failed to createInferRuntime\n";
294 std::cout <<
"Failed to deserialize CUDA engine.\n";
296 std::cout <<
"Deserialized CUDA engine.\n";
303 std::cout <<
"Number of IO Tensors: " <<
numIOTensors << std::endl;
306 auto inputName =
engine->getIOTensorName(0);
307 auto outputName =
engine->getIOTensorName(1);
308 std::cout <<
"Tensor IO names: " << inputName <<
", " << outputName << std::endl;
319 std::cout <<
"Tensor input dimensions: " <<
inputC <<
"x" <<
inputH <<
"x" <<
inputW << std::endl;
320 std::cout <<
"Tensor output dimensions: " <<
outputSize << std::endl;
374 std::cout <<
"setupConfig()" << std::endl;
380 config.add(
"parameters.dataDirs",
382 "parameters.dataDirs",
388 "The path to the directory with the onnx model." );
390 config.add(
"parameters.engineDirs",
392 "parameters.engineDirs",
398 "The path to the directory with the TRT engine." );
400 config.add(
"parameters.engineName",
402 "parameters.engineName",
408 "Name of the TRT engine." );
410 config.add(
"parameters.rebuildEngine",
412 "parameters.rebuildEngine",
418 "If true the engine will be rebuild." );
420 config.add(
"parameters.imageNorm",
422 "parameters.imageNorm",
428 "Normalization term for the preprocessed images." );
430 config.add(
"parameters.modalNorm",
432 "parameters.modalNorm",
438 "Normalization term for the modal coefficients." );
440 config.add(
"parameters.use_fp16",
442 "parameters.use_fp16",
448 "If true the half precision mode will be used." );
450 config.add(
"parameters.explicit_tt",
452 "parameters.explicit_tt",
458 "If true the model will additionally give the pupil intensities as input to the NN." );
460 config.add(
"parameters.m_pupPix",
462 "parameters.m_pupPix",
468 "Number of pixels across a PWFS pupil." );
470 config.add(
"parameters.pup_offset1_x",
472 "parameters.pup_offset1_x",
478 "Horizontal offset to the top left of the closest set op PWFS pupils." );
480 config.add(
"parameters.pup_offset1_y",
482 "parameters.pup_offset1_y",
488 "Vertical offset to the top left of the closest set op PWFS pupils." );
490 config.add(
"parameters.pup_offset2_x",
492 "parameters.pup_offset2_x",
498 "Horizontal offset to the top left of the furthest set op PWFS pupils." );
500 config.add(
"parameters.pup_offset2_y",
502 "parameters.pup_offset2_y",
508 "Vertical offset to the top left of the furthest set op PWFS pupils." );
514 std::cout <<
"loadConfigImpl()" << std::endl;
542 std::cout <<
"Debug configuration loading: " << std::endl;
543 std::cout <<
"dataDirs: " <<
dataDirs << std::endl;
544 std::cout <<
"engineDirs: " <<
engineDirs << std::endl;
545 std::cout <<
"engineName: " <<
engineName << std::endl;
546 std::cout <<
"rebuildEngine: " <<
rebuildEngine << std::endl;
547 std::cout <<
"imageNorm: " <<
imageNorm << std::endl;
548 std::cout <<
"modalNorm: " <<
modalNorm << std::endl;
549 std::cout <<
"use_fp16: " <<
use_fp16 << std::endl;
550 std::cout <<
"explicit_tt: " <<
explicit_tt << std::endl;
553 std::cout <<
"m_pupPix: " <<
m_pupPix << std::endl;
554 std::cout <<
"pup_offset1_x: " <<
pup_offset1_x << std::endl;
555 std::cout <<
"pup_offset1_y: " <<
pup_offset1_y << std::endl;
556 std::cout <<
"pup_offset2_x: " <<
pup_offset2_x << std::endl;
557 std::cout <<
"pup_offset2_y: " <<
pup_offset2_y << std::endl;
661 std::cout <<
"allocate()" << std::endl;
662 static_cast<void>(
dummy );
699 static_cast<void>(
dummy );
788 static bool logged =
false;
801 log<text_log>( std::format(
"{} is wrong size ({}x{}) or type ({})",
876 if(
ipRecv.find(
"current" ) !=
true )
881 std::lock_guard<std::mutex> guard( m_indiMutex );
883 realT fps =
ipRecv[
"current"].get<
float>();
void log(Severity severity, const char *msg) noexcept override
The base-class for XWCTk applications.
stateCodes::stateCodeT state()
Get the current state code.
int m_shutdown
Flag to signal it's time to shutdown. When not 0, the main loop exits.
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
int createROIndiNumber(pcf::IndiProperty &prop, const std::string &propName, const std::string &propLabel="", const std::string &propGroup="")
Create a ReadOnly INDI Number property.
int registerIndiPropertyReadOnly(pcf::IndiProperty &prop)
Register an INDI property which is read only.
std::mutex m_indiMutex
Mutex for locking INDI communications.
timespec m_currImageTimestamp
The timestamp of the current image.
uint32_t m_width
The width of the image, once deinterlaced etc.
int recordFGTimings(bool force=false)
bool m_ownShmim
Flag controlling if the shmim is owned. If true it will be destroyed as needed.
size_t m_typeSize
The size of the type, in bytes. Result of sizeof.
uint8_t m_dataType
The ImageStreamIO type code.
uint32_t m_height
The height of the image, once deinterlaced etc.
uint32_t m_width
The width of the images in the stream.
uint32_t m_height
The height of the images in the stream.
int acquireAndCheckValid()
Acquire data.
float m_fps
Current FPS from the FPS source.
static constexpr bool c_frameGrabber_flippable
This framegrabber can't be flipped.
sem_t m_smSemaphore
Semaphore used to synchronize the fg thread and the dm command thread.
float realT
Floating point type in which to do all calculations.
int loadImageIntoStream(void *dest)
Loads the modevals into the stream.
void create_engine_context()
dev::telemeter< nnReconstructor > telemeterT
size_t m_pwfsWidth
The width of the image.
void cleanup_engine_memory()
eigenImage< float > modeval
void cleanup_engine_context()
virtual int appShutdown()
Shutdown the app.
size_t m_pwfsHeight
The height of the image.
virtual void setupConfig()
nnReconstructor()
Default c'tor.
int reconfig()
Take any actions needed to reconfigure the system. Called if m_reconfig is set to true.
int configureAcquisition()
Configure the output stream for acquistion.
pcf::IndiProperty m_indiP_fpsSource
int loadConfigImpl(mx::app::appConfigurator &_config)
Implementation of loadConfig logic, separated for testing.
int recordTelem(const telem_fgtimings *)
int allocate(const dev::shmimT &dummy)
INDI_SETCALLBACK_DECL(nnReconstructor, m_indiP_fpsSource)
dev::frameGrabber< nnReconstructor > frameGrabberT
uint8_t m_pwfsDataType
The ImageStreamIO type code.
IExecutionContext * context
virtual void loadConfig()
virtual int appStartup()
Startup function.
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()
bool m_updated
Flag indicating that the mode vals have been updated.
float fps()
Gets the frames-per-second readout rate.
std::vector< char > engineData
~nnReconstructor() noexcept
D'tor, declared and defined for noexcept.
int startAcquisition()
Start acquisition.
dev::shmimMonitor< nnReconstructor > shmimMonitorT
pcf::IndiProperty m_indiP_fps
#define FRAMEGRABBER_SETUP_CONFIG(cfig)
Call frameGrabberT::setupConfig with error checking for frameGrabber.
#define FRAMEGRABBER_APP_LOGIC
Call frameGrabberT::appLogic with error checking for frameGrabber.
#define FRAMEGRABBER_APP_SHUTDOWN
Call frameGrabberT::appShutdown with error checking for frameGrabber.
#define FRAMEGRABBER_UPDATE_INDI
Call frameGrabberT::updateINDI with error checking for frameGrabber.
#define FRAMEGRABBER_LOAD_CONFIG(cfig)
Call frameGrabberT::loadConfig with error checking for frameGrabber.
#define FRAMEGRABBER_APP_STARTUP
Call frameGrabberT::appStartup with error checking for frameGrabber.
#define INDI_SETCALLBACK_DEFN(class, prop)
Define the callback for a set property request.
#define REG_INDI_SETPROP(prop, devName, propName)
Register a SET INDI property with the class, using the standard callback name.
@ OPERATING
The device is operating, other than homing.
#define INDI_VALIDATE_CALLBACK_PROPS(prop1, prop2)
Standard check for matching INDI properties in a callback.
const pcf::IndiProperty & ipRecv
updateIfChanged(m_indiP_angle, "target", m_angle)
std::unique_lock< std::mutex > lock(m_indiMutex)
static constexpr logPrioT LOG_INFO
Informational. The info log level is the lowest level recorded during normal operations.
void halfToFloatArray(float *dst, const half *src, size_t num_elements)
void floatToHalfArray(half *dst, const float *src, size_t num_elements)
#define SHMIMMONITOR_APP_SHUTDOWN
Call shmimMonitorT::appShutdown with error checking for shmimMonitor.
#define SHMIMMONITOR_APP_LOGIC
Call shmimMonitorT::appLogic with error checking for shmimMonitor.
#define SHMIMMONITOR_APP_STARTUP
Call shmimMonitorT::appStartup with error checking for shmimMonitor.
#define SHMIMMONITOR_LOAD_CONFIG(cfig)
Call shmimMonitorT::loadConfig with error checking for shmimMonitor.
#define SHMIMMONITOR_UPDATE_INDI
Call shmimMonitorT::updateINDI with error checking for shmimMonitor.
#define SHMIMMONITOR_SETUP_CONFIG(cfig)
Call shmimMonitorT::setupConfig with error checking for shmimMonitor.
A device base class which saves telemetry.
int checkRecordTimes(const telT &tel, telTs... tels)
Check the time of the last record for each telemetry type and make an entry if needed.
Software CRITICAL log entry.
Log entry recording framegrabber timings.
#define TELEMETER_APP_LOGIC
Call telemeter::appLogic with error checking.
#define TELEMETER_LOAD_CONFIG(cfig)
Call telemeter::loadConfig with error checking.
#define TELEMETER_APP_STARTUP
Call telemeter::appStartup with error checking.
#define TELEMETER_SETUP_CONFIG(cfig)
Call telemeter::setupConfig with error checking.
#define TELEMETER_APP_SHUTDOWN
Call telemeter::appShutdown with error checking.