12#include <nv/index/iindex.h>
20#ifndef MI_PLATFORM_WINDOWS
35#define check_success(expr) \
37 fprintf(stderr, "Error in file %s, line %d: \"%s\".\n", __FILE__, __LINE__, #expr); \
38 exit(EXIT_FAILURE); } }
42static std::string G_nvindexlib_fname;
43static void * G_p_handle = 0;
54 const std::string& message,
55 std::map< std::string, std::string >& opt_map)
57 if(opt_map.find(
"dice::verbose") == opt_map.end())
60 std::cout <<
"info: " << message << std::endl;
64 std::string lv = opt_map[
"dice::verbose"];
65 if((lv ==
"0") || (lv ==
"1") || (lv ==
"2")){
68 std::cout <<
"info: " << message << std::endl;
77nv::index::IIndex* load_and_get_iindex(
const std::string & nvindexlib_fname)
79#ifdef MI_PLATFORM_WINDOWS
80 G_p_handle = LoadLibrary(TEXT(nvindexlib_fname.c_str()));
83 printf(
"error: Could not retrieve a handle to the %s library\n", nvindexlib_fname.c_str());
86 void* symbol = GetProcAddress((HMODULE)G_p_handle,
"nv_factory");
89 printf(
"error: Could not retrieve the entry point into the %s library\n", nvindexlib_fname.c_str());
93 G_p_handle = dlopen(nvindexlib_fname.c_str(),
RTLD_LAZY);
95 printf(
"error: iindex: handle: %s\n", dlerror());
99 void* symbol = dlsym(G_p_handle,
"nv_factory");
101 printf(
"error: iindex: symbol: %s\n", dlerror());
106 G_nvindexlib_fname = nvindexlib_fname;
108 return nv::index::nv_factory<nv::index::IIndex>(symbol);
115bool unload_iindex(std::map< std::string, std::string > & opt_map)
118#ifdef MI_PLATFORM_WINDOWS
119 if (FALSE == FreeLibrary((HMODULE)G_p_handle)) {
120 fprintf(stderr,
"error: unload_iindex.\n");
124 int result = dlclose(G_p_handle);
126 fprintf(stderr,
"error: unload_iindex: %s\n", dlerror());
145 virtual ~Nvindex_access()
156 bool is_initialized()
const
158 return m_nvindex_interface.is_valid_interface();
163 mi::base::Handle<nv::index::IIndex>& get_interface()
165 return m_nvindex_interface;
171 mi::Sint32 start_service()
174 m_nvindex_interface->start();
186 m_nvindex_interface = 0;
191 mi::base::Handle<nv::index::IIndex> m_nvindex_interface;
195bool Nvindex_access::load_library()
198 std::string lib_name =
"libnvindex";
210 m_nvindex_interface = load_and_get_iindex(lib_name);
218bool Nvindex_access::shutdown()
221 const mi::Sint32 nvi_shutdown = m_nvindex_interface->shutdown();
222 if(nvi_shutdown != 0){
223 fprintf(stderr,
"error: failed IndeX library shutdown (code: %d)\n", nvi_shutdown);
226 return nvi_shutdown == 0;
234int main(
int argc,
char* argv[])
236 const std::string com_name(argv[0]);
238 std::map< std::string, std::string > opt_map;
239 opt_map[
"dice::verbose"] =
"3";
240 opt_map[
"unittest"] =
"0";
242 if(opt_map[
"unittest"] ==
"1")
244 opt_map[
"dice::verbose"] =
"2";
246 info_cout(
"running " + com_name, opt_map);
249 Nvindex_access nvindex_accessor;
253 nvindex_accessor.start_service();
256 info_cout(
"NVIDIA IndeX version: " + std::string(nvindex_accessor.get_interface()->get_version()), opt_map);
258 const char* version = nvindex_accessor.get_interface()->get_dice_version();
260 info_cout(
"DiCE header API version = " + std::string(MI_NEURAYLIB_VERSION_QUALIFIED_STRING), opt_map);
261 info_cout(
"DiCE library build version string = \"" + std::string(version) +
"\".", opt_map);
267 nvindex_accessor.clear();
int main(int argc, char *argv[])
#define check_success(expr)