Code quality: safer getenv on windows
This commit is contained in:
@@ -31,7 +31,10 @@ public:
|
||||
static void release();
|
||||
static ProgramCache & get(CommandQueue const & queue, expression_type expression, numeric_type dtype);
|
||||
private:
|
||||
DISABLE_MSVC_WARNING_C4251
|
||||
static std::map<std::tuple<CommandQueue, expression_type, numeric_type>, ProgramCache * > cache_;
|
||||
RESTORE_MSVC_WARNING_C4251
|
||||
|
||||
};
|
||||
|
||||
class contexts
|
||||
@@ -45,7 +48,9 @@ public:
|
||||
static Context const & import(cl_context context);
|
||||
static void get(std::list<Context const *> &);
|
||||
private:
|
||||
DISABLE_MSVC_WARNING_C4251
|
||||
static std::list<Context const *> cache_;
|
||||
RESTORE_MSVC_WARNING_C4251
|
||||
};
|
||||
|
||||
class queues
|
||||
@@ -58,7 +63,9 @@ public:
|
||||
static void get(Context const &, std::vector<CommandQueue *> &queues);
|
||||
static CommandQueue & get(Context const &, unsigned int id);
|
||||
private:
|
||||
DISABLE_MSVC_WARNING_C4251
|
||||
static std::map< Context, std::vector<CommandQueue*> > cache_;
|
||||
RESTORE_MSVC_WARNING_C4251
|
||||
};
|
||||
|
||||
static void init();
|
||||
|
@@ -20,6 +20,8 @@ class ISAACAPI Context
|
||||
friend class CommandQueue;
|
||||
friend class Buffer;
|
||||
|
||||
private:
|
||||
void init_cache_path();
|
||||
|
||||
public:
|
||||
explicit Context(cl_context const & context, bool take_ownership = true);
|
||||
@@ -32,11 +34,12 @@ public:
|
||||
|
||||
HANDLE_TYPE(cl_context, CUcontext) const & handle() const { return h_; }
|
||||
private:
|
||||
DISABLE_MSVC_WARNING_C4251
|
||||
backend_type backend_;
|
||||
Device device_;
|
||||
|
||||
std::string cache_path_;
|
||||
HANDLE_TYPE(cl_context, CUcontext) h_;
|
||||
RESTORE_MSVC_WARNING_C4251
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -23,10 +23,12 @@ public:
|
||||
Program(Context const & context, std::string const & source);
|
||||
Context const & context() const;
|
||||
private:
|
||||
DISABLE_MSVC_WARNING_C4251
|
||||
backend_type backend_;
|
||||
Context context_;
|
||||
std::string source_;
|
||||
HANDLE_TYPE(cl_program, CUmodule) h_;
|
||||
RESTORE_MSVC_WARNING_C4251
|
||||
};
|
||||
|
||||
|
||||
|
@@ -19,7 +19,9 @@ public:
|
||||
Program & add(Context const & context, std::string const & name, std::string const & src);
|
||||
Program const *find(std::string const & name);
|
||||
private:
|
||||
DISABLE_MSVC_WARNING_C4251
|
||||
std::map<std::string, Program> cache_;
|
||||
RESTORE_MSVC_WARNING_C4251
|
||||
};
|
||||
|
||||
|
||||
|
@@ -4,10 +4,13 @@
|
||||
#include <string>
|
||||
#include <exception>
|
||||
|
||||
#include "isaac/defines.h"
|
||||
|
||||
namespace isaac
|
||||
{
|
||||
|
||||
/** @brief Exception for the case the generator is unable to deal with the operation */
|
||||
DISABLE_MSVC_WARNING_C4275
|
||||
class operation_not_supported_exception : public std::exception
|
||||
{
|
||||
public:
|
||||
@@ -16,8 +19,11 @@ public:
|
||||
virtual const char* what() const throw();
|
||||
virtual ~operation_not_supported_exception() throw();
|
||||
private:
|
||||
DISABLE_MSVC_WARNING_C4251
|
||||
std::string message_;
|
||||
RESTORE_MSVC_WARNING_C4251
|
||||
};
|
||||
RESTORE_MSVC_WARNING_C4275
|
||||
|
||||
}
|
||||
|
||||
|
@@ -9,6 +9,7 @@ namespace isaac
|
||||
{
|
||||
|
||||
/** @brief Exception for the case the generator is unable to deal with the operation */
|
||||
DISABLE_MSVC_WARNING_C4275
|
||||
class ISAACAPI unknown_datatype : public std::exception
|
||||
{
|
||||
public:
|
||||
@@ -16,8 +17,11 @@ public:
|
||||
virtual const char* what() const throw();
|
||||
virtual ~unknown_datatype() throw();
|
||||
private:
|
||||
DISABLE_MSVC_WARNING_C4251
|
||||
std::string message_;
|
||||
RESTORE_MSVC_WARNING_C4251
|
||||
};
|
||||
RESTORE_MSVC_WARNING_C4275
|
||||
|
||||
}
|
||||
|
||||
|
34
include/isaac/tools/getenv.hpp
Normal file
34
include/isaac/tools/getenv.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef ISAAC_TOOLS_GETENV
|
||||
#define ISAAC_TOOLS_GETENV
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace isaac
|
||||
{
|
||||
|
||||
namespace tools
|
||||
{
|
||||
|
||||
inline std::string getenv(const char * name)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
char* cache_path = 0;
|
||||
std::size_t sz = 0;
|
||||
_dupenv_s(&cache_path, &sz, name);
|
||||
#else
|
||||
const char * cache_path = std::getenv(name);
|
||||
#endif
|
||||
if(!cache_path)
|
||||
return "";
|
||||
std::string result(cache_path);
|
||||
#ifdef _MSC_VER
|
||||
free(cache_path);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@@ -2,34 +2,40 @@
|
||||
#include "isaac/driver/context.h"
|
||||
#include "helpers/ocl/infos.hpp"
|
||||
#include "isaac/driver/program.h"
|
||||
#include "isaac/tools/getenv.hpp"
|
||||
|
||||
namespace isaac
|
||||
{
|
||||
|
||||
namespace driver
|
||||
{
|
||||
|
||||
Context::Context(cl_context const & context, bool take_ownership) : backend_(OPENCL), device_(ocl::info<CL_CONTEXT_DEVICES>(context)[0], false), h_(backend_, take_ownership)
|
||||
void Context::init_cache_path()
|
||||
{
|
||||
h_.cl() = context;
|
||||
|
||||
#ifndef ANDROID
|
||||
if (std::getenv("ISAAC_CACHE_PATH"))
|
||||
cache_path_ = std::getenv("ISAAC_CACHE_PATH");
|
||||
#ifdef _MSC_VER
|
||||
char* cache_path = 0;
|
||||
std::size_t sz = 0;
|
||||
_dupenv_s(&cache_path, &sz, "ISAAC_CACHE_PATH");
|
||||
#else
|
||||
const char * cache_path = std::getenv("ISAAC_CACHE_PATH");
|
||||
#endif
|
||||
if (cache_path)
|
||||
cache_path_ = cache_path;
|
||||
else
|
||||
#endif
|
||||
cache_path_ = "";
|
||||
|
||||
}
|
||||
|
||||
Context::Context(Device const & device) : backend_(device.backend_), device_(device), h_(backend_, true)
|
||||
Context::Context(cl_context const & context, bool take_ownership) : backend_(OPENCL), device_(ocl::info<CL_CONTEXT_DEVICES>(context)[0], false), cache_path_(tools::getenv("ISAAC_CACHE_PATH")), h_(backend_, take_ownership)
|
||||
{
|
||||
#ifndef ANDROID
|
||||
if (std::getenv("ISAAC_CACHE_PATH"))
|
||||
cache_path_ = std::getenv("ISAAC_CACHE_PATH");
|
||||
else
|
||||
#endif
|
||||
cache_path_ = "";
|
||||
init_cache_path();
|
||||
h_.cl() = context;
|
||||
}
|
||||
|
||||
Context::Context(Device const & device) : backend_(device.backend_), device_(device), cache_path_(tools::getenv("ISAAC_CACHE_PATH")), h_(backend_, true)
|
||||
{
|
||||
init_cache_path();
|
||||
switch(backend_)
|
||||
{
|
||||
#ifdef ISAAC_WITH_CUDA
|
||||
|
@@ -18,6 +18,8 @@
|
||||
#include "isaac/model/model.h"
|
||||
#include "isaac/tools/make_vector.hpp"
|
||||
#include "isaac/tools/timer.hpp"
|
||||
#include "isaac/tools/getenv.hpp"
|
||||
|
||||
#include "convert.hpp"
|
||||
|
||||
|
||||
@@ -249,8 +251,9 @@ models::map_type& models::init(driver::CommandQueue const & queue)
|
||||
for(expression_type etype: etypes)
|
||||
result[std::make_pair(etype, dtype)] = std::shared_ptr<model>(new model(etype, dtype, *fallbacks[std::make_pair(etype, dtype)], queue));
|
||||
|
||||
if(const char * homepath = std::getenv("HOME"))
|
||||
import(std::string(homepath) + "/.isaac/devices/device0.json", queue);
|
||||
std::string homepath = tools::getenv("HOME");
|
||||
if(homepath.size())
|
||||
import(homepath + "/.isaac/devices/device0.json", queue);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@@ -61,7 +61,7 @@ def main():
|
||||
def find_opencl():
|
||||
cvars = sysconfig.get_config_vars()
|
||||
is_on_android = '-mandroid' in cvars['PY_CFLAGS']
|
||||
lib = find_library('OpenCL', '/opt/adreno-driver*/lib' if is_on_android else '/opt/AMDAPPSDK*/lib/x86_64')
|
||||
lib = find_library('OpenCL', '' if is_on_android else '/opt/AMDAPPSDK*/lib/x86_64')
|
||||
return {'include': '', 'lib': dirname(lib)} if lib else None
|
||||
|
||||
def find_in_path(name, path):
|
||||
@@ -115,7 +115,7 @@ def main():
|
||||
include =' src/include'.split() + ['external/boost/include', os.path.join(find_module("numpy")[1], "core", "include")]
|
||||
|
||||
#Source files
|
||||
src = 'src/lib/array.cpp src/lib/wrap/clBLAS.cpp src/lib/value_scalar.cpp src/lib/symbolic/preset.cpp src/lib/symbolic/expression.cpp src/lib/symbolic/execute.cpp src/lib/symbolic/io.cpp src/lib/model/model.cpp src/lib/model/predictors/random_forest.cpp src/lib/exception/unknown_datatype.cpp src/lib/exception/operation_not_supported.cpp src/lib/driver/program.cpp src/lib/driver/context.cpp src/lib/driver/command_queue.cpp src/lib/driver/check.cpp src/lib/driver/buffer.cpp src/lib/driver/event.cpp src/lib/driver/device.cpp src/lib/driver/backend.cpp src/lib/driver/platform.cpp src/lib/driver/ndrange.cpp src/lib/driver/kernel.cpp src/lib/driver/handle.cpp src/lib/backend/parse.cpp src/lib/backend/templates/reduction.cpp src/lib/backend/templates/mreduction.cpp src/lib/backend/templates/mproduct.cpp src/lib/backend/templates/maxpy.cpp src/lib/backend/templates/vaxpy.cpp src/lib/backend/templates/base.cpp src/lib/backend/stream.cpp src/lib/backend/mapped_object.cpp src/lib/backend/keywords.cpp src/lib/backend/binder.cpp '.split() + [os.path.join('src', 'wrap', sf) for sf in ['_isaac.cpp', 'core.cpp', 'driver.cpp', 'model.cpp', 'exceptions.cpp']]
|
||||
src = 'src/lib/wrap/clBLAS.cpp src/lib/value_scalar.cpp src/lib/kernels/parse.cpp src/lib/kernels/templates/base.cpp src/lib/kernels/templates/ger.cpp src/lib/kernels/templates/gemv.cpp src/lib/kernels/templates/gemm.cpp src/lib/kernels/templates/dot.cpp src/lib/kernels/templates/axpy.cpp src/lib/kernels/stream.cpp src/lib/kernels/mapped_object.cpp src/lib/kernels/keywords.cpp src/lib/kernels/binder.cpp src/lib/array.cpp src/lib/symbolic/preset.cpp src/lib/symbolic/expression.cpp src/lib/symbolic/execute.cpp src/lib/symbolic/io.cpp src/lib/model/model.cpp src/lib/model/predictors/random_forest.cpp src/lib/exception/unknown_datatype.cpp src/lib/exception/operation_not_supported.cpp src/lib/driver/context.cpp src/lib/driver/program_cache.cpp src/lib/driver/program.cpp src/lib/driver/platform.cpp src/lib/driver/ndrange.cpp src/lib/driver/kernel.cpp src/lib/driver/handle.cpp src/lib/driver/event.cpp src/lib/driver/device.cpp src/lib/driver/command_queue.cpp src/lib/driver/check.cpp src/lib/driver/buffer.cpp src/lib/driver/backend.cpp '.split() + [os.path.join('src', 'wrap', sf) for sf in ['_isaac.cpp', 'core.cpp', 'driver.cpp', 'model.cpp', 'exceptions.cpp']]
|
||||
boostsrc = 'external/boost/libs/'
|
||||
for s in ['numpy','python','smart_ptr','system','thread']:
|
||||
src = src + [x for x in recursive_glob('external/boost/libs/' + s + '/src/','.cpp') if 'win32' not in x and 'pthread' not in x]
|
||||
|
Reference in New Issue
Block a user