Skip to content
Snippets Groups Projects
Select Git revision
  • fb9eb280f29b197a159bbd858ddc91fc158d9051
  • main default protected
  • ud_training_script
  • fix_seed
  • merged-with-ner
  • multiword_fix_transformer
  • transformer_encoder
  • combo3
  • save_deprel_matrix_to_npz
  • master protected
  • combo-lambo
  • lambo-sent-attributes
  • adding_lambo
  • develop
  • update_allenlp2
  • develop_tmp
  • tokens_truncation
  • LR_test
  • eud_iwpt
  • iob
  • eud_iwpt_shared_task_bert_finetuning
  • 3.3.1
  • list
  • 3.2.1
  • 3.0.3
  • 3.0.1
  • 3.0.0
  • v1.0.6
  • v1.0.5
  • v1.0.4
  • v1.0.3
  • v1.0.2
  • v1.0.1
  • v1.0.0
34 results

test_samplers.py

Blame
  • plugin.cpp 1.93 KiB
    #include <libpwrutils/plugin.h>
    #include <dlfcn.h>
    #include <iostream>
    
    namespace PwrNlp {
    namespace Plugin {
    
    std::string make_soname(const std::string &scope, const std::string &name)
    {
    	if (name.size() > 1 && name.find('/') != name.npos) {
    		return name;
    	} else {
    		return "lib" + scope + "_" + name + ".so";
    	}
    }
    
    bool load(const std::string &scope, const std::string &name, bool quiet)
    {
    	std::string soname = make_soname(scope, name);
    	// std::cerr << "PLUGIN LOAD " << scope << " " << name << " " << soname << "\n";
    	// first check if the plugin was already loaded
    	void* handle = dlopen(soname.c_str(), RTLD_NOW | RTLD_NOLOAD);
    	if (handle != NULL) {
    		if (!quiet) {
    			std::cerr << "Warning: " << scope << " plugin '" << name
    				<< "'' already loaded\n";
    		}
    		return false;
    	}
    	// actually load the library
    	dlerror();
    	handle = dlopen(soname.c_str(), RTLD_NOW);
    	if (handle == NULL) {
    		if (!quiet) {
    			const char* dle = dlerror();
    			std::cerr << "Error: dlopen error while loading " << scope
    				<< " plugin '" << name << "' (" << soname << "): ";
    			if (dle != NULL) {
    				std::cerr << dle << "\n";
    			}
    		}
    		return false;
    	}
    	// run plugin init function if it exists
    	typedef void (*init_func_t)();
    	init_func_t init_func = reinterpret_cast<init_func_t>(
    			dlsym(handle, "pwrnlp_plugin_init"));
    	if (init_func) {
    		init_func();
    	}
    	if (!quiet) {
    		std::cerr << "Loaded " << scope << " plugin '" << name << "'\n";
    	}
    	return true;
    }
    
    bool load_check(const std::string &scope, const std::string &name, bool quiet,
    		boost::function<size_t (void)> counter, const std::string &what)
    {
    	size_t before = counter();
    	if (load(scope, name, quiet)) {
    		size_t after = counter();
    		if (after <= before) {
    			if (!quiet) {
    				std::cerr << "Warning: " << scope << " plugin '"
    					<< name << "'' loaded, but"
    					<< what << " count did not increase\n";
    			}
    			return false;
    		}
    		return true;
    	} else {
    		return false;
    	}
    }
    
    } /* end ns Plugin */
    } /* end ns PwrNlp */