Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 17 additions & 67 deletions src/include/kompute/Sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Sequence : public std::enable_shared_from_this<Sequence>
* function also requires the Sequence to be recording, otherwise it will
* not be able to add the operation.
*
* @param op Object derived from kp::BaseOp that will be recoreded by the
* @param op Object derived from kp::BaseOp that will be recorded by the
* sequence which will be used when the operation is evaluated.
* @return shared_ptr<Sequence> of the Sequence class itself
*/
Expand All @@ -53,37 +53,18 @@ class Sequence : public std::enable_shared_from_this<Sequence>
* function also requires the Sequence to be recording, otherwise it will
* not be able to add the operation.
*
* @param tensors Vector of tensors to use for the operation
* @param param Template parameter that is used to initialise the operation.
* @param TArgs Template parameters that are used to initialise operation
* which allows for extensible configurations on initialisation.
* @return shared_ptr<Sequence> of the Sequence class itself
*/
template<typename T, typename... TArgs>
std::shared_ptr<Sequence> record(
std::vector<std::shared_ptr<Tensor>> tensors,
typename T::ConstructorParameterType param,
TArgs&&... params)
{
std::shared_ptr<T> op{ new T(tensors, std::forward<TArgs>(params)...) };
return this->record(op);
}
/**
* Record function for operation to be added to the GPU queue in batch. This
* template requires classes to be derived from the OpBase class. This
* function also requires the Sequence to be recording, otherwise it will
* not be able to add the operation.
*
* @param algorithm Algorithm to use for the record often used for OpAlgo
* operations
* @param TArgs Template parameters that are used to initialise operation
* which allows for extensible configurations on initialisation.
* @return shared_ptr<Sequence> of the Sequence class itself
*/
template<typename T, typename... TArgs>
std::shared_ptr<Sequence> record(std::shared_ptr<Algorithm> algorithm,
TArgs&&... params)
{
std::shared_ptr<T> op{ new T(algorithm,
std::forward<TArgs>(params)...) };
static_assert(std::is_base_of<OpBase, T>::value, "T must derive from OpBase");
std::shared_ptr<T> op{ new T(param, std::forward<TArgs>(params)...) };
return this->record(op);
}

Expand All @@ -108,34 +89,18 @@ class Sequence : public std::enable_shared_from_this<Sequence>
* Eval sends all the recorded and stored operations in the vector of
* operations into the gpu as a submit job with a barrier.
*
* @param tensors Vector of tensors to use for the operation
* @param param Template parameter that is used to initialise the operation.
* @param TArgs Template parameters that are used to initialise operation
* which allows for extensible configurations on initialisation.
* @return shared_ptr<Sequence> of the Sequence class itself
*/
template<typename T, typename... TArgs>
std::shared_ptr<Sequence> eval(std::vector<std::shared_ptr<Tensor>> tensors,
TArgs&&... params)
{
std::shared_ptr<T> op{ new T(tensors, std::forward<TArgs>(params)...) };
return this->eval(op);
}
/**
* Eval sends all the recorded and stored operations in the vector of
* operations into the gpu as a submit job with a barrier.
*
* @param algorithm Algorithm to use for the record often used for OpAlgo
* operations
* @param TArgs Template parameters that are used to initialise operation
* which allows for extensible configurations on initialisation.
* @return shared_ptr<Sequence> of the Sequence class itself
*/
template<typename T, typename... TArgs>
std::shared_ptr<Sequence> eval(std::shared_ptr<Algorithm> algorithm,
TArgs&&... params)
std::shared_ptr<Sequence> eval(
typename T::ConstructorParameterType param,
TArgs&&... params)
{
std::shared_ptr<T> op{ new T(algorithm,
std::forward<TArgs>(params)...) };
static_assert(std::is_base_of<OpBase, T>::value, "T must derive from OpBase");
std::shared_ptr<T> op{ new T(param, std::forward<TArgs>(params)...) };
return this->eval(op);
}

Expand All @@ -148,6 +113,7 @@ class Sequence : public std::enable_shared_from_this<Sequence>
* @return Boolean stating whether execution was successful.
*/
std::shared_ptr<Sequence> evalAsync();

/**
* Clears currnet operations to record provided one in the vector of
* operations into the gpu as a submit job without a barrier. EvalAwait()
Expand All @@ -157,39 +123,23 @@ class Sequence : public std::enable_shared_from_this<Sequence>
* @return Boolean stating whether execution was successful.
*/
std::shared_ptr<Sequence> evalAsync(std::shared_ptr<OpBase> op);

/**
* Eval sends all the recorded and stored operations in the vector of
* operations into the gpu as a submit job with a barrier.
*
* @param tensors Vector of tensors to use for the operation
* @param param Template parameter that is used to initialise the operation.
* @param TArgs Template parameters that are used to initialise operation
* which allows for extensible configurations on initialisation.
* @return shared_ptr<Sequence> of the Sequence class itself
*/
template<typename T, typename... TArgs>
std::shared_ptr<Sequence> evalAsync(
std::vector<std::shared_ptr<Tensor>> tensors,
typename T::ConstructorParameterType param,
TArgs&&... params)
{
std::shared_ptr<T> op{ new T(tensors, std::forward<TArgs>(params)...) };
return this->evalAsync(op);
}
/**
* Eval sends all the recorded and stored operations in the vector of
* operations into the gpu as a submit job with a barrier.
*
* @param algorithm Algorithm to use for the record often used for OpAlgo
* operations
* @param TArgs Template parameters that are used to initialise operation
* which allows for extensible configurations on initialisation.
* @return shared_ptr<Sequence> of the Sequence class itself
*/
template<typename T, typename... TArgs>
std::shared_ptr<Sequence> evalAsync(std::shared_ptr<Algorithm> algorithm,
TArgs&&... params)
{
std::shared_ptr<T> op{ new T(algorithm,
std::forward<TArgs>(params)...) };
static_assert(std::is_base_of<OpBase, T>::value, "T must derive from OpBase");
std::shared_ptr<T> op{ new T(param, std::forward<TArgs>(params)...) };
return this->evalAsync(op);
}

Expand Down
2 changes: 2 additions & 0 deletions src/include/kompute/operations/OpAlgoDispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace kp {
class OpAlgoDispatch : public OpBase
{
public:
using ConstructorParameterType = std::shared_ptr<kp::Algorithm>;

/**
* Constructor that stores the algorithm to use as well as the relevant
* push constants to override when recording.
Expand Down
2 changes: 2 additions & 0 deletions src/include/kompute/operations/OpBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace kp {
class OpBase
{
public:
using ConstructorParameterType = void;

/**
* Default destructor for OpBase class. This OpBase destructor class should
* always be called to destroy and free owned resources unless it is
Expand Down
2 changes: 2 additions & 0 deletions src/include/kompute/operations/OpMemoryBarrier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace kp {
class OpMemoryBarrier : public OpBase
{
public:
using ConstructorParameterType = std::vector<std::shared_ptr<Tensor>>;

/**
* Constructor that stores tensors as well as memory barrier parameters to
* be used to create a pipeline barrier on the respective primary or staging
Expand Down
2 changes: 2 additions & 0 deletions src/include/kompute/operations/OpMult.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace kp {
class OpMult : public OpAlgoDispatch
{
public:
using ConstructorParameterType = std::vector<std::shared_ptr<Tensor>>;

/**
* Default constructor with parameters that provides the bare minimum
* requirements for the operations to be able to create and manage their
Expand Down
2 changes: 2 additions & 0 deletions src/include/kompute/operations/OpTensorCopy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace kp {
class OpTensorCopy : public OpBase
{
public:
using ConstructorParameterType = std::vector<std::shared_ptr<Tensor>>;

/**
* Default constructor with parameters that provides the core vulkan
* resources and the tensors that will be used in the operation.
Expand Down
2 changes: 2 additions & 0 deletions src/include/kompute/operations/OpTensorSyncDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace kp {
class OpTensorSyncDevice : public OpBase
{
public:
using ConstructorParameterType = std::vector<std::shared_ptr<Tensor>>;

/**
* Default constructor with parameters that provides the core vulkan
* resources and the tensors that will be used in the operation. The tensos
Expand Down
2 changes: 2 additions & 0 deletions src/include/kompute/operations/OpTensorSyncLocal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace kp {
class OpTensorSyncLocal : public OpBase
{
public:
using ConstructorParameterType = std::vector<std::shared_ptr<Tensor>>;

/**
* Default constructor with parameters that provides the core vulkan
* resources and the tensors that will be used in the operation. The tensors
Expand Down