remove cached benchmark

it wasn't doing what I expected, probably
This commit is contained in:
Kasper Sauramo
2025-11-10 09:32:01 +02:00
parent c40571d3a7
commit 7875e26ea2

View File

@@ -1,11 +1,11 @@
#include <vulkan/vulkan.h>
#include <vulkan/vulkan_core.h>
#include <chrono>
#include <cstring>
#include <iostream>
#include <limits>
#include <vector>
#include <vulkan/vulkan_core.h>
/// TODO: Pinned memory
/// TODO: Plot by buffer size
@@ -34,13 +34,9 @@ struct Gpu {
VkCommandPool pool = nullptr;
// for benchmarks
VkDeviceMemory stagingMem = nullptr;
VkDeviceMemory cachedMem = nullptr;
VkDeviceMemory deviceMem = nullptr;
VkDeviceMemory pinnedMem = nullptr;
VkBuffer stagingBuf = nullptr;
VkBuffer cachedBuf = nullptr;
VkBuffer deviceBuf = nullptr;
VkBuffer pinnedBuf = nullptr;
};
// ---------- helpers ----------
@@ -186,22 +182,6 @@ Gpu initGpu(VkPhysicalDevice phy, uint32_t buffer_size) {
gpu.deviceMem = allocateMem(gpu.device, phy, gpu.deviceBuf,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
gpu.cachedBuf = createBuffer(gpu.device, buffer_size,
VK_BUFFER_USAGE_TRANSFER_DST_BIT |
VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
gpu.cachedMem = allocateMem(gpu.device, phy, gpu.cachedBuf,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
VK_MEMORY_PROPERTY_HOST_CACHED_BIT);
gpu.pinnedBuf = createBuffer(gpu.device, buffer_size,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
VK_BUFFER_USAGE_TRANSFER_DST_BIT);
gpu.pinnedMem = allocateMem(gpu.device, phy, gpu.pinnedBuf,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
return gpu;
}
@@ -209,12 +189,8 @@ void cleanupGpu(Gpu &gpu) {
vkDestroyBuffer(gpu.device, gpu.stagingBuf, nullptr);
vkDestroyBuffer(gpu.device, gpu.deviceBuf, nullptr);
vkDestroyBuffer(gpu.device, gpu.cachedBuf, nullptr);
vkDestroyBuffer(gpu.device, gpu.pinnedBuf, nullptr);
vkFreeMemory(gpu.device, gpu.stagingMem, nullptr);
vkFreeMemory(gpu.device, gpu.deviceMem, nullptr);
vkFreeMemory(gpu.device, gpu.cachedMem, nullptr);
vkFreeMemory(gpu.device, gpu.pinnedMem, nullptr);
vkDestroyCommandPool(gpu.device, gpu.pool, nullptr);
vkDestroyDevice(gpu.device, nullptr);
}
@@ -266,35 +242,6 @@ BenchmarkResult runStagedBenchmark(Gpu &gpu, BenchmarkConfig config) {
return {tH2D, tD2H};
}
BenchmarkResult runCachedBenchmark(Gpu &gpu, BenchmarkConfig config) {
// fill staging buffer
void *mapped;
vkMapMemory(gpu.device, gpu.cachedMem, 0, config.buffer_size, 0, &mapped);
std::memset(mapped, 0xAB, config.buffer_size);
vkUnmapMemory(gpu.device, gpu.cachedMem);
// warm-up, probably not significant
benchCopy(gpu.device, gpu.pool, gpu.queue, gpu.cachedBuf, gpu.deviceBuf,
config.buffer_size);
// ---- benchmark host->device ----
double tH2D = 0.0;
for (uint32_t i = 0; i < config.iterations; ++i)
tH2D += benchCopy(gpu.device, gpu.pool, gpu.queue, gpu.cachedBuf,
gpu.pinnedBuf, config.buffer_size);
tH2D /= config.iterations;
// ---- benchmark device->host ----
double tD2H = 0.0;
for (uint32_t i = 0; i < config.iterations; ++i)
tD2H += benchCopy(gpu.device, gpu.pool, gpu.queue, gpu.pinnedBuf,
gpu.cachedBuf, config.buffer_size);
tD2H /= config.iterations;
return {tH2D, tD2H};
}
auto main() -> int {
VkApplicationInfo app{};
@@ -342,11 +289,6 @@ auto main() -> int {
std::cout << "Running staged benchmark" << std::endl;
BenchmarkResult res = runStagedBenchmark(gpu, config);
reportBenchmark(res, gpu, config);
std::cout << "Running cached benchmark" << std::endl;
res = runCachedBenchmark(gpu, config);
reportBenchmark(res, gpu, config);
std::cout << "--------------------" << std::endl;
}