109 lines
4.1 KiB
C++
109 lines
4.1 KiB
C++
/* Copyright 2015-2017 Philippe Tillet
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
* a copy of this software and associated documentation files
|
|
* (the "Software"), to deal in the Software without restriction,
|
|
* including without limitation the rights to use, copy, modify, merge,
|
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
* and to permit persons to whom the Software is furnished to do so,
|
|
* subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be
|
|
* included in all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
#ifndef _ISAAC_SYMBOLIC_HANDLER_H
|
|
#define _ISAAC_SYMBOLIC_HANDLER_H
|
|
|
|
#include "isaac/jit/syntax/expression/expression.h"
|
|
|
|
namespace isaac
|
|
{
|
|
|
|
namespace runtime
|
|
{
|
|
|
|
struct execution_options_type
|
|
{
|
|
execution_options_type(unsigned int _queue_id = 0, std::list<driver::Event>* _events = NULL, std::vector<driver::Event>* _dependencies = NULL) :
|
|
events(_events), dependencies(_dependencies), queue_id_(_queue_id)
|
|
{}
|
|
|
|
execution_options_type(driver::CommandQueue const & queue, std::list<driver::Event> *_events = NULL, std::vector<driver::Event> *_dependencies = NULL) :
|
|
events(_events), dependencies(_dependencies), queue_id_(-1), queue_(new driver::CommandQueue(queue))
|
|
{}
|
|
|
|
void enqueue(driver::Context const & context, driver::Kernel const & kernel, driver::NDRange global, driver::NDRange local) const
|
|
{
|
|
driver::CommandQueue & q = queue(context);
|
|
if(events)
|
|
{
|
|
driver::Event event(q.backend());
|
|
q.enqueue(kernel, global, local, dependencies, &event);
|
|
events->push_back(event);
|
|
}
|
|
else
|
|
q.enqueue(kernel, global, local, dependencies, NULL);
|
|
}
|
|
|
|
driver::CommandQueue & queue(driver::Context const & context) const
|
|
{
|
|
if(queue_)
|
|
return *queue_;
|
|
return driver::backend::queues::get(context, queue_id_);
|
|
}
|
|
|
|
std::list<driver::Event>* events;
|
|
std::vector<driver::Event>* dependencies;
|
|
|
|
private:
|
|
int queue_id_;
|
|
std::shared_ptr<driver::CommandQueue> queue_;
|
|
};
|
|
|
|
struct dispatcher_options_type
|
|
{
|
|
dispatcher_options_type(bool _tune = false, int _label = -1) : tune(_tune), label(_label){}
|
|
bool tune;
|
|
int label;
|
|
};
|
|
|
|
struct compilation_options_type
|
|
{
|
|
compilation_options_type(std::string const & _program_name = "", bool _recompile = false) : program_name(_program_name), recompile(_recompile){}
|
|
std::string program_name;
|
|
bool recompile;
|
|
};
|
|
|
|
class execution_handler
|
|
{
|
|
public:
|
|
execution_handler(expression_tree const & x, execution_options_type const& execution_options = execution_options_type(),
|
|
dispatcher_options_type const & dispatcher_options = dispatcher_options_type(),
|
|
compilation_options_type const & compilation_options = compilation_options_type())
|
|
: x_(x), execution_options_(execution_options), dispatcher_options_(dispatcher_options), compilation_options_(compilation_options){}
|
|
execution_handler(expression_tree const & x, runtime::execution_handler const & other) : x_(x), execution_options_(other.execution_options_), dispatcher_options_(other.dispatcher_options_), compilation_options_(other.compilation_options_){}
|
|
expression_tree const & x() const { return x_; }
|
|
execution_options_type const & execution_options() const { return execution_options_; }
|
|
dispatcher_options_type const & dispatcher_options() const { return dispatcher_options_; }
|
|
compilation_options_type const & compilation_options() const { return compilation_options_; }
|
|
private:
|
|
expression_tree x_;
|
|
execution_options_type execution_options_;
|
|
dispatcher_options_type dispatcher_options_;
|
|
compilation_options_type compilation_options_;
|
|
};
|
|
|
|
}
|
|
}
|
|
|
|
#endif
|