55 :
cmd(
"missing"), flags(
"missing"), lang(
"missing"), out(
"-o "), temp(
detectTemp())
58 env = getenv (
"JIT_COMPILER_CMD");
59 if(env!=NULL)
cmd = env;
61 env = getenv (
"JIT_COMPILER_FLAGS");
62 if(env!=NULL) flags = env;
64 env = getenv (
"JIT_COMPILER_LANG");
65 if(env!=NULL) lang = env;
67 env = getenv (
"JIT_COMPILER_TEMP");
68 if(env!=NULL) temp = env;
75 const std::string& flags,
76 const std::string& lang,
77 const std::string& out,
79 : cmd(cmd), flags(flags), lang(lang), out(out), temp(temp)
84 std::swap(cmd , other.
cmd );
85 std::swap(flags, other.flags);
86 std::swap(lang , other.lang );
87 std::swap(out , other.out );
88 std::swap(temp , other.temp );
91 # if __cplusplus >= 201103L || _MSC_VER >= 1600
110 : cmd(std::move(other.cmd)), flags(std::move(other.flags)),
111 lang(std::move(other.lang)), out(std::move(other.out)),
112 temp(std::move(other.temp))
118 cmd = std::move(other.cmd);
119 flags = std::move(other.flags);
120 lang = std::move(other.lang);
121 out = std::move(other.out);
122 temp = std::move(other.temp);
135 virtual const std::string&
getCmd()
const {
return cmd; }
138 virtual const std::string&
getFlags()
const {
return flags; }
141 virtual const std::string&
getLang()
const {
return lang; }
144 virtual const std::string&
getOut()
const {
return out; }
147 virtual const std::string&
getTemp()
const {
return temp; }
151 { this->cmd = _cmd; }
155 { this->flags = _flags; }
159 { this->lang = _lang; }
163 { this->out = _out; }
167 { this->temp = _temp; }
170 std::ostream&
print(std::ostream &os)
const
172 os <<
"JIT Compiler.\n"
173 <<
" cmd: " << cmd <<
"\n"
174 <<
" flags: " << flags <<
"\n"
175 <<
" language: " << lang <<
"\n"
176 <<
" output flag: " << out <<
"\n"
177 <<
" temporal directory: " << temp <<
"\n";
183 void load(
const std::string filename,
187 "Error: Invalid compiler language.");
192 std::swap(*cc, *
this);
193 if (this->temp.empty()) this->temp=
detectTemp();
204 std::swap(*cc, *
this);
205 if (this->temp.empty()) this->temp=
detectTemp();
227 GISMO_ERROR(
"Error : Clang does not provide any Fortran compiler.");
408 # if defined(__INTEL_COMPILER)
415 # elif defined(_MSC_VER)
418 # elif defined(__clang__)
421 # elif defined(__GNUC__)
422 # if defined(__cplusplus)
424 # elif defined(__GFortran__)
430 # elif defined(__PGIC__)
433 # elif defined(__SUNPRO_C)
435 # elif defined(__SUNPRO_CC)
437 # elif defined(__SUNPRO_F90) || defined(__SUNPRO_F95)
463 inline std::ostream &operator<<(std::ostream &os,
465 {
return c.
print(os); }
474 class gsXml< gsJITCompilerConfig >
480 GSXML_COMMON_FUNCTIONS(gsJITCompilerConfig)
481 GSXML_GET_POINTER(gsJITCompilerConfig)
482 static std::
string tag () {
return "JITCompilerConfig"; }
483 static std::string type() {
return ""; }
485 static void get_into(gsXmlNode * node, gsJITCompilerConfig & result)
487 gsXmlAttribute * tmp = node->first_attribute(
"cmd");
489 result.setCmd(tmp->value());
491 tmp = node->first_attribute(
"flags");
493 result.setFlags(tmp->value());
495 tmp = node->first_attribute(
"lang");
497 result.setLang(tmp->value());
499 tmp = node->first_attribute(
"out");
501 result.setOut(tmp->value());
503 tmp = node->first_attribute(
"temp");
505 result.setTemp(tmp->value());
508 static gsXmlNode * put (
const gsJITCompilerConfig & obj, gsXmlTree & data)
514 tmp->append_attribute(
makeAttribute(
"cmd" , obj.getCmd() , data) );
515 tmp->append_attribute(
makeAttribute(
"flags", obj.getFlags(), data) );
516 tmp->append_attribute(
makeAttribute(
"lang" , obj.getLang() , data) );
517 tmp->append_attribute(
makeAttribute(
"out" , obj.getOut() , data) );
518 tmp->append_attribute(
makeAttribute(
"temp" , obj.getTemp() , data) );
541 gsDebug <<
"Loading dynamic library: " << filename <<
"\n";
545 HMODULE dl = LoadLibrary(filename);
548 std::ostringstream err;
549 err <<
"LoadLibrary - error: " << GetLastError();
550 throw std::runtime_error( err.str() );
552 handle.reset(dl, FreeLibrary);
553 #elif defined(__APPLE__) || defined(__linux__) || defined(__unix)
554 void * dl = ::dlopen(filename, flag);
556 throw std::runtime_error( ::dlerror() );
557 handle.reset(dl, ::dlclose);
559 #error("Unsupported operating system")
568 throw std::runtime_error(
"An error occured while accessing the dynamic library");
572 *(
void **)(&symbol) = (
void*)GetProcAddress(
handle.get(), name );
573 #elif defined(__APPLE__) || defined(__linux__) || defined(__unix)
574 *(
void **)(&symbol) = ::dlsym(
handle.get(), name );
577 throw std::runtime_error(
"An error occured while getting symbol from the dynamic library");
583 operator bool()
const {
return (
bool)
handle; }
589 memory::shared_ptr< util::remove_pointer<HMODULE>::type >
handle;
590 #else //if defined(__APPLE__) || defined(__linux__) || defined(__unix)
620 :
kernel(), config(config)
631 # if __cplusplus >= 201103L || _MSC_VER >= 1600
637 kernel << other.kernel.rdbuf();
643 kernel << other.kernel.rdbuf();
644 config = std::move(other.config);
667 # if __cplusplus >= 201103L || _MSC_VER >= 1600
668 size_t h = std::hash<std::string>()(
getKernel().str() +
673 return build(
"JIT",
true);
682 std::stringstream libName;
688 # elif defined(__APPLE__)
690 # elif defined(unix) || defined(__unix__) || defined(__unix)
693 # error("Unsupported operating system")
697 std::ifstream libfile(libName.str().c_str());
698 if(!libfile || force)
701 std::stringstream srcName;
704 std::ofstream file(srcName.str().c_str());
705 file <<
"#ifdef __cplusplus\n";
706 file <<
"#define EXPORT extern \"C\" __declspec(dllexport)\n";
710 std::ofstream file(srcName.str().c_str());
711 file <<
"#ifdef __cplusplus\n";
712 file <<
"#define EXPORT extern \"C\"\n";
719 std::stringstream systemcall;
725 << srcName.str() <<
"\" "
730 << srcName.str() <<
"\" "
734 gsDebug <<
"Compiling dynamic library: " << systemcall.str() <<
"\n";
735 if(std::system(systemcall.str().c_str()) != 0)
736 throw std::runtime_error(
"An error occured while compiling the kernel source code");
750 kernel.str(std::string());
754 std::ostream&
print(std::ostream &os)
const
782 {
return c.
print(os); }
791 class gsXml< gsJITCompiler >
797 GSXML_COMMON_FUNCTIONS(gsJITCompiler)
798 GSXML_GET_POINTER(gsJITCompiler)
799 static std::
string tag () {
return "JITCompiler"; }
800 static std::string type() {
return ""; }
802 static void get_into(gsXmlNode * node, gsJITCompiler & result)
804 result.getKernel() << node->value();
807 static gsXmlNode * put (
const gsJITCompiler & obj, gsXmlTree & data)
std::ostringstream & getKernel()
Return pointer to kernel source code.
Definition: gsJITCompiler.h:767
static gsJITCompilerConfig sunstudio(const int lang=gsJITLang::CXX)
Initialize to default Oracle/SunStudio compiler.
Definition: gsJITCompiler.h:378
std::string cmd
Members variables.
Definition: gsJITCompiler.h:447
std::vector< T * > release(std::vector< unique_ptr< T > > &cont)
Takes a vector of smart pointers, releases them and returns the corresponding raw pointers...
Definition: gsMemory.h:228
Struct definig a compiler configuration.
Definition: gsJITCompiler.h:51
gsDynamicLibrary(const char *filename, int flag)
Constructor (using file name)
Definition: gsJITCompiler.h:539
#define gsDebug
Definition: gsDebug.h:61
gsJITCompilerConfig()
Constructor (default)
Definition: gsJITCompiler.h:54
void setCmd(const std::string &_cmd)
Set compiler command.
Definition: gsJITCompiler.h:150
static std::string getTempPath()
Auto-detect temp directory.
Definition: gsFileManager.cpp:355
memory::unique_ptr< Object > getId(const int &id) const
Searches and fetches the Gismo object with a given id.
Definition: gsFileData.h:180
C.
Definition: gsJITCompiler.h:38
Fortran.
Definition: gsJITCompiler.h:41
gsJITCompiler(gsJITCompiler const &other)
Constructor (copy)
Definition: gsJITCompiler.h:612
static gsJITCompilerConfig guess()
Try to initialize compiler automatically based on the context.
Definition: gsJITCompiler.h:406
gsJITCompiler()
Constructor (default)
Definition: gsJITCompiler.h:607
#define GISMO_ENSURE(cond, message)
Definition: gsDebug.h:102
static gsJITCompilerConfig clang(const int lang=gsJITLang::CXX)
Initialize to default Clang compiler.
Definition: gsJITCompiler.h:210
gsDynamicLibrary build(const std::string &name, bool force=false)
Definition: gsJITCompiler.h:679
Provides utility function related to memory management.
void setOut(const std::string &_out)
Set compiler output flag.
Definition: gsJITCompiler.h:162
virtual const std::string & getCmd() const
Return compiler command.
Definition: gsJITCompiler.h:135
static gsJITCompilerConfig msvc(const int lang=gsJITLang::CXX)
Initialize to default Microsoft Visual Studio compiler.
Definition: gsJITCompiler.h:312
void setFlags(const std::string &_flags)
Set compiler flags.
Definition: gsJITCompiler.h:154
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsJITCompiler.h:754
T * getSymbol(const char *name) const
Get symbol from dynamic library.
Definition: gsJITCompiler.h:565
virtual const std::string & getFlags() const
Return compiler flags.
Definition: gsJITCompiler.h:138
std::string to_string(const unsigned &i)
Helper to convert small unsigned to string.
Definition: gsXml.cpp:74
std::ostringstream kernel
Kernel source code.
Definition: gsJITCompiler.h:774
Supported languages.
Definition: gsJITCompiler.h:35
void setTemp(const std::string &_temp)
Set compiler temporal directory.
Definition: gsJITCompiler.h:166
static gsJITCompilerConfig intel(const int lang=gsJITLang::CXX)
Initialize to default Intel compiler.
Definition: gsJITCompiler.h:263
static gsJITCompilerConfig pgi(const int lang=gsJITLang::CXX)
Initialize to default PGI compiler.
Definition: gsJITCompiler.h:350
gsDynamicLibrary build(bool force=false)
Definition: gsJITCompiler.h:665
C++.
Definition: gsJITCompiler.h:39
gsXmlAttribute * makeAttribute(const std::string &name, const std::string &value, gsXmlTree &data)
Helper to allocate XML attribute.
Definition: gsXml.cpp:37
gsJITCompiler & operator<<(std::istream &is)
Input kernel source code from input stream.
Definition: gsJITCompiler.h:657
gsXmlNode * makeNode(const std::string &name, gsXmlTree &data)
Helper to allocate XML node.
Definition: gsXml.cpp:54
virtual const std::string & getLang() const
Return compiler language.
Definition: gsJITCompiler.h:141
gsJITCompilerConfig(const std::string &cmd, const std::string &flags, const std::string &lang, const std::string &out, const std::string &temp=detectTemp())
Constructor (passing arguments as strings)
Definition: gsJITCompiler.h:74
const std::ostringstream & getKernel() const
Return kernel source code (as output stringstream)
Definition: gsJITCompiler.h:761
static std::string detectTemp()
Auto-detect temp directory.
Definition: gsJITCompiler.h:456
void load_id(const std::string filename, const int id)
Reads compiler configuration from XML file by ID.
Definition: gsJITCompiler.h:198
void clear()
Clear kernel source code.
Definition: gsJITCompiler.h:747
gsJITCompiler & operator=(gsJITCompiler const &other)
Assignment operator (copy)
Definition: gsJITCompiler.h:624
static gsJITCompilerConfig gcc(const int lang=gsJITLang::CXX)
Initialize to default GCC compiler.
Definition: gsJITCompiler.h:235
virtual const std::string & getTemp() const
Return compiler temporal directory.
Definition: gsJITCompiler.h:147
#define GISMO_UNUSED(x)
Definition: gsDebug.h:112
gsJITCompilerConfig & operator=(gsJITCompilerConfig other)
Assignment operator.
Definition: gsJITCompiler.h:127
void load(const std::string filename, const int _lang=gsJITLang::CXX)
Reads compiler configuration from XML file by language.
Definition: gsJITCompiler.h:183
gsJITCompilerConfig config
Compiler configuration.
Definition: gsJITCompiler.h:777
Utility class for finding files and handling paths.
Class defining a dynamic library.
Definition: gsJITCompiler.h:532
EIGEN_STRONG_INLINE idMat_expr id(const index_t dim)
The identity matrix of dimension dim.
Definition: gsExpressions.h:4470
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
gsJITCompiler & operator<<(const std::string &s)
Input kernel source code from string.
Definition: gsJITCompiler.h:650
void setLang(const std::string &_lang)
Set compiler language.
Definition: gsJITCompiler.h:158
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsJITCompiler.h:170
memory::shared_ptr< void > handle
Handle to dynamic library object.
Definition: gsJITCompiler.h:591
static gsJITCompilerConfig nvcc(const int lang=gsJITLang::CUDA)
Initialize to default NVIDIA nvcc compiler.
Definition: gsJITCompiler.h:334
Cuda.
Definition: gsJITCompiler.h:40
gsDynamicLibrary()
Default Constructor.
Definition: gsJITCompiler.h:536
This class represents an XML data tree which can be read from or written to a (file) stream...
Definition: gsFileData.h:33
Class defining a just-in-time compiler.
Definition: gsJITCompiler.h:603
gsJITCompiler(const gsJITCompilerConfig &config)
Constructor (using compiler configuration)
Definition: gsJITCompiler.h:619
Provides declaration of input/output XML utilities struct.
virtual const std::string & getOut() const
Return compiler output flag.
Definition: gsJITCompiler.h:144