From 368afc25933df4e7e55b987b6befbab5592d976c Mon Sep 17 00:00:00 2001 From: Joshua Santosh Ranjan Date: Tue, 5 Nov 2024 10:14:35 +0000 Subject: [PATCH] test: support additional parameters for copy workload Related-To: NEO-12811 Signed-off-by: Joshua Santosh Ranjan --- .../zello_metrics/zello_metrics.h | 13 ++++-- .../zello_metrics/zello_metrics_workload.cpp | 46 +++++++++++++------ 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/level_zero/tools/test/black_box_tests/zello_metrics/zello_metrics.h b/level_zero/tools/test/black_box_tests/zello_metrics/zello_metrics.h index 5b0d8ce689..5abff363bf 100644 --- a/level_zero/tools/test/black_box_tests/zello_metrics/zello_metrics.h +++ b/level_zero/tools/test/black_box_tests/zello_metrics/zello_metrics.h @@ -181,20 +181,27 @@ class AppendMemoryCopyFromHeapToDeviceAndBackToHost : public Workload { class CopyBufferToBuffer : public Workload { public: - CopyBufferToBuffer(ExecutionContext *execCtxt) : Workload(execCtxt) { initialize(); } + CopyBufferToBuffer(ExecutionContext *execCtxt) : Workload(execCtxt) { initialize(nullptr, nullptr, 0); } + CopyBufferToBuffer(ExecutionContext *execCtxt, void *srcAddress, void *dstAddress, uint32_t size) : Workload(execCtxt) { initialize(srcAddress, dstAddress, size); } ~CopyBufferToBuffer() override { finalize(); }; bool appendCommands() override; bool validate() override; + void setValidationStatus(bool status) { + isValidationEnabled = status; + } private: - void initialize(); + void initialize(void *src, void *dst, uint32_t size); void finalize(); - const uint32_t allocationSize = 4096; + uint32_t allocationSize = 4096; void *sourceBuffer = nullptr; void *destinationBuffer = nullptr; ze_module_handle_t module = nullptr; ze_kernel_handle_t kernel = nullptr; bool executeFromSpirv = false; + bool isSourceBufferAllocated = false; + bool isDestinationBufferAllocated = false; + bool isValidationEnabled = true; }; class SingleMetricCollector : public Collector { diff --git a/level_zero/tools/test/black_box_tests/zello_metrics/zello_metrics_workload.cpp b/level_zero/tools/test/black_box_tests/zello_metrics/zello_metrics_workload.cpp index 1cea93c7ca..6c4ea8594f 100644 --- a/level_zero/tools/test/black_box_tests/zello_metrics/zello_metrics_workload.cpp +++ b/level_zero/tools/test/black_box_tests/zello_metrics/zello_metrics_workload.cpp @@ -69,7 +69,11 @@ void AppendMemoryCopyFromHeapToDeviceAndBackToHost::finalize() { //////////////////////// /////CopyBufferToBuffer //////////////////////// -void CopyBufferToBuffer::initialize() { +void CopyBufferToBuffer::initialize(void *src, void *dst, uint32_t size) { + + sourceBuffer = src; + destinationBuffer = dst; + allocationSize = size != 0u ? size : allocationSize; ze_device_mem_alloc_desc_t deviceDesc = {ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC}; deviceDesc.flags = ZE_DEVICE_MEM_ALLOC_FLAG_BIAS_UNCACHED; @@ -78,16 +82,21 @@ void CopyBufferToBuffer::initialize() { ze_host_mem_alloc_desc_t hostDesc = {ZE_STRUCTURE_TYPE_HOST_MEM_ALLOC_DESC}; hostDesc.flags = ZE_DEVICE_MEM_ALLOC_FLAG_BIAS_UNCACHED; - VALIDATECALL(zeMemAllocShared(executionCtxt->getContextHandle(0), &deviceDesc, &hostDesc, - allocationSize, 1, executionCtxt->getDeviceHandle(0), - &sourceBuffer)); - VALIDATECALL(zeMemAllocShared(executionCtxt->getContextHandle(0), &deviceDesc, &hostDesc, - allocationSize, 1, executionCtxt->getDeviceHandle(0), - &destinationBuffer)); + if (sourceBuffer == nullptr) { + VALIDATECALL(zeMemAllocShared(executionCtxt->getContextHandle(0), &deviceDesc, &hostDesc, + allocationSize, 1, executionCtxt->getDeviceHandle(0), + &sourceBuffer)); + isSourceBufferAllocated = true; + memset(sourceBuffer, 55, allocationSize); + } - // Initialize memory - memset(sourceBuffer, 55, allocationSize); - memset(destinationBuffer, 0, allocationSize); + if (destinationBuffer == nullptr) { + VALIDATECALL(zeMemAllocShared(executionCtxt->getContextHandle(0), &deviceDesc, &hostDesc, + allocationSize, 1, executionCtxt->getDeviceHandle(0), + &destinationBuffer)); + isDestinationBufferAllocated = true; + memset(destinationBuffer, 0, allocationSize); + } std::ifstream file("copy_buffer_to_buffer.spv", std::ios::binary); @@ -130,7 +139,8 @@ void CopyBufferToBuffer::initialize() { bool CopyBufferToBuffer::appendCommands() { if (executeFromSpirv) { - uint32_t groupSizeX = 32u; + LOG(zmu::LogLevel::DEBUG) << "Using copy_buffer_to_buffer.spv" << std::endl; + uint32_t groupSizeX = std::min(32u, allocationSize); uint32_t groupSizeY = 1u; uint32_t groupSizeZ = 1u; VALIDATECALL(zeKernelSuggestGroupSize(kernel, allocationSize, 1U, 1U, &groupSizeX, &groupSizeY, &groupSizeZ)); @@ -160,6 +170,11 @@ bool CopyBufferToBuffer::appendCommands() { } bool CopyBufferToBuffer::validate() { + + if (!isValidationEnabled) { + return true; + } + // Validate. const bool outputValidationSuccessful = (memcmp(destinationBuffer, sourceBuffer, allocationSize) == 0); @@ -185,8 +200,13 @@ bool CopyBufferToBuffer::validate() { void CopyBufferToBuffer::finalize() { - VALIDATECALL(zeMemFree(executionCtxt->getContextHandle(0), sourceBuffer)); - VALIDATECALL(zeMemFree(executionCtxt->getContextHandle(0), destinationBuffer)); + if (isSourceBufferAllocated) { + VALIDATECALL(zeMemFree(executionCtxt->getContextHandle(0), sourceBuffer)); + } + + if (isDestinationBufferAllocated) { + VALIDATECALL(zeMemFree(executionCtxt->getContextHandle(0), destinationBuffer)); + } if (kernel) { zeKernelDestroy(kernel);