UPdated examples and documentations to not require glsl deps
This commit is contained in:
parent
15346ee505
commit
96768a3302
10 changed files with 85 additions and 27 deletions
|
|
@ -5,6 +5,18 @@
|
|||
|
||||
#include "kompute/Kompute.hpp"
|
||||
|
||||
static std::vector<uint32_t>
|
||||
compileSource(
|
||||
const std::string& source)
|
||||
{
|
||||
if (system(std::string("glslangValidator --stdin -S comp -V -o tmp_kp_shader.comp.spv << END\n" + source + "\nEND").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())};
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
#if KOMPUTE_ENABLE_SPDLOG
|
||||
|
|
@ -39,7 +51,7 @@ int main()
|
|||
|
||||
std::vector<std::shared_ptr<kp::Tensor>> params = { tensorInA, tensorInB, tensorOut };
|
||||
|
||||
std::shared_ptr<kp::Algorithm> algo = mgr.algorithm(params, kp_test_utils::Shader::compileSource(shader));
|
||||
std::shared_ptr<kp::Algorithm> algo = mgr.algorithm(params, kp_test_utils::compileSource(shader));
|
||||
|
||||
mgr.sequence()
|
||||
->record<kp::OpTensorSyncDevice>(params)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,18 @@
|
|||
|
||||
#include "KomputeSummatorNode.h"
|
||||
|
||||
static std::vector<uint32_t>
|
||||
compileSource(
|
||||
const std::string& source)
|
||||
{
|
||||
if (system(std::string("glslangValidator --stdin -S comp -V -o tmp_kp_shader.comp.spv << END\n" + source + "\nEND").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())};
|
||||
}
|
||||
|
||||
KomputeSummatorNode::KomputeSummatorNode() {
|
||||
this->_init();
|
||||
}
|
||||
|
|
@ -52,9 +64,9 @@ void KomputeSummatorNode::_init() {
|
|||
)");
|
||||
|
||||
std::shared_ptr<kp::Algorithm> algo =
|
||||
mgr.algorithm(
|
||||
this->mManager.algorithm(
|
||||
{ this->mPrimaryTensor, this->mSecondaryTensor },
|
||||
kp_test_utils::Shader::compileSource(shader));
|
||||
compileSource(shader));
|
||||
|
||||
|
||||
// First we ensure secondary tensor loads to GPU
|
||||
|
|
@ -63,7 +75,7 @@ void KomputeSummatorNode::_init() {
|
|||
{ this->mSecondaryTensor });
|
||||
|
||||
// Then we run the operation with both tensors
|
||||
sq->record<kp::OpAlgoDispatch>(algo)
|
||||
sq->record<kp::OpAlgoDispatch>(algo);
|
||||
|
||||
// We map the result back to local
|
||||
sq->record<kp::OpTensorSyncLocal>(
|
||||
|
|
|
|||
|
|
@ -5,6 +5,18 @@
|
|||
|
||||
#include "KomputeSummator.hpp"
|
||||
|
||||
static std::vector<uint32_t>
|
||||
compileSource(
|
||||
const std::string& source)
|
||||
{
|
||||
if (system(std::string("glslangValidator --stdin -S comp -V -o tmp_kp_shader.comp.spv << END\n" + source + "\nEND").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())};
|
||||
}
|
||||
|
||||
namespace godot {
|
||||
|
||||
KomputeSummator::KomputeSummator() {
|
||||
|
|
@ -58,7 +70,7 @@ void KomputeSummator::_init() {
|
|||
// Then we run the operation with both tensors
|
||||
this->mSequence->record<kp::OpAlgoCreate>(
|
||||
{ this->mPrimaryTensor, this->mSecondaryTensor },
|
||||
kp_test_utils::Shader::compileSource(shader));
|
||||
compileSource(shader));
|
||||
|
||||
// We map the result back to local
|
||||
this->mSequence->record<kp::OpTensorSyncLocal>(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,15 @@
|
|||
import os
|
||||
|
||||
import kp
|
||||
|
||||
def compile_source(source):
|
||||
os.system("glslangValidator --stdin -S comp -V -o tmp_kp_shader.comp.spv << END\n" + source + "\nEND")
|
||||
return open("tmp_kp_shader.comp.spv", "rb").read()
|
||||
|
||||
|
||||
# This is the convolution & leakyrelu shader.
|
||||
global conv_shader
|
||||
conv_shader = kp.Shader.compile_source("""
|
||||
conv_shader = compile_source("""
|
||||
#version 450
|
||||
|
||||
layout (local_size_x = 8, local_size_y = 2) in;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue