MCPcopy Create free account
hub / github.com/brainflow-dev/brainflow / load_api

Method load_api

src/ml/onnx/onnx_classifier.cpp:480–577  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

478}
479
480int OnnxClassifier::load_api ()
481{
482 int res = (int)BrainFlowExitCodes::STATUS_OK;
483 const OrtApiBase *(*OrtGetApiBase) (void) = NULL;
484 OrtGetApiBase = (const OrtApiBase *(*)(void))dll_loader->get_address ("OrtGetApiBase");
485 if (OrtGetApiBase == NULL)
486 {
487 safe_logger (spdlog::level::err, "failed to get function address for OrtGetApiBase");
488 res = (int)BrainFlowExitCodes::GENERAL_ERROR;
489 }
490
491 if (res == (int)BrainFlowExitCodes::STATUS_OK)
492 {
493 ort = OrtGetApiBase ()->GetApi (ORT_API_VERSION);
494 if (ort == NULL)
495 {
496 safe_logger (spdlog::level::err, "Ort GetApi failed");
497 res = (int)BrainFlowExitCodes::GENERAL_ERROR;
498 }
499 }
500
501 if (res == (int)BrainFlowExitCodes::STATUS_OK)
502 {
503 OrtStatus *onnx_status = ort->CreateEnvWithCustomLogger ((OrtLoggingFunction)log_onnx_msg,
504 (void *)this, ORT_LOGGING_LEVEL_VERBOSE, "brainflow_onnx_lib", &env);
505 if (onnx_status != NULL)
506 {
507 const char *msg = ort->GetErrorMessage (onnx_status);
508 safe_logger (spdlog::level::err, "CreateEnv failed: {}", msg);
509 ort->ReleaseStatus (onnx_status);
510 res = (int)BrainFlowExitCodes::GENERAL_ERROR;
511 }
512 else if (env == NULL)
513 {
514 safe_logger (spdlog::level::err, "CreateEnvWithCustomLogger failed");
515 res = (int)BrainFlowExitCodes::GENERAL_ERROR;
516 }
517 }
518
519 if (res == (int)BrainFlowExitCodes::STATUS_OK)
520 {
521 OrtStatus *onnx_status = ort->CreateSessionOptions (&session_options);
522 if (onnx_status != NULL)
523 {
524 const char *msg = ort->GetErrorMessage (onnx_status);
525 safe_logger (spdlog::level::err, "CreateSessionOptions failed: {}", msg);
526 ort->ReleaseStatus (onnx_status);
527 res = (int)BrainFlowExitCodes::GENERAL_ERROR;
528 }
529 else if (session_options == NULL)
530 {
531 safe_logger (spdlog::level::err, "CreateSessionOptions failed");
532 res = (int)BrainFlowExitCodes::GENERAL_ERROR;
533 }
534 }
535
536 if (res == (int)BrainFlowExitCodes::STATUS_OK)
537 {

Callers

nothing calls this directly

Calls 1

get_addressMethod · 0.45

Tested by

no test coverage detected