|
| 1 | +/* |
| 2 | + * Copyright (C) 2023 Intel Corporation |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +#include "framework/ocl/opencl.h" |
| 9 | +#include "framework/ocl/utility/program_helper_ocl.h" |
| 10 | +#include "framework/test_case/register_test_case.h" |
| 11 | +#include "framework/utility/timer.h" |
| 12 | + |
| 13 | +#include "definitions/enqueue_barrier_with_empty_waitlist.h" |
| 14 | + |
| 15 | +#include <cstring> |
| 16 | +#include <gtest/gtest.h> |
| 17 | + |
| 18 | +static TestResult run(const EnqueueBarrierWithEmptyWaitlistArguments &arguments, Statistics &statistics) { |
| 19 | + MeasurementFields typeSelector(MeasurementUnit::Microseconds, MeasurementType::Cpu); |
| 20 | + |
| 21 | + if (isNoopRun()) { |
| 22 | + statistics.pushUnitAndType(typeSelector.getUnit(), typeSelector.getType()); |
| 23 | + return TestResult::Nooped; |
| 24 | + } |
| 25 | + |
| 26 | + // Setup |
| 27 | + QueueProperties queueProperties = QueueProperties::create().setOoq(arguments.outOfOrderQueue); |
| 28 | + Opencl opencl(queueProperties); |
| 29 | + Timer timer{}; |
| 30 | + cl_int retVal{}; |
| 31 | + |
| 32 | + // Prepare data |
| 33 | + const size_t workgroupCount = 128; |
| 34 | + const size_t lws = 128; |
| 35 | + const size_t gws = lws * workgroupCount; |
| 36 | + const size_t enqueueCount = arguments.enqueueCount; |
| 37 | + if (enqueueCount == 0) { |
| 38 | + return TestResult::InvalidArgs; |
| 39 | + } |
| 40 | + |
| 41 | + // Create kernel |
| 42 | + cl_program program = nullptr; |
| 43 | + const char *programName = "ulls_benchmark_eat_time.cl"; |
| 44 | + const char *kernelName = "eat_time"; |
| 45 | + if (auto result = ProgramHelperOcl::buildProgramFromSourceFile(opencl.context, opencl.device, programName, nullptr, program); result != TestResult::Success) { |
| 46 | + return result; |
| 47 | + } |
| 48 | + cl_kernel kernel = clCreateKernel(program, kernelName, &retVal); |
| 49 | + ASSERT_CL_SUCCESS(retVal); |
| 50 | + const cl_int operationsCount = 1; |
| 51 | + ASSERT_CL_SUCCESS(clSetKernelArg(kernel, 0, sizeof(size_t), &operationsCount)); |
| 52 | + |
| 53 | + // Warmup |
| 54 | + { |
| 55 | + cl_event event{}; |
| 56 | + for (auto j = 0u; j < enqueueCount - 1; ++j) { |
| 57 | + ASSERT_CL_SUCCESS(clEnqueueNDRangeKernel(opencl.commandQueue, kernel, 1, nullptr, &gws, &lws, 0, nullptr, nullptr)); |
| 58 | + ASSERT_CL_SUCCESS(clEnqueueBarrierWithWaitList(opencl.commandQueue, 0, nullptr, nullptr)); |
| 59 | + } |
| 60 | + ASSERT_CL_SUCCESS(clEnqueueNDRangeKernel(opencl.commandQueue, kernel, 1, nullptr, &gws, &lws, 0, nullptr, nullptr)); |
| 61 | + ASSERT_CL_SUCCESS(clEnqueueBarrierWithWaitList(opencl.commandQueue, 0, nullptr, &event)); |
| 62 | + |
| 63 | + ASSERT_CL_SUCCESS(clWaitForEvents(1, &event)); |
| 64 | + ASSERT_CL_SUCCESS(clReleaseEvent(event)); |
| 65 | + } |
| 66 | + |
| 67 | + // Benchmark |
| 68 | + for (auto i = 0u; i < arguments.iterations; i++) { |
| 69 | + timer.measureStart(); |
| 70 | + { |
| 71 | + cl_event event{}; |
| 72 | + for (auto j = 0u; j < enqueueCount - 1; ++j) { |
| 73 | + ASSERT_CL_SUCCESS(clEnqueueNDRangeKernel(opencl.commandQueue, kernel, 1, nullptr, &gws, &lws, 0, nullptr, nullptr)); |
| 74 | + ASSERT_CL_SUCCESS(clEnqueueBarrierWithWaitList(opencl.commandQueue, 0, nullptr, nullptr)); |
| 75 | + } |
| 76 | + ASSERT_CL_SUCCESS(clEnqueueNDRangeKernel(opencl.commandQueue, kernel, 1, nullptr, &gws, &lws, 0, nullptr, nullptr)); |
| 77 | + ASSERT_CL_SUCCESS(clEnqueueBarrierWithWaitList(opencl.commandQueue, 0, nullptr, &event)); |
| 78 | + |
| 79 | + ASSERT_CL_SUCCESS(clWaitForEvents(1, &event)); |
| 80 | + ASSERT_CL_SUCCESS(clReleaseEvent(event)); |
| 81 | + } |
| 82 | + timer.measureEnd(); |
| 83 | + statistics.pushValue(timer.get(), typeSelector.getUnit(), typeSelector.getType()); |
| 84 | + } |
| 85 | + |
| 86 | + // Cleanup |
| 87 | + ASSERT_CL_SUCCESS(clReleaseKernel(kernel)); |
| 88 | + ASSERT_CL_SUCCESS(clReleaseProgram(program)); |
| 89 | + return TestResult::Success; |
| 90 | +} |
| 91 | + |
| 92 | +static RegisterTestCaseImplementation<EnqueueBarrierWithEmptyWaitlist> registerTestCase(run, Api::OpenCL); |
0 commit comments