@@ -33,32 +33,27 @@ void* loadApiFunction(void* handle, const char* name, bool optional) {
3333 return fn;
3434}
3535
36- std::mutex EnnApi::instance_mutex_;
37-
3836EnnApi* EnnApi::getEnnApiInstance () {
39- std::lock_guard<std::mutex> lgd (instance_mutex_);
4037 static EnnApi enn_api;
41- if (!enn_api.getInitialize ()) {
42- auto status = enn_api.loadApiLib ();
43- if (status == Error::Ok) {
44- ENN_LOG_INFO (" Loading ENN API library Completed." )
45- enn_api.initialize_ = true ;
46- } else {
47- ENN_LOG_ERROR (" Failed to load enn api library. %s" , dlerror ());
48- }
49- }
5038 return &enn_api;
5139}
5240
53- EnnApi::~EnnApi () {
54- std::lock_guard<std::mutex> lgd (instance_mutex_);
55- if (getInitialize ()) {
56- unloadApiLib ();
41+ EnnApi::EnnApi () {
42+ auto status = loadApiLib ();
43+ if (status == Error::Ok) {
44+ ET_LOG (Info, " Loading ENN API library Completed." );
45+ EnnInitialize ();
46+ initialize_ = true ;
47+ } else {
48+ ET_LOG (Error, " Failed to load enn api library. %s" , dlerror ());
5749 }
5850}
5951
60- bool EnnApi::getInitialize () const {
61- return initialize_;
52+ EnnApi::~EnnApi () {
53+ if (initialize_) {
54+ EnnDeinitialize ();
55+ unloadApiLib ();
56+ }
6257}
6358
6459Error EnnApi::loadApiLib () {
@@ -76,6 +71,7 @@ Error EnnApi::loadApiLib() {
7671 ENN_LOAD_API_FUNC (libenn_public_api_, EnnUnsetFastIpc, this );
7772 ENN_LOAD_API_FUNC (libenn_public_api_, EnnExecuteModelFastIpc, this );
7873 ENN_LOAD_API_FUNC (libenn_public_api_, EnnExecuteModel, this );
74+ ENN_LOAD_API_FUNC (libenn_public_api_, EnnCreateBuffer, this );
7975 ENN_LOAD_API_FUNC (
8076 libenn_public_api_, EnnExecuteModelWithSessionIdAsync, this );
8177 ENN_LOAD_API_FUNC (libenn_public_api_, EnnExecuteModelWithSessionIdWait, this );
@@ -87,13 +83,18 @@ Error EnnApi::loadApiLib() {
8783 ENN_LOAD_API_FUNC (libenn_public_api_, EnnBufferCommit, this );
8884 ENN_LOAD_API_FUNC (libenn_public_api_, EnnGetBuffersInfo, this );
8985 ENN_LOAD_API_FUNC (libenn_public_api_, EnnReleaseBuffers, this );
86+ ENN_LOAD_API_FUNC (libenn_public_api_, EnnCreateBuffer, this );
87+ ENN_LOAD_API_FUNC (libenn_public_api_, EnnReleaseBuffer, this );
88+ ENN_LOAD_API_FUNC (
89+ libenn_public_api_, EnnGetFileDescriptorFromEnnBuffer, this );
90+ ENN_LOAD_API_FUNC (libenn_public_api_, EnnOpenModelFromFd, this );
9091
9192 return Error::Ok;
9293}
9394
9495Error EnnApi::unloadApiLib () {
9596 if (dlclose (libenn_public_api_) != 0 ) {
96- ENN_LOG_ERROR ( " Failed to close ENN API library. %s" , dlerror ());
97+ ET_LOG (Error, " Failed to close ENN API library. %s" , dlerror ());
9798 return Error::Internal;
9899 }
99100 libenn_public_api_ = nullptr ;
0 commit comments