aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichalis Spyrou <michalis.spyrou@arm.com>2018-11-30 16:30:43 +0000
committerMichalis Spyrou <michalis.spyrou@arm.com>2018-12-03 13:47:53 +0000
commit323ce0f0b06bca785959913e75e1f51d383c351a (patch)
treedc3729e19a43d8290285987c51d9799581412c33
parent08a4517905da959b6e3401cc24f5e2018f9b51ac (diff)
downloadComputeLibrary-323ce0f0b06bca785959913e75e1f51d383c351a.tar.gz
COMPMID-1819 Add option to build library with -fno-exceptions
Change-Id: I3de6bb33746d52f8d8c337ab7776eccee8c205fb Reviewed-on: https://review.mlplatform.org/328 Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com> Reviewed-by: Pablo Marquez <pablo.tello@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com>
-rw-r--r--SConstruct13
-rw-r--r--arm_compute/core/Error.h6
-rw-r--r--arm_compute/core/utils/misc/Cast.h4
-rw-r--r--src/core/Error.cpp4
-rw-r--r--src/core/Utils.cpp4
-rw-r--r--src/graph/TypeLoader.cpp15
-rw-r--r--src/runtime/CPP/CPPScheduler.cpp11
-rw-r--r--src/runtime/MEMUtils.cpp4
8 files changed, 53 insertions, 8 deletions
diff --git a/SConstruct b/SConstruct
index 11fbd8b357..49b1d1765c 100644
--- a/SConstruct
+++ b/SConstruct
@@ -55,6 +55,7 @@ vars.AddVariables(
BoolVariable("cppthreads", "Enable C++11 threads backend", True),
PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept),
PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept),
+ BoolVariable("exceptions", "Enable/disable C++ exception support", True),
#FIXME Remove before release (And remove all references to INTERNAL_ONLY)
BoolVariable("internal_only", "Enable ARM internal only tests", False),
("extra_cxx_flags", "Extra CXX flags to be appended to the build command", ""),
@@ -118,6 +119,14 @@ if env['os'] == 'bare_metal':
print("ERROR: OpenMP and C++11 threads not supported in bare_metal. Use cppthreads=0 openmp=0")
Exit(1)
+if not env['exceptions']:
+ if env['opencl'] or env['gles_compute']:
+ print("ERROR: OpenCL and GLES are not supported when building without exceptions. Use opencl=0 gles_compute=0")
+ Exit(1)
+
+ env.Append(CPPDEFINES = ['ARM_COMPUTE_EXCEPTIONS_DISABLED'])
+ env.Append(CXXFLAGS = ['-fno-exceptions'])
+
env.Append(CXXFLAGS = ['-Wno-deprecated-declarations','-Wall','-DARCH_ARM',
'-Wextra','-Wno-unused-parameter','-pedantic','-Wdisabled-optimization','-Wformat=2',
'-Winit-self','-Wstrict-overflow=2','-Wswitch-default',
@@ -297,8 +306,8 @@ if env['gles_compute'] and env['os'] != 'android':
SConscript('./SConscript', variant_dir=build_path, duplicate=0)
-if env['examples'] and env['os'] != 'bare_metal':
+if env['examples'] and env['os'] != 'bare_metal' and env['exceptions']:
SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0)
-if env['os'] != 'bare_metal':
+if env['os'] != 'bare_metal' and env['exceptions']:
SConscript('./tests/SConscript', variant_dir='%s/tests' % build_path, duplicate=0)
diff --git a/arm_compute/core/Error.h b/arm_compute/core/Error.h
index f137be6ecb..64bfbd2787 100644
--- a/arm_compute/core/Error.h
+++ b/arm_compute/core/Error.h
@@ -347,4 +347,10 @@ Status create_error(ErrorCode error_code, const char *function, const char *file
#define ARM_COMPUTE_ERROR_ON_LOC(cond, func, file, line) \
ARM_COMPUTE_ERROR_ON_LOC_MSG(cond, func, file, line, #cond)
+#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
+#define ARM_COMPUTE_THROW(ex) throw(ex)
+#else /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
+#define ARM_COMPUTE_THROW(ex) (ex), std::abort()
+#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
+
#endif /* __ARM_COMPUTE_ERROR_H__ */
diff --git a/arm_compute/core/utils/misc/Cast.h b/arm_compute/core/utils/misc/Cast.h
index 5d9d1b0eca..ae594c96b4 100644
--- a/arm_compute/core/utils/misc/Cast.h
+++ b/arm_compute/core/utils/misc/Cast.h
@@ -48,7 +48,7 @@ inline Target polymorphic_cast(Source *v)
{
if(dynamic_cast<Target>(v) == nullptr)
{
- throw std::bad_cast();
+ ARM_COMPUTE_THROW(std::bad_cast());
}
return static_cast<Target>(v);
}
@@ -88,7 +88,7 @@ std::unique_ptr<Target, Deleter> polymorphic_cast_unique_ptr(std::unique_ptr<Sou
{
if(dynamic_cast<Target *>(v.get()) == nullptr)
{
- throw std::bad_cast();
+ ARM_COMPUTE_THROW(std::bad_cast());
}
auto r = static_cast<Target *>(v.release());
return std::unique_ptr<Target, Deleter>(r, std::move(v.get_deleter()));
diff --git a/src/core/Error.cpp b/src/core/Error.cpp
index 2f6a94bb85..e7b43655a2 100644
--- a/src/core/Error.cpp
+++ b/src/core/Error.cpp
@@ -54,9 +54,9 @@ void arm_compute::error(const char *function, const char *file, const int line,
va_start(args, msg);
auto err = create_error_va_list(ErrorCode::RUNTIME_ERROR, function, file, line, msg, args);
va_end(args);
- throw std::runtime_error(err.error_description());
+ ARM_COMPUTE_THROW(std::runtime_error(err.error_description()));
}
void Status::internal_throw_on_error() const
{
- throw std::runtime_error(_error_description);
+ ARM_COMPUTE_THROW(std::runtime_error(_error_description));
}
diff --git a/src/core/Utils.cpp b/src/core/Utils.cpp
index 39dad8f581..6080dc45ba 100644
--- a/src/core/Utils.cpp
+++ b/src/core/Utils.cpp
@@ -48,8 +48,10 @@ std::string arm_compute::read_file(const std::string &filename, bool binary)
std::string out;
std::ifstream fs;
+#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
try
{
+#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
fs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
std::ios_base::openmode mode = std::ios::in;
@@ -68,11 +70,13 @@ std::string arm_compute::read_file(const std::string &filename, bool binary)
fs.seekg(0, std::ios::beg);
// Copy the content of the file
out.assign(std::istreambuf_iterator<char>(fs), std::istreambuf_iterator<char>());
+#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
}
catch(const std::ifstream::failure &e)
{
ARM_COMPUTE_ERROR("Accessing %s: %s", filename.c_str(), e.what());
}
+#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
return out;
}
diff --git a/src/graph/TypeLoader.cpp b/src/graph/TypeLoader.cpp
index 30a3546821..096188a7f9 100644
--- a/src/graph/TypeLoader.cpp
+++ b/src/graph/TypeLoader.cpp
@@ -38,14 +38,19 @@ arm_compute::DataType data_type_from_name(const std::string &name)
{ "qasymm8", DataType::QASYMM8 },
};
+#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
try
{
+#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
return data_types.at(arm_compute::utility::tolower(name));
+
+#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
}
catch(const std::out_of_range &)
{
throw std::invalid_argument(name);
}
+#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
}
arm_compute::DataLayout data_layout_from_name(const std::string &name)
@@ -56,14 +61,19 @@ arm_compute::DataLayout data_layout_from_name(const std::string &name)
{ "nchw", DataLayout::NCHW },
};
+#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
try
{
+#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
return data_layouts.at(arm_compute::utility::tolower(name));
+
+#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
}
catch(const std::out_of_range &)
{
throw std::invalid_argument(name);
}
+#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
}
namespace graph
{
@@ -76,14 +86,19 @@ Target target_from_name(const std::string &name)
{ "gles", Target::GC },
};
+#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
try
{
+#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
return targets.at(arm_compute::utility::tolower(name));
+
+#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
}
catch(const std::out_of_range &)
{
throw std::invalid_argument(name);
}
+#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
}
} // namespace graph
} // namespace arm_compute
diff --git a/src/runtime/CPP/CPPScheduler.cpp b/src/runtime/CPP/CPPScheduler.cpp
index 2b179fd5ff..5916bb46fd 100644
--- a/src/runtime/CPP/CPPScheduler.cpp
+++ b/src/runtime/CPP/CPPScheduler.cpp
@@ -190,15 +190,19 @@ void CPPScheduler::Thread::worker_thread()
return;
}
+#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
try
{
+#endif /* ARM_COMPUTE_EXCEPTIONS_ENABLED */
process_workloads(*_workloads, *_feeder, _info);
+
+#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
}
catch(...)
{
_current_exception = std::current_exception();
}
-
+#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
_job_complete = true;
lock.unlock();
_cv.notify_one();
@@ -250,18 +254,21 @@ void CPPScheduler::run_workloads(std::vector<IScheduler::Workload> &workloads)
info.thread_id = t;
process_workloads(workloads, feeder, info);
-
+#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
try
{
+#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
for(auto &thread : _threads)
{
thread.wait();
}
+#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
}
catch(const std::system_error &e)
{
std::cerr << "Caught system_error with code " << e.code() << " meaning " << e.what() << '\n';
}
+#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
}
#endif /* DOXYGEN_SKIP_THIS */
diff --git a/src/runtime/MEMUtils.cpp b/src/runtime/MEMUtils.cpp
index a45f9c80c1..be6a3b690d 100644
--- a/src/runtime/MEMUtils.cpp
+++ b/src/runtime/MEMUtils.cpp
@@ -48,8 +48,10 @@ void parse_mem_info(size_t &total, size_t &free, size_t &buffer)
std::stringstream str_stream;
str_stream << meminfo_f.rdbuf();
const std::string str = str_stream.str();
+#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
try
{
+#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
std::smatch match;
if(std::regex_search(str, match, std::regex("MemTotal: (.*)kB")) && match.size() > 1)
{
@@ -72,12 +74,14 @@ void parse_mem_info(size_t &total, size_t &free, size_t &buffer)
memcache = arm_compute::support::cpp11::stoul(result, nullptr);
}
free = memfree + (buffer + memcache);
+#ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
}
catch(std::regex_error &e)
{
// failed parsing /proc/meminfo
// return 0s on all fields
}
+#endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
}
#endif // ifndef BARE_METAL
}