mirror of
https://github.com/Tencent/ncnn.git
synced 2026-10-29 04:17:40 +08:00
print gpu per layer benchmark
This commit is contained in:
+104
@@ -168,6 +168,11 @@ int Command::queue_submit_and_wait_fence()
|
||||
|
||||
VkCompute::VkCompute(const VulkanDevice* _vkdev) : Command(_vkdev, _vkdev->info.compute_queue_family_index)
|
||||
{
|
||||
#if NCNN_BENCHMARK
|
||||
query_count = 0;
|
||||
query_pool = 0;
|
||||
#endif // NCNN_BENCHMARK
|
||||
|
||||
if (vkdev->info.support_VK_KHR_push_descriptor)
|
||||
{
|
||||
begin_command_buffer();
|
||||
@@ -184,6 +189,13 @@ VkCompute::~VkCompute()
|
||||
vkDestroyDescriptorPool(vkdev->vkdevice(), descriptor_pools[i], 0);
|
||||
}
|
||||
}
|
||||
|
||||
#if NCNN_BENCHMARK
|
||||
if (query_pool)
|
||||
{
|
||||
vkDestroyQueryPool(vkdev->vkdevice(), query_pool, 0);
|
||||
}
|
||||
#endif // NCNN_BENCHMARK
|
||||
}
|
||||
|
||||
void VkCompute::record_upload(const VkMat& m)
|
||||
@@ -294,6 +306,19 @@ void VkCompute::record_pipeline(const Pipeline* pipeline, const std::vector<VkMa
|
||||
record_dispatch(group_count_xyz);
|
||||
}
|
||||
|
||||
#if NCNN_BENCHMARK
|
||||
void VkCompute::record_write_timestamp(uint32_t query)
|
||||
{
|
||||
if (vkdev->info.support_VK_KHR_push_descriptor)
|
||||
return write_timestamp(query);
|
||||
|
||||
record_type r;
|
||||
r.type = 10;
|
||||
r.write_timestamp.query = query;
|
||||
delayed_records.push_back(r);
|
||||
}
|
||||
#endif // NCNN_BENCHMARK
|
||||
|
||||
void VkCompute::record_bind_pipeline(VkPipeline pipeline)
|
||||
{
|
||||
if (vkdev->info.support_VK_KHR_push_descriptor)
|
||||
@@ -516,6 +541,10 @@ int VkCompute::submit_and_wait()
|
||||
|
||||
begin_command_buffer();
|
||||
|
||||
#if NCNN_BENCHMARK
|
||||
reset_query_pool();
|
||||
#endif // NCNN_BENCHMARK
|
||||
|
||||
// handle delayed records
|
||||
for (size_t i=0; i<delayed_records.size(); i++)
|
||||
{
|
||||
@@ -553,6 +582,11 @@ int VkCompute::submit_and_wait()
|
||||
case 9:
|
||||
transfer_transfer_barrier(r.compute_compute_barrier.buffer, r.compute_compute_barrier.offset, r.compute_compute_barrier.size);
|
||||
break;
|
||||
#if NCNN_BENCHMARK
|
||||
case 10:
|
||||
write_timestamp(r.write_timestamp.query);
|
||||
break;
|
||||
#endif // NCNN_BENCHMARK
|
||||
}
|
||||
}
|
||||
|
||||
@@ -584,11 +618,63 @@ int VkCompute::reset()
|
||||
if (vkdev->info.support_VK_KHR_push_descriptor)
|
||||
{
|
||||
begin_command_buffer();
|
||||
|
||||
#if NCNN_BENCHMARK
|
||||
reset_query_pool();
|
||||
#endif // NCNN_BENCHMARK
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if NCNN_BENCHMARK
|
||||
int VkCompute::create_query_pool(uint32_t _query_count)
|
||||
{
|
||||
query_count = _query_count;
|
||||
|
||||
VkQueryPoolCreateInfo queryPoolCreateInfo;
|
||||
queryPoolCreateInfo.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
|
||||
queryPoolCreateInfo.pNext = 0;
|
||||
queryPoolCreateInfo.flags = 0;
|
||||
queryPoolCreateInfo.queryType = VK_QUERY_TYPE_TIMESTAMP;
|
||||
queryPoolCreateInfo.queryCount = query_count;
|
||||
queryPoolCreateInfo.pipelineStatistics = 0;
|
||||
|
||||
VkResult ret = vkCreateQueryPool(vkdev->vkdevice(), &queryPoolCreateInfo, 0, &query_pool);
|
||||
if (ret != VK_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "vkCreateQueryPool failed %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vkdev->info.support_VK_KHR_push_descriptor)
|
||||
{
|
||||
reset_query_pool();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VkCompute::get_query_pool_results(uint32_t first_query, uint32_t query_count, std::vector<uint64_t>& results)
|
||||
{
|
||||
if (results.size() < first_query + query_count)
|
||||
{
|
||||
fprintf(stderr, "results not large enough\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
VkResult ret = vkGetQueryPoolResults(vkdev->vkdevice(), query_pool, first_query, query_count,
|
||||
query_count * sizeof(uint64_t), results.data() + first_query, sizeof(uint64_t), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
|
||||
if (ret != VK_SUCCESS && ret != VK_NOT_READY)
|
||||
{
|
||||
fprintf(stderr, "vkGetQueryPoolResults failed %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif // NCNN_BENCHMARK
|
||||
|
||||
void VkCompute::copy_buffer(VkBuffer src, size_t src_offset, VkBuffer dst, size_t dst_offset, size_t size)
|
||||
{
|
||||
// fprintf(stderr, "cmd copy %p to %p\n", src, dst);
|
||||
@@ -727,6 +813,24 @@ void VkCompute::transfer_transfer_barrier(VkBuffer buffer, size_t offset, size_t
|
||||
vkCmdPipelineBarrier(command_buffer, srcStageMask, dstStageMask, 0, 0, 0, 1, &bufferBarrier, 0, 0);
|
||||
}
|
||||
|
||||
#if NCNN_BENCHMARK
|
||||
void VkCompute::reset_query_pool()
|
||||
{
|
||||
// fprintf(stderr, "cmd reset_query_pool\n");
|
||||
|
||||
if (query_pool)
|
||||
vkCmdResetQueryPool(command_buffer, query_pool, 0, query_count);
|
||||
}
|
||||
|
||||
void VkCompute::write_timestamp(uint32_t query)
|
||||
{
|
||||
// fprintf(stderr, "cmd write_timestamp %u\n", query);
|
||||
|
||||
if (query_pool)
|
||||
vkCmdWriteTimestamp(command_buffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, query_pool, query);
|
||||
}
|
||||
#endif // NCNN_BENCHMARK
|
||||
|
||||
VkTransfer::VkTransfer(const VulkanDevice* _vkdev) : Command(_vkdev, _vkdev->info.transfer_queue_family_index)
|
||||
{
|
||||
buffer_offset_alignment = vkdev->info.buffer_offset_alignment;
|
||||
|
||||
Reference in New Issue
Block a user