bool register_backend()

in source/neuropod/internal/backend_registration.cc [236:273]


bool register_backend(const std::string &    name,
                      const std::string &    type,
                      const std::string &    version,
                      BackendFactoryFunction factory_fn)
{
    init_registrar_if_needed();

    SPDLOG_DEBUG("Registering backend {} with type {} and version {}", name, type, version);

    BackendInfo info;
    info.version = version;
    info.factory = std::move(factory_fn);

    if (!semver::valid(version))
    {
        NEUROPOD_ERROR("Tried registering backend {} with type {} and version {}, but the specified version is not a "
                       "valid semver version. See https://semver.org/ for more details.",
                       name,
                       type,
                       version);
    }

    // Check to see if we've already loaded a backend for `type`
    // We can only load one backend version per type into the same process
    // (i.e. if we load TF 1.12.0, we can't load another version of TF into this process)
    // Using OPE overcomes this problem
    if (registered_backends_by_type->find(type) != registered_backends_by_type->end())
    {
        NEUROPOD_ERROR(
            "Attempted to register a backend for type '{}', but one was already loaded. If you are trying "
            "to use multiple versions of the same framework, you must use OPE. See the docs at https://neuropod.ai",
            type);
    }

    registered_backends_by_type->insert(std::make_pair(type, info));

    return true;
}