2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2018-03-30 01:44:20 +08:00
|
|
|
* Copyright (c) 2017 - 2018, Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "runtime/mem_obj/buffer.h"
|
|
|
|
#include "runtime/helpers/ptr_math.h"
|
|
|
|
#include "runtime/helpers/aligned_memory.h"
|
|
|
|
#include "unit_tests/command_queue/command_enqueue_fixture.h"
|
2018-02-07 21:48:24 +08:00
|
|
|
#include "unit_tests/fixtures/buffer_fixture.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "gen_cmd_parse.h"
|
|
|
|
#include "unit_tests/mocks/mock_context.h"
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
|
|
|
struct EnqueueWriteBufferRectTest : public CommandEnqueueFixture,
|
|
|
|
public ::testing::Test {
|
|
|
|
EnqueueWriteBufferRectTest(void)
|
|
|
|
: buffer(nullptr),
|
|
|
|
hostPtr(nullptr) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
CommandEnqueueFixture::SetUp();
|
2018-03-05 16:25:40 +08:00
|
|
|
context.reset(new MockContext(&pCmdQ->getDevice()));
|
|
|
|
BufferDefaults::context = context.get();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
//For 3D
|
|
|
|
hostPtr = ::alignedMalloc(slicePitch * rowPitch, 4096);
|
|
|
|
|
|
|
|
auto retVal = CL_INVALID_VALUE;
|
2018-02-07 21:48:24 +08:00
|
|
|
buffer.reset(Buffer::create(
|
2018-03-05 16:25:40 +08:00
|
|
|
context.get(),
|
2017-12-21 07:45:38 +08:00
|
|
|
CL_MEM_READ_WRITE,
|
|
|
|
slicePitch * rowPitch,
|
|
|
|
nullptr,
|
2018-02-07 21:48:24 +08:00
|
|
|
retVal));
|
|
|
|
|
|
|
|
nonZeroCopyBuffer.reset(BufferHelper<BufferUseHostPtr<>>::create());
|
|
|
|
|
|
|
|
ASSERT_NE(nullptr, buffer.get());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
2018-02-07 21:48:24 +08:00
|
|
|
buffer.reset(nullptr);
|
|
|
|
nonZeroCopyBuffer.reset(nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
::alignedFree(hostPtr);
|
2018-03-05 16:25:40 +08:00
|
|
|
context.reset(nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
CommandEnqueueFixture::TearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
template <typename FamilyType>
|
|
|
|
void enqueueWriteBufferRect2D(cl_bool blocking = CL_FALSE) {
|
|
|
|
typedef typename FamilyType::GPGPU_WALKER GPGPU_WALKER;
|
|
|
|
typedef typename FamilyType::PIPELINE_SELECT PIPELINE_SELECT;
|
|
|
|
|
|
|
|
size_t bufferOrigin[] = {0, 0, 0};
|
|
|
|
size_t hostOrigin[] = {0, 0, 0};
|
|
|
|
size_t region[] = {50, 50, 1};
|
|
|
|
auto retVal = pCmdQ->enqueueWriteBufferRect(
|
2018-02-07 21:48:24 +08:00
|
|
|
buffer.get(),
|
2017-12-21 07:45:38 +08:00
|
|
|
blocking,
|
|
|
|
bufferOrigin,
|
|
|
|
hostOrigin,
|
|
|
|
region,
|
|
|
|
rowPitch,
|
|
|
|
slicePitch,
|
|
|
|
rowPitch,
|
|
|
|
slicePitch,
|
|
|
|
hostPtr,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
parseCommands<FamilyType>(*pCmdQ);
|
|
|
|
}
|
|
|
|
|
2018-03-05 16:25:40 +08:00
|
|
|
std::unique_ptr<MockContext> context;
|
2018-02-07 21:48:24 +08:00
|
|
|
std::unique_ptr<Buffer> buffer;
|
|
|
|
std::unique_ptr<Buffer> nonZeroCopyBuffer;
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
void *hostPtr;
|
|
|
|
|
|
|
|
static const size_t rowPitch = 100;
|
|
|
|
static const size_t slicePitch = 100 * 100;
|
|
|
|
};
|
2018-02-07 21:48:24 +08:00
|
|
|
} // namespace OCLRT
|