mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
Initial commit
Change-Id: I4bf1707bd3dfeadf2c17b0a7daff372b1925ebbd
This commit is contained in:
150
unit_tests/mem_obj/image1d_tests.cpp
Normal file
150
unit_tests/mem_obj/image1d_tests.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "hw_cmds.h"
|
||||
#include "runtime/mem_obj/image.h"
|
||||
#include "runtime/mem_obj/buffer.h"
|
||||
#include "unit_tests/fixtures/device_fixture.h"
|
||||
#include "unit_tests/mocks/mock_context.h"
|
||||
#include "test.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
static const unsigned int testImageDimensions = 32;
|
||||
|
||||
class CreateImage1DTest : public DeviceFixture,
|
||||
public testing::TestWithParam<uint32_t /*cl_mem_object_type*/> {
|
||||
public:
|
||||
CreateImage1DTest() {
|
||||
}
|
||||
|
||||
protected:
|
||||
void SetUp() override {
|
||||
DeviceFixture::SetUp();
|
||||
types = GetParam();
|
||||
|
||||
// clang-format off
|
||||
imageFormat.image_channel_data_type = CL_UNORM_INT8;
|
||||
imageFormat.image_channel_order = CL_RGBA;
|
||||
|
||||
imageDesc.image_type = types;
|
||||
imageDesc.image_width = testImageDimensions;
|
||||
imageDesc.image_height = 0;
|
||||
imageDesc.image_depth = 0;
|
||||
imageDesc.image_array_size = 1;
|
||||
imageDesc.image_row_pitch = 0;
|
||||
imageDesc.image_slice_pitch = 0;
|
||||
imageDesc.num_mip_levels = 0;
|
||||
imageDesc.num_samples = 0;
|
||||
imageDesc.mem_object = NULL;
|
||||
// clang-format on
|
||||
|
||||
if (types == CL_MEM_OBJECT_IMAGE1D_ARRAY) {
|
||||
imageDesc.image_array_size = 10;
|
||||
}
|
||||
context = new MockContext(pDevice);
|
||||
|
||||
if (types == CL_MEM_OBJECT_IMAGE1D_BUFFER) {
|
||||
imageDesc.mem_object = clCreateBuffer(context, CL_MEM_ALLOC_HOST_PTR, testImageDimensions, nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
if (types == CL_MEM_OBJECT_IMAGE1D_BUFFER) {
|
||||
clReleaseMemObject(imageDesc.mem_object);
|
||||
}
|
||||
delete context;
|
||||
DeviceFixture::TearDown();
|
||||
}
|
||||
|
||||
cl_image_format imageFormat;
|
||||
cl_image_desc imageDesc;
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
MockContext *context;
|
||||
cl_mem_object_type types = 0;
|
||||
};
|
||||
|
||||
typedef CreateImage1DTest CreateImage1DType;
|
||||
|
||||
HWTEST_P(CreateImage1DType, validTypes) {
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE;
|
||||
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat);
|
||||
auto image = Image::create(
|
||||
context,
|
||||
flags,
|
||||
surfaceFormat,
|
||||
&imageDesc,
|
||||
nullptr,
|
||||
retVal);
|
||||
ASSERT_EQ(CL_SUCCESS, retVal);
|
||||
ASSERT_NE(nullptr, image);
|
||||
|
||||
auto imgDesc = image->getImageDesc();
|
||||
|
||||
EXPECT_NE(0u, imgDesc.image_width);
|
||||
EXPECT_EQ(0u, imgDesc.image_height);
|
||||
EXPECT_EQ(0u, imgDesc.image_depth);
|
||||
EXPECT_NE(0u, imgDesc.image_row_pitch);
|
||||
EXPECT_GE(imgDesc.image_slice_pitch, imgDesc.image_row_pitch);
|
||||
|
||||
size_t ImageInfoHeight = 0;
|
||||
retVal = clGetImageInfo(image, CL_IMAGE_HEIGHT, sizeof(size_t), &ImageInfoHeight, NULL);
|
||||
ASSERT_EQ(CL_SUCCESS, retVal);
|
||||
ASSERT_EQ(0u, ImageInfoHeight);
|
||||
|
||||
if ((types == CL_MEM_OBJECT_IMAGE1D) || (types == CL_MEM_OBJECT_IMAGE1D_BUFFER)) {
|
||||
EXPECT_EQ(0u, imgDesc.image_array_size);
|
||||
} else if (types == CL_MEM_OBJECT_IMAGE1D_ARRAY) {
|
||||
EXPECT_NE(0u, imgDesc.image_array_size);
|
||||
} else {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
|
||||
EXPECT_EQ(image->getCubeFaceIndex(), static_cast<uint32_t>(__GMM_NO_CUBE_MAP));
|
||||
|
||||
ASSERT_EQ(true, image->isMemObjZeroCopy());
|
||||
auto address = image->getCpuAddress();
|
||||
EXPECT_NE(nullptr, address);
|
||||
|
||||
if (types == CL_MEM_OBJECT_IMAGE1D_BUFFER) {
|
||||
Buffer *inputBuffer = castToObject<Buffer>(imageDesc.buffer);
|
||||
EXPECT_NE(nullptr, inputBuffer->getCpuAddress());
|
||||
EXPECT_EQ(inputBuffer->getCpuAddress(), image->getCpuAddress());
|
||||
EXPECT_TRUE(image->getIsObjectRedescribed());
|
||||
EXPECT_GE(2, inputBuffer->getRefInternalCount());
|
||||
}
|
||||
|
||||
typedef typename FamilyType::RENDER_SURFACE_STATE SURFACE_STATE;
|
||||
auto imageHw = static_cast<ImageHw<FamilyType> *>(image);
|
||||
EXPECT_EQ(SURFACE_STATE::SURFACE_TYPE_SURFTYPE_1D, imageHw->surfaceType);
|
||||
delete image;
|
||||
}
|
||||
|
||||
static cl_mem_object_type Image1DTypes[] = {
|
||||
CL_MEM_OBJECT_IMAGE1D,
|
||||
CL_MEM_OBJECT_IMAGE1D_BUFFER,
|
||||
CL_MEM_OBJECT_IMAGE1D_ARRAY};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
CreateImage1DTest_Create,
|
||||
CreateImage1DType,
|
||||
testing::ValuesIn(Image1DTypes));
|
||||
Reference in New Issue
Block a user