ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
ETISSInit.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2//
3// This file is part of ETISS. It is licensed under the BSD 3-Clause License; you may not use this file except in
4// compliance with the License. You should have received a copy of the license along with this project. If not, see the
5// LICENSE file.
15#include "etiss/ETISS.h"
16#include "etiss/config.h"
17
18#include <cstdlib>
19#include <fstream>
20#include <sstream>
21#include <string>
22#include <vector>
23
24#include <boost/filesystem.hpp>
25
26namespace etiss
27{
28
29std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems)
30{
31 std::stringstream ss(s);
32 std::string item;
33 while (std::getline(ss, item, delim))
34 {
35 elems.push_back(item);
36 }
37 return elems;
38}
39
40} // namespace etiss
41
76static bool loadLibraryList(const std::string &path)
77{
78 std::string list_file = (path + "/list.txt");
79 std::ifstream lcfg(list_file.c_str());
80 if (!lcfg)
81 {
82 etiss::log(etiss::ERROR, std::string("Failed to open library list file: ") + list_file);
83 return false;
84 }
85
86 bool ret = false;
87 std::string line;
88 while (std::getline(lcfg, line))
89 {
90 if (line.find(',') == std::string::npos)
91 { // relative path
92 if (etiss::loadLibrary(path, line))
93 ret = true;
94 }
95 else
96 { // absolute path
97 std::vector<std::string> def;
98 etiss::split(line, ',', def);
99 if (def.size() == 3)
100 {
101 if (def[0] == def[2] && def[1].length() > 0 && def[2].length() > 0)
102 {
103 if (etiss::loadLibrary(def[1], def[2]))
104 ret = true;
105 }
106 else
107 {
108 etiss::log(etiss::ERROR, "Invalid line in plugin list file", line);
109 }
110 }
111 else
112 {
113 etiss::log(etiss::ERROR, "Invalid line in plugin list file", line);
114 }
115 }
116 }
117 return ret;
118}
119
131static void findLibs(const boost::filesystem::path &path, std::vector<std::string> &libs)
132{
133 if (boost::filesystem::exists(path) && boost::filesystem::is_directory(path))
134 {
135 boost::filesystem::recursive_directory_iterator end_itr;
136 for (boost::filesystem::recursive_directory_iterator itr(path); itr != end_itr; ++itr)
137 {
138 if (boost::filesystem::is_regular_file(itr->status()))
139 {
140 std::string name(itr->path().filename().string());
141 if (name.compare(0, 3, "lib") == 0 && name.compare(name.length() - 3, 3, ".so") == 0)
142 {
143 libs.push_back(itr->path().string());
144 }
145 }
146 }
147 }
148}
149
153
155{
156
157 // only allow to execute preloadLibraries() ones
159 {
160 return;
161 }
162 else
163 {
165 }
166
167 // load libraries
168 loadLibraryList(installDir() + "/lib/plugins");
169
170 // load libraries from user folder
171 std::string etiss_path = etiss::cfg().get<std::string>("etiss_wd", ".");
172 std::vector<std::string> lib_dirs{ std::string("ArchImpl"), std::string("JITImpl"), std::string("PluginImpl") };
173 if (!etiss_path.empty())
174 {
175 std::vector<std::string> libs;
176 for (auto itr = lib_dirs.begin(); itr != lib_dirs.end(); ++itr)
177 {
178 findLibs(boost::filesystem::path(etiss_path) / *itr, libs);
179 }
180 for (auto itr = libs.begin(); itr != libs.end(); ++itr)
181 {
182 size_t path_end = itr->rfind('/');
183 etiss::loadLibrary(itr->substr(0, path_end), itr->substr(path_end + 4, itr->length() - path_end - 7));
184 }
185 }
186}
bool etiss_preload_libraries
This flag indicate whether the preloading of the libraries has been executed or not.
static void findLibs(const boost::filesystem::path &path, std::vector< std::string > &libs)
Find all dynamically linked libraries in a folder and its subfolders.
static bool loadLibraryList(const std::string &path)
Load libraries specified in a list.txt file.
Definition ETISSInit.cpp:76
Header file of the ETISS library.
__device__ __2f16 float bool s
T get(const std::string &key, T default_, bool *default_used=0)
template function to read the value of a configuration key.
Definition Misc.h:312
contains defines to configure ETISS.
bool loadLibrary(std::string path, std::string name)
Load a library.
Definition ETISS.cpp:270
void preloadLibraries()
Search and try to load libraries.
forwards: include/jit/*
Definition Benchmark.h:17
std::list< std::string > split(const std::string &str, std::function< size_t(const std::string &, size_t, size_t &)> findsplit)
Definition Misc.cpp:54
std::string installDir()
Get ETISS installation directory.
Definition Misc.cpp:554
@ ERROR
Definition Misc.h:85
Configuration & cfg()
Definition Misc.cpp:548
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition Misc.cpp:94
float __ovld __cnfn length(float p)
Return the length of vector p, i.e., sqrt(p.x2 + p.y 2 + ...)