diff --git a/lib/kernels/templates/base.cpp b/lib/kernels/templates/base.cpp index fb3e685cb..7d4f7caae 100644 --- a/lib/kernels/templates/base.cpp +++ b/lib/kernels/templates/base.cpp @@ -12,6 +12,7 @@ #include "isaac/kernels/templates/base.h" #include "isaac/kernels/parse.h" #include "isaac/exception/unknown_datatype.h" +#include "isaac/exception/operation_not_supported.h" #include "isaac/symbolic/io.h" #include "tools/map.hpp" @@ -83,6 +84,10 @@ std::string base::generate(std::string const & suffix, expressions_tuple const & expressions_tuple::data_type::const_iterator sit; std::vector::iterator mit; + int err = is_invalid(expressions, device); + if(err != 0) + throw operation_not_supported_exception("The supplied parameters for this template are invalid : err " + tools::to_string(err)); + //Create mapping std::vector mappings(expressions.data().size()); std::unique_ptr binder; @@ -141,10 +146,6 @@ int base_impl::is_invalid(expressions_tuple const & expressions, d if (p_.simd_width!=1 && p_.simd_width!=2 && p_.simd_width!=3 && p_.simd_width!=4) return TEMPLATE_INVALID_SIMD_WIDTH; - //Temporary workspace - if(temporary_workspace(expressions) > 2e6) - return TEMPLATE_TEMPORARY_TOO_LARGE; - return is_invalid_impl(device, expressions); } diff --git a/lib/profiles/profiles.cpp b/lib/profiles/profiles.cpp index e378312e0..e7fd36240 100644 --- a/lib/profiles/profiles.cpp +++ b/lib/profiles/profiles.cpp @@ -109,6 +109,8 @@ void profiles::value_type::execute(controller const & expr) } //Prediction + static const int MAX_TEMPORARY_WORKSPACE = 1e6; + int label = 0; if(expr.dispatcher_options().label>=0) label = expr.dispatcher_options().label; @@ -120,13 +122,13 @@ void profiles::value_type::execute(controller const & expr) do{ label = std::distance(predictions.begin(),std::max_element(predictions.begin(), predictions.end())); predictions[label] = 0; - }while(templates_[label]->is_invalid(expr.x(),queue_.device())); + }while(templates_[label]->temporary_workspace(expr.x()) > MAX_TEMPORARY_WORKSPACE); } //Execution - int err = templates_[label]->is_invalid(expr.x(), queue_.device()); - if(err != 0) - throw operation_not_supported_exception("The supplied parameters for this template are invalid : err " + tools::to_string(err)); + if(templates_[label]->temporary_workspace(expr.x()) > MAX_TEMPORARY_WORKSPACE) + throw operation_not_supported_exception("Running this operation would require an overly large temporary."); + return templates_[label]->enqueue(queue_, program, tools::to_string(label), *fallback_, expr); }