Updated tests to not use namespaace for compileShader

This commit is contained in:
Alejandro Saucedo 2021-07-21 20:30:21 +01:00
parent b7fd1b4d79
commit 15346ee505
10 changed files with 36 additions and 57 deletions

View file

@ -12,7 +12,6 @@ endif()
file(GLOB test_kompute_CPP
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/utils/kompute_test/*.cpp"
)
add_executable(test_kompute ${test_kompute_CPP})

View file

@ -39,7 +39,7 @@ TEST(TestAsyncOperations, TestManagerParallelExecution)
}
)");
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
std::vector<uint32_t> spirv = compileSource(shader);
std::vector<float> data(size, 0.0);
std::vector<float> resultSync(size, 100000000);
@ -147,7 +147,7 @@ TEST(TestAsyncOperations, TestManagerAsyncExecution)
}
)");
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
std::vector<uint32_t> spirv = compileSource(shader);
std::vector<float> data(size, 0.0);
std::vector<float> resultAsync(size, 100000000);

View file

@ -18,7 +18,7 @@ TEST(TestDestroy, TestDestroyTensorSingle)
pa[index] = pa[index] + 1;
})");
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
std::vector<uint32_t> spirv = compileSource(shader);
{
std::shared_ptr<kp::Sequence> sq = nullptr;
@ -60,7 +60,7 @@ TEST(TestDestroy, TestDestroyTensorVector)
pa[index] = pa[index] + 1;
pb[index] = pb[index] + 2;
})");
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
std::vector<uint32_t> spirv = compileSource(shader);
{
std::shared_ptr<kp::Sequence> sq = nullptr;
@ -105,7 +105,7 @@ TEST(TestDestroy, TestDestroySequenceSingle)
pa[index] = pa[index] + 1;
})");
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
std::vector<uint32_t> spirv = compileSource(shader);
{
std::shared_ptr<kp::Sequence> sq = nullptr;

View file

@ -53,7 +53,7 @@ TEST(TestMultipleAlgoExecutions, TestEndToEndFunctionality)
kp::Constants pushConstsB({ 3.0 });
auto algorithm = mgr.algorithm(params,
kp_test_utils::Shader::compileSource(shader),
compileSource(shader),
workgroup,
specConsts,
pushConstsA);
@ -91,7 +91,7 @@ TEST(TestMultipleAlgoExecutions, SingleSequenceRecord)
pa[index] = pa[index] + 1;
})");
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
std::vector<uint32_t> spirv = compileSource(shader);
{
// A sharedMemoryBarrier is required as the shader is not thread-safe:w
@ -132,7 +132,7 @@ TEST(TestMultipleAlgoExecutions, MultipleCmdBufRecords)
pa[index] = pa[index] + 1;
})");
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
std::vector<uint32_t> spirv = compileSource(shader);
std::shared_ptr<kp::Algorithm> algorithm =
mgr.algorithm({ tensorA }, spirv);
@ -168,7 +168,7 @@ TEST(TestMultipleAlgoExecutions, MultipleSequences)
pa[index] = pa[index] + 1;
})");
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
std::vector<uint32_t> spirv = compileSource(shader);
std::shared_ptr<kp::Algorithm> algorithm =
mgr.algorithm({ tensorA }, spirv);
@ -203,7 +203,7 @@ TEST(TestMultipleAlgoExecutions, SingleRecordMultipleEval)
pa[index] = pa[index] + 1;
})");
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
std::vector<uint32_t> spirv = compileSource(shader);
std::shared_ptr<kp::Algorithm> algorithm =
mgr.algorithm({ tensorA }, spirv);

View file

@ -29,7 +29,7 @@ TEST(TestOpAlgoCreate, ShaderRawDataFromConstructor)
}
)");
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
std::vector<uint32_t> spirv = compileSource(shader);
std::vector<std::shared_ptr<kp::Tensor>> params = { tensorA, tensorB };

View file

@ -24,7 +24,7 @@ TEST(TestPushConstants, TestConstantsAlgoDispatchOverride)
pa[2] += pcs.z;
})");
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
std::vector<uint32_t> spirv = compileSource(shader);
std::shared_ptr<kp::Sequence> sq = nullptr;
@ -69,7 +69,7 @@ TEST(TestPushConstants, TestConstantsAlgoDispatchNoOverride)
pa[2] += pcs.z;
})");
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
std::vector<uint32_t> spirv = compileSource(shader);
std::shared_ptr<kp::Sequence> sq = nullptr;
@ -114,7 +114,7 @@ TEST(TestPushConstants, TestConstantsWrongSize)
pa[2] += pcs.z;
})");
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
std::vector<uint32_t> spirv = compileSource(shader);
std::shared_ptr<kp::Sequence> sq = nullptr;

View file

@ -68,7 +68,7 @@ TEST(TestSequence, RerecordSequence)
sq->eval<kp::OpTensorSyncDevice>({ tensorA, tensorB, tensorOut });
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(R"(
std::vector<uint32_t> spirv = compileSource(R"(
#version 450
layout (local_size_x = 1) in;
@ -118,7 +118,7 @@ TEST(TestSequence, SequenceTimestamps)
pa[index] = pa[index] + 1;
})");
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
std::vector<uint32_t> spirv = compileSource(shader);
auto seq = mgr.sequence(0, 100); // 100 timestamps
seq->record<kp::OpTensorSyncDevice>({ tensorA })

View file

@ -20,7 +20,7 @@ TEST(TestSpecializationConstants, TestTwoConstants)
pb[index] = cTwo;
})");
std::vector<uint32_t> spirv = kp_test_utils::Shader::compileSource(shader);
std::vector<uint32_t> spirv = compileSource(shader);
std::shared_ptr<kp::Sequence> sq = nullptr;

View file

@ -1,20 +0,0 @@
#include "kompute/Kompute.hpp"
#include "kompute_test/Shader.hpp"
namespace kp_test_utils {
std::vector<uint32_t>
Shader::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())};
}
}

View file

@ -2,26 +2,26 @@
#include <iostream>
#include <vector>
namespace kp_test_utils {
#include <fstream>
/**
Shader utily class with functions to compile and process glsl files.
*/
class Shader
* Compile a single glslang source from string value. This is only meant
* to be used for testing as it's non threadsafe, and it had to be removed
* from the glslang dependency and now can only run the CLI directly due to
* license issues: see https://github.com/EthicalML/vulkan-kompute/pull/235
*
* @param source An individual raw glsl shader in string format
* @return The compiled SPIR-V binary in unsigned int32 format
*/
static
std::vector<uint32_t>
compileSource(
const std::string& source)
{
public:
/**
* Compile a single glslang source from string value. This is only meant
* to be used for testing as it's non threadsafe, and it had to be removed
* from the glslang dependency and now can only run the CLI directly due to
* license issues: see https://github.com/EthicalML/vulkan-kompute/pull/235
*
* @param source An individual raw glsl shader in string format
* @return The compiled SPIR-V binary in unsigned int32 format
*/
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())};
}