Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

77 Fix end to end examples by creating tensors on separate sequence #78

Merged
merged 4 commits into from
Oct 20, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ void KomputeModelML::train(std::vector<float> yData, std::vector<float> xIData,
{
kp::Manager mgr;

if (std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("createTensors").lock()) {
{

sq->begin();
std::shared_ptr<kp::Sequence> sqTensor =
mgr.createManagedSequence().lock();

sq->record<kp::OpTensorCreate>(params);
sqTensor->begin();
sqTensor->record<kp::OpTensorCreate>(params);
sqTensor->end();
sqTensor->eval();

sq->end();
sq->eval();
std::shared_ptr<kp::Sequence> sq = mgr.createManagedSequence().lock();

// Record op algo base
sq->begin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ void KomputeModelMLNode::train(Array yArr, Array xIArr, Array xJArr) {
{
kp::Manager mgr;

if (std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("createTensors").lock()) {
std::shared_ptr<kp::Sequence> sqTensor =
mgr.createManagedSequence().lock();

sq->begin();

sq->record<kp::OpTensorCreate>(params);
sqTensor->begin();
sqTensor->record<kp::OpTensorCreate>(params);
sqTensor->end();
sqTensor->eval();

sq->end();
sq->eval();
std::shared_ptr<kp::Sequence> sq = mgr.createManagedSequence().lock();

// Record op algo base
sq->begin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ void KomputeModelML::train(Array yArr, Array xIArr, Array xJArr) {
{
kp::Manager mgr;

if (std::shared_ptr<kp::Sequence> sq =
mgr.getOrCreateManagedSequence("createTensors").lock()) {
{
std::shared_ptr<kp::Sequence> sqTensor =
mgr.createManagedSequence().lock();

sq->begin();

sq->record<kp::OpTensorCreate>(params);
sqTensor->begin();
sqTensor->record<kp::OpTensorCreate>(params);
sqTensor->end();
sqTensor->eval();

sq->end();
sq->eval();
std::shared_ptr<kp::Sequence> sq = mgr.createManagedSequence().lock();

// Record op algo base
sq->begin();
Expand Down
14 changes: 7 additions & 7 deletions examples/logistic_regression/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ int main()

kp::Manager mgr;

std::weak_ptr<kp::Sequence> sqWeakPtr = mgr.getOrCreateManagedSequence("createTensors");
std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock();
std::shared_ptr<kp::Sequence> sqTensor =
mgr.createManagedSequence().lock();

sq->begin();

sq->record<kp::OpTensorCreate>(params);
sqTensor->begin();
sqTensor->record<kp::OpTensorCreate>(params);
sqTensor->end();
sqTensor->eval();

sq->end();
sq->eval();
std::shared_ptr<kp::Sequence> sq = mgr.createManagedSequence().lock();

// Record op algo base
sq->begin();
Expand Down
27 changes: 18 additions & 9 deletions single_include/kompute/Kompute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,8 @@ class Manager
* Create a new managed Kompute sequence so it's available within the
* manager.
*
* @param sequenceName The name for the named sequence to be created, if empty then default indexed value is used
* @param sequenceName The name for the named sequence to be created, if
* empty then default indexed value is used
* @param queueIndex The queue to use from the available queues
* @return Weak pointer to the manager owned sequence resource
*/
Expand Down Expand Up @@ -1363,8 +1364,10 @@ class Manager
{
SPDLOG_DEBUG("Kompute Manager evalOp Default triggered");
this->mCurrentSequenceIndex++;
this->evalOp<T>(
tensors, KP_DEFAULT_SESSION + std::to_string(this->mCurrentSequenceIndex), std::forward<TArgs>(params)...);
this->evalOp<T>(tensors,
KP_DEFAULT_SESSION +
std::to_string(this->mCurrentSequenceIndex),
std::forward<TArgs>(params)...);
}

/**
Expand Down Expand Up @@ -1406,20 +1409,23 @@ class Manager
}

/**
* Operation that evaluates operation against default sequence asynchronously.
* Operation that evaluates operation against default sequence
* asynchronously.
*
* @param tensors The tensors to be used in the operation recorded
* @param params Template parameters that will be used to initialise
* Operation to allow for extensible configurations on initialisation
*/
template<typename T, typename... TArgs>
void evalOpAsyncDefault(std::vector<std::shared_ptr<Tensor>> tensors,
TArgs&&... params)
TArgs&&... params)
{
SPDLOG_DEBUG("Kompute Manager evalOpAsyncDefault triggered");
this->mCurrentSequenceIndex++;
this->evalOpAsync<T>(
tensors, KP_DEFAULT_SESSION + std::to_string(this->mCurrentSequenceIndex), std::forward<TArgs>(params)...);
this->evalOpAsync<T>(tensors,
KP_DEFAULT_SESSION +
std::to_string(this->mCurrentSequenceIndex),
std::forward<TArgs>(params)...);
}

/**
Expand All @@ -1430,7 +1436,8 @@ class Manager
*/
void evalOpAwait(std::string sequenceName, uint64_t waitFor = UINT64_MAX)
{
SPDLOG_DEBUG("Kompute Manager evalOpAwait triggered with sequence {}", sequenceName);
SPDLOG_DEBUG("Kompute Manager evalOpAwait triggered with sequence {}",
sequenceName);
std::unordered_map<std::string, std::shared_ptr<Sequence>>::iterator
found = this->mManagedSequences.find(sequenceName);

Expand Down Expand Up @@ -1459,7 +1466,9 @@ class Manager
void evalOpAwaitDefault(uint64_t waitFor = UINT64_MAX)
{
SPDLOG_DEBUG("Kompute Manager evalOpAwaitDefault triggered");
this->evalOpAwait(KP_DEFAULT_SESSION + std::to_string(this->mCurrentSequenceIndex), waitFor);
this->evalOpAwait(KP_DEFAULT_SESSION +
std::to_string(this->mCurrentSequenceIndex),
waitFor);
}

/**
Expand Down