From 8285f2f878222893bdd4d07ad86d2079685ffd99 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Tue, 3 Nov 2020 18:04:29 +0000 Subject: [PATCH] Updated logistic regression model --- .../kompute_summator/KomputeSummatorNode.h | 2 +- .../gdnative_shared/src/KomputeSummator.cpp | 22 +++++-------------- .../gdnative_shared/src/KomputeSummator.hpp | 2 +- .../kompute_model_ml/KomputeModelMLNode.cpp | 8 +++---- .../gdnative_shared/src/KomputeModelML.cpp | 8 +++---- 5 files changed, 16 insertions(+), 26 deletions(-) diff --git a/examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.h b/examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.h index 5bc201a90..1d94da9a5 100644 --- a/examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.h +++ b/examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.h @@ -24,7 +24,7 @@ protected: private: kp::Manager mManager; - std::weak_ptr mSequence; + std::shared_ptr mSequence; std::shared_ptr mPrimaryTensor; std::shared_ptr mSecondaryTensor; }; diff --git a/examples/godot_examples/gdnative_shared/src/KomputeSummator.cpp b/examples/godot_examples/gdnative_shared/src/KomputeSummator.cpp index f64e0d088..788486e82 100644 --- a/examples/godot_examples/gdnative_shared/src/KomputeSummator.cpp +++ b/examples/godot_examples/gdnative_shared/src/KomputeSummator.cpp @@ -16,12 +16,7 @@ void KomputeSummator::add(float value) { // Set the new data in the local device this->mSecondaryTensor->setData({value}); // Execute recorded sequence - if (std::shared_ptr sq = this->mSequence.lock()) { - sq->eval(); - } - else { - throw std::runtime_error("Sequence pointer no longer available"); - } + this->mSequence->eval(); } void KomputeSummator::reset() { @@ -38,9 +33,7 @@ void KomputeSummator::_init() { this->mSequence = this->mManager.getOrCreateManagedSequence("AdditionSeq"); // We now record the steps in the sequence - if (std::shared_ptr sq = this->mSequence.lock()) { - std::string shader(R"( #version 450 @@ -55,26 +48,23 @@ void KomputeSummator::_init() { } )"); - sq->begin(); + this->mSequence->begin(); // First we ensure secondary tensor loads to GPU // No need to sync the primary tensor as it should not be changed - sq->record( + this->mSequence->record( { this->mSecondaryTensor }); // Then we run the operation with both tensors - sq->record>( + this->mSequence->record( { this->mPrimaryTensor, this->mSecondaryTensor }, std::vector(shader.begin(), shader.end())); // We map the result back to local - sq->record( + this->mSequence->record( { this->mPrimaryTensor }); - sq->end(); - } - else { - throw std::runtime_error("Sequence pointer no longer available"); + this->mSequence->end(); } } diff --git a/examples/godot_examples/gdnative_shared/src/KomputeSummator.hpp b/examples/godot_examples/gdnative_shared/src/KomputeSummator.hpp index 9131e7f57..7f6b42e82 100644 --- a/examples/godot_examples/gdnative_shared/src/KomputeSummator.hpp +++ b/examples/godot_examples/gdnative_shared/src/KomputeSummator.hpp @@ -26,7 +26,7 @@ public: private: kp::Manager mManager; - std::weak_ptr mSequence; + std::shared_ptr mSequence; std::shared_ptr mPrimaryTensor; std::shared_ptr mSecondaryTensor; }; diff --git a/examples/godot_logistic_regression/custom_module/kompute_model_ml/KomputeModelMLNode.cpp b/examples/godot_logistic_regression/custom_module/kompute_model_ml/KomputeModelMLNode.cpp index fe0a911a5..f583d910f 100644 --- a/examples/godot_logistic_regression/custom_module/kompute_model_ml/KomputeModelMLNode.cpp +++ b/examples/godot_logistic_regression/custom_module/kompute_model_ml/KomputeModelMLNode.cpp @@ -51,14 +51,14 @@ void KomputeModelMLNode::train(Array yArr, Array xIArr, Array xJArr) { kp::Manager mgr; std::shared_ptr sqTensor = - mgr.createManagedSequence().lock(); + mgr.createManagedSequence(); sqTensor->begin(); sqTensor->record(params); sqTensor->end(); sqTensor->eval(); - std::shared_ptr sq = mgr.createManagedSequence().lock(); + std::shared_ptr sq = mgr.createManagedSequence(); // Record op algo base sq->begin(); @@ -67,11 +67,11 @@ void KomputeModelMLNode::train(Array yArr, Array xIArr, Array xJArr) { #ifdef KOMPUTE_ANDROID_SHADER_FROM_STRING // Newer versions of Android are able to use shaderc to read raw string - sq->record>( + sq->record( params, std::vector(LR_SHADER.begin(), LR_SHADER.end())); #else // Older versions of Android require the SPIRV binary directly - sq->record>( + sq->record( params, std::vector( kp::shader_data::shaders_glsl_logisticregression_comp_spv, kp::shader_data::shaders_glsl_logisticregression_comp_spv diff --git a/examples/godot_logistic_regression/gdnative_shared/src/KomputeModelML.cpp b/examples/godot_logistic_regression/gdnative_shared/src/KomputeModelML.cpp index 174398501..4135e83ed 100644 --- a/examples/godot_logistic_regression/gdnative_shared/src/KomputeModelML.cpp +++ b/examples/godot_logistic_regression/gdnative_shared/src/KomputeModelML.cpp @@ -56,14 +56,14 @@ void KomputeModelML::train(Array yArr, Array xIArr, Array xJArr) { { std::shared_ptr sqTensor = - mgr.createManagedSequence().lock(); + mgr.createManagedSequence(); sqTensor->begin(); sqTensor->record(params); sqTensor->end(); sqTensor->eval(); - std::shared_ptr sq = mgr.createManagedSequence().lock(); + std::shared_ptr sq = mgr.createManagedSequence(); // Record op algo base sq->begin(); @@ -72,11 +72,11 @@ void KomputeModelML::train(Array yArr, Array xIArr, Array xJArr) { #ifdef KOMPUTE_ANDROID_SHADER_FROM_STRING // Newer versions of Android are able to use shaderc to read raw string - sq->record>( + sq->record( params, std::vector(LR_SHADER.begin(), LR_SHADER.end())); #else // Older versions of Android require the SPIRV binary directly - sq->record>( + sq->record( params, std::vector( kp::shader_data::shaders_glsl_logisticregression_comp_spv, kp::shader_data::shaders_glsl_logisticregression_comp_spv