removing compute smoke test

This commit is contained in:
2026-08-26 11:42:49 -07:00
parent 99e06bbbb1
commit 027efebd48
2 changed files with 0 additions and 126 deletions
@@ -1,14 +0,0 @@
#pragma once
#include <string>
namespace sophia {
// Minimal end-to-end compute dispatch: compiles the GLSL compute shader at
// `computeShaderPath`, builds the descriptor/pipeline layer around a small
// storage buffer, dispatches it, reads the buffer back, and verifies the
// result against what the shader is expected to compute. Logs the outcome
// and throws std::runtime_error if the GPU result doesn't match.
void runComputeSmokeTest(const std::string& computeShaderPath);
} // namespace sophia
-112
View File
@@ -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