Added .clang-format file and formatted everything
Signed-off-by: Fabian Sauter <sauter.fabian@mailbox.org>
This commit is contained in:
parent
f731f2e55c
commit
24cd307042
47 changed files with 5157 additions and 4354 deletions
|
|
@ -4,55 +4,63 @@
|
|||
|
||||
#include "KomputeSummatorNode.h"
|
||||
|
||||
static
|
||||
std::vector<uint32_t>
|
||||
compileSource(
|
||||
const std::string& source)
|
||||
static std::vector<uint32_t>
|
||||
compileSource(const std::string& source)
|
||||
{
|
||||
std::ofstream fileOut("tmp_kp_shader.comp");
|
||||
fileOut << source;
|
||||
fileOut.close();
|
||||
if (system(std::string("glslangValidator -V tmp_kp_shader.comp -o tmp_kp_shader.comp.spv").c_str()))
|
||||
fileOut << source;
|
||||
fileOut.close();
|
||||
if (system(
|
||||
std::string(
|
||||
"glslangValidator -V tmp_kp_shader.comp -o tmp_kp_shader.comp.spv")
|
||||
.c_str()))
|
||||
throw std::runtime_error("Error running glslangValidator command");
|
||||
std::ifstream fileStream("tmp_kp_shader.comp.spv", std::ios::binary);
|
||||
std::vector<char> buffer;
|
||||
buffer.insert(buffer.begin(), std::istreambuf_iterator<char>(fileStream), {});
|
||||
return {(uint32_t*)buffer.data(), (uint32_t*)(buffer.data() + buffer.size())};
|
||||
buffer.insert(
|
||||
buffer.begin(), std::istreambuf_iterator<char>(fileStream), {});
|
||||
return { (uint32_t*)buffer.data(),
|
||||
(uint32_t*)(buffer.data() + buffer.size()) };
|
||||
}
|
||||
|
||||
|
||||
KomputeSummatorNode::KomputeSummatorNode() {
|
||||
KomputeSummatorNode::KomputeSummatorNode()
|
||||
{
|
||||
this->_init();
|
||||
}
|
||||
|
||||
void KomputeSummatorNode::add(float value) {
|
||||
void
|
||||
KomputeSummatorNode::add(float value)
|
||||
{
|
||||
// Set the new data in the local device
|
||||
this->mSecondaryTensor->setData({value});
|
||||
this->mSecondaryTensor->setData({ value });
|
||||
// Execute recorded sequence
|
||||
if (std::shared_ptr<kp::Sequence> sq = this->mSequence) {
|
||||
sq->eval();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw std::runtime_error("Sequence pointer no longer available");
|
||||
}
|
||||
}
|
||||
|
||||
void KomputeSummatorNode::reset() {
|
||||
}
|
||||
void
|
||||
KomputeSummatorNode::reset()
|
||||
{}
|
||||
|
||||
float KomputeSummatorNode::get_total() const {
|
||||
float
|
||||
KomputeSummatorNode::get_total() const
|
||||
{
|
||||
return this->mPrimaryTensor->data()[0];
|
||||
}
|
||||
|
||||
void KomputeSummatorNode::_init() {
|
||||
void
|
||||
KomputeSummatorNode::_init()
|
||||
{
|
||||
std::cout << "CALLING INIT" << std::endl;
|
||||
this->mPrimaryTensor = this->mManager.tensor({ 0.0 });
|
||||
this->mSecondaryTensor = this->mManager.tensor({ 0.0 });
|
||||
this->mSequence = this->mManager.sequence();
|
||||
|
||||
// We now record the steps in the sequence
|
||||
if (std::shared_ptr<kp::Sequence> sq = this->mSequence)
|
||||
{
|
||||
if (std::shared_ptr<kp::Sequence> sq = this->mSequence) {
|
||||
|
||||
std::string shader(R"(
|
||||
#version 450
|
||||
|
|
@ -68,40 +76,38 @@ void KomputeSummatorNode::_init() {
|
|||
}
|
||||
)");
|
||||
|
||||
std::shared_ptr<kp::Algorithm> algo =
|
||||
this->mManager.algorithm(
|
||||
{ this->mPrimaryTensor, this->mSecondaryTensor },
|
||||
compileSource(shader));
|
||||
|
||||
std::shared_ptr<kp::Algorithm> algo = this->mManager.algorithm(
|
||||
{ this->mPrimaryTensor, this->mSecondaryTensor },
|
||||
compileSource(shader));
|
||||
|
||||
// First we ensure secondary tensor loads to GPU
|
||||
// No need to sync the primary tensor as it should not be changed
|
||||
sq->record<kp::OpTensorSyncDevice>(
|
||||
{ this->mSecondaryTensor });
|
||||
sq->record<kp::OpTensorSyncDevice>({ this->mSecondaryTensor });
|
||||
|
||||
// Then we run the operation with both tensors
|
||||
sq->record<kp::OpAlgoDispatch>(algo);
|
||||
|
||||
// We map the result back to local
|
||||
sq->record<kp::OpTensorSyncLocal>(
|
||||
{ this->mPrimaryTensor });
|
||||
// We map the result back to local
|
||||
sq->record<kp::OpTensorSyncLocal>({ this->mPrimaryTensor });
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw std::runtime_error("Sequence pointer no longer available");
|
||||
}
|
||||
}
|
||||
|
||||
void KomputeSummatorNode::_process(float delta) {
|
||||
void
|
||||
KomputeSummatorNode::_process(float delta)
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
void KomputeSummatorNode::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("_process", "delta"), &KomputeSummatorNode::_process);
|
||||
void
|
||||
KomputeSummatorNode::_bind_methods()
|
||||
{
|
||||
ClassDB::bind_method(D_METHOD("_process", "delta"),
|
||||
&KomputeSummatorNode::_process);
|
||||
ClassDB::bind_method(D_METHOD("_init"), &KomputeSummatorNode::_init);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add", "value"), &KomputeSummatorNode::add);
|
||||
ClassDB::bind_method(D_METHOD("reset"), &KomputeSummatorNode::reset);
|
||||
ClassDB::bind_method(D_METHOD("get_total"), &KomputeSummatorNode::get_total);
|
||||
ClassDB::bind_method(D_METHOD("get_total"),
|
||||
&KomputeSummatorNode::get_total);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,10 +6,11 @@
|
|||
|
||||
#include "scene/main/node.h"
|
||||
|
||||
class KomputeSummatorNode : public Node {
|
||||
class KomputeSummatorNode : public Node
|
||||
{
|
||||
GDCLASS(KomputeSummatorNode, Node);
|
||||
|
||||
public:
|
||||
public:
|
||||
KomputeSummatorNode();
|
||||
|
||||
void add(float value);
|
||||
|
|
@ -19,13 +20,12 @@ public:
|
|||
void _process(float delta);
|
||||
void _init();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
private:
|
||||
kp::Manager mManager;
|
||||
std::shared_ptr<kp::Sequence> mSequence;
|
||||
std::shared_ptr<kp::Tensor> mPrimaryTensor;
|
||||
std::shared_ptr<kp::Tensor> mSecondaryTensor;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,17 @@
|
|||
|
||||
#include "register_types.h"
|
||||
|
||||
#include "core/class_db.h"
|
||||
#include "KomputeSummatorNode.h"
|
||||
#include "core/class_db.h"
|
||||
|
||||
void register_kompute_summator_types() {
|
||||
void
|
||||
register_kompute_summator_types()
|
||||
{
|
||||
ClassDB::register_class<KomputeSummatorNode>();
|
||||
}
|
||||
|
||||
void unregister_kompute_summator_types() {
|
||||
// Nothing to do here in this example.
|
||||
void
|
||||
unregister_kompute_summator_types()
|
||||
{
|
||||
// Nothing to do here in this example.
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
/* register_types.h */
|
||||
#pragma once
|
||||
|
||||
void register_kompute_summator_types();
|
||||
void unregister_kompute_summator_types();
|
||||
void
|
||||
register_kompute_summator_types();
|
||||
void
|
||||
unregister_kompute_summator_types();
|
||||
/* yes, the word in the middle must be the same as the module folder name */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue