removing compute smoke test
This commit is contained in:
@@ -1,112 +0,0 @@
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <sophia/compute_smoke_test.hpp>
|
||||
#include <sophia/util/logger.hpp>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include "buffer.hpp"
|
||||
#include "descriptors/descriptor_pool.hpp"
|
||||
#include "descriptors/descriptor_set_layout.hpp"
|
||||
#include "descriptors/descriptor_writer.hpp"
|
||||
#include "device.hpp"
|
||||
#include "pipelines/compute_pipeline.hpp"
|
||||
#include "shader.hpp"
|
||||
|
||||
namespace sophia {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr u32 kElementCount = 256;
|
||||
constexpr u32 kWorkgroupSize = 64;
|
||||
|
||||
} // namespace
|
||||
|
||||
void runComputeSmokeTest(const std::string& computeShaderPath) {
|
||||
auto device = Device::Builder().headless().build();
|
||||
|
||||
Buffer buffer{*device, sizeof(f32), kElementCount,
|
||||
vk::BufferUsageFlagBits::eStorageBuffer,
|
||||
vk::MemoryPropertyFlagBits::eHostVisible |
|
||||
vk::MemoryPropertyFlagBits::eHostCoherent};
|
||||
|
||||
std::vector<f32> input(kElementCount);
|
||||
for (u32 i = 0; i < kElementCount; i++) {
|
||||
input[i] = static_cast<f32>(i);
|
||||
}
|
||||
|
||||
buffer.map();
|
||||
buffer.writeToBuffer(input.data(), sizeof(f32) * kElementCount);
|
||||
buffer.unmap();
|
||||
|
||||
auto shader = Shader::Builder()
|
||||
.fromGLSL(computeShaderPath)
|
||||
.setStage(ShaderStage::COMPUTE)
|
||||
.build();
|
||||
|
||||
auto setLayout = DescriptorSetLayout::Builder(*device)
|
||||
.addBinding(0, vk::DescriptorType::eStorageBuffer,
|
||||
vk::ShaderStageFlagBits::eCompute)
|
||||
.build();
|
||||
|
||||
auto pool = DescriptorPool::Builder(*device)
|
||||
.addPoolSize(vk::DescriptorType::eStorageBuffer, 1)
|
||||
.setMaxSets(1)
|
||||
.build();
|
||||
|
||||
vk::DescriptorBufferInfo bufferInfo = buffer.descriptorInfo();
|
||||
vk::DescriptorSet descriptorSet;
|
||||
if (!DescriptorWriter(*setLayout, *pool)
|
||||
.writeBuffer(0, &bufferInfo)
|
||||
.build(descriptorSet)) {
|
||||
log::fatal("compute smoke test: failed to allocate descriptor set");
|
||||
throw std::runtime_error(
|
||||
"compute smoke test: failed to allocate descriptor set");
|
||||
}
|
||||
|
||||
vk::DescriptorSetLayout rawSetLayout = setLayout->getDescriptorSetLayout();
|
||||
vk::PipelineLayoutCreateInfo pipelineLayoutInfo{};
|
||||
pipelineLayoutInfo.setLayoutCount = 1;
|
||||
pipelineLayoutInfo.pSetLayouts = &rawSetLayout;
|
||||
|
||||
vk::UniquePipelineLayout pipelineLayout =
|
||||
device->get()->createPipelineLayoutUnique(pipelineLayoutInfo);
|
||||
|
||||
std::unique_ptr<sophia::ComputePipeline> computePipeline =
|
||||
ComputePipeline::Builder(*device)
|
||||
.setShader(*shader)
|
||||
.setPipelineLayout(pipelineLayout.get())
|
||||
.build();
|
||||
|
||||
vk::CommandBuffer commandBuffer = device->beginSingleTimeCommands();
|
||||
computePipeline->bind(commandBuffer);
|
||||
commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eCompute,
|
||||
pipelineLayout.get(), 0, descriptorSet, {});
|
||||
commandBuffer.dispatch((kElementCount + kWorkgroupSize - 1) / kWorkgroupSize,
|
||||
1, 1);
|
||||
device->endSingleTimeCommands(commandBuffer);
|
||||
|
||||
std::vector<f32> output(kElementCount);
|
||||
buffer.map();
|
||||
std::memcpy(output.data(), buffer.getMappedMemory(),
|
||||
sizeof(f32) * kElementCount);
|
||||
buffer.unmap();
|
||||
|
||||
u32 mismatches = 0;
|
||||
for (u32 i = 0; i < kElementCount; i++) {
|
||||
f32 expected = input[i] * 2.0f;
|
||||
if (std::fabs(output[i] - expected) > 1e-4f) {
|
||||
mismatches++;
|
||||
}
|
||||
}
|
||||
|
||||
if (mismatches > 0) {
|
||||
log::fatal("compute smoke test FAILED:", mismatches, "/", kElementCount,
|
||||
"elements mismatched");
|
||||
throw std::runtime_error("compute smoke test: GPU result did not match");
|
||||
}
|
||||
|
||||
log::info("compute smoke test PASSED:", kElementCount, "elements verified");
|
||||
}
|
||||
|
||||
} // namespace sophia
|
||||
Reference in New Issue
Block a user