aboutsummaryrefslogtreecommitdiff
path: root/reference_model/src/main.cpp
diff options
context:
space:
mode:
authorJerry Ge <jerry.ge@arm.com>2023-10-30 10:18:45 -0700
committerJerry Ge <jerry.ge@arm.com>2023-11-16 21:56:43 +0000
commit5637a8606bc3caeec3c590350de770c7fcec8dd7 (patch)
treeb83a0d33d8a76c77cf560026e6cc8e8db22ad712 /reference_model/src/main.cpp
parentd3797f014811ca1ea876989b4839a8297eb1731e (diff)
downloadreference_model-5637a8606bc3caeec3c590350de770c7fcec8dd7.tar.gz
Support loading shared libraries for custom operators
- Add a new command line option to allow users to specify a custom defined dll library - Add a custom registry to store all registered libraries - Add a dummy example (custom_op_example.cpp) for demonstrating this new feature Signed-off-by: Jerry Ge <jerry.ge@arm.com> Change-Id: I7c360835933f77e33fcbd772cabfe01d82282d47
Diffstat (limited to 'reference_model/src/main.cpp')
-rw-r--r--reference_model/src/main.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/reference_model/src/main.cpp b/reference_model/src/main.cpp
index 80125ee..24784b5 100644
--- a/reference_model/src/main.cpp
+++ b/reference_model/src/main.cpp
@@ -18,6 +18,8 @@
#include "arith_util.h"
#include "command_line_utils.h"
+#include "custom_op_interface.h"
+#include "custom_registry.h"
#include "ops/op_factory.h"
#include "subgraph_traverser.h"
#include "tosa_serialization_handler.h"
@@ -38,6 +40,7 @@ int readInputTensors(SubgraphTraverser& gt, json& test_desc);
int writeFinalTensors(SubgraphTraverser& gt, json& test_desc, const std::string& filename_prefix);
int readVariableTensors(SubgraphTraverser& gt, json test_desc);
int writeVariableTensors(SubgraphTraverser& gt, json test_desc);
+int loadSharedLibs(std::string& custom_op_lib_path);
int loadGraph(TosaSerializationHandler& tsh, json& test_desc);
void parse_value(const std::string& text, tosa_level_t& value);
const std::string getResultFilenamePrefix();
@@ -83,6 +86,15 @@ int main(int argc, char** argv)
FATAL_ERROR("Unable to load test json");
}
+ // load shared libs if specified
+ if (g_func_config.custom_op_lib_path != "")
+ {
+ if (loadSharedLibs(g_func_config.custom_op_lib_path))
+ {
+ FATAL_ERROR("Shared library specified but not loaded successfully");
+ }
+ }
+
if (loadGraph(tsh, test_desc))
{
FATAL_ERROR("Unable to load graph");
@@ -236,6 +248,25 @@ int main(int argc, char** argv)
return (int)status;
}
+int loadSharedLibs(std::string& custom_op_lib_path)
+{
+ // Load the shared_lib
+ void* lib_handle = dlopen(custom_op_lib_path.c_str(), RTLD_LAZY);
+ if (lib_handle == nullptr)
+ {
+ FATAL_ERROR("Library %s does not exist\n", custom_op_lib_path.c_str());
+ }
+
+ typedef int (*get_customOp_function_t)(registration_callback_t registration_func);
+ auto get_customOp_creation_funcs = (get_customOp_function_t)dlsym(lib_handle, "getCustomOpCreationFuncs");
+ if (get_customOp_creation_funcs == nullptr)
+ {
+ FATAL_ERROR("Can't find the getCustomOpCreationFuncs \n");
+ }
+
+ return get_customOp_creation_funcs(&MasterRegistry::register_function);
+}
+
int loadGraph(TosaSerializationHandler& tsh, json& test_desc)
{
char graph_fullname[1024];