CoolFace
Datasetpublic

GSaha567/seq_level_training_data

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes52downloads
shard_000073.csv92116 linesDownload Raw Back to root
1text,length,is_long_context,metric_val,label_metric2"/*3 * Copyright (C) 2017-2021 Intel Corporation4 *5 * SPDX-License-Identifier: MIT6 *7 */8 9#include ""shared/source/built_ins/built_ins.h""10#include ""shared/source/compiler_interface/compiler_interface.h""11#include ""shared/source/helpers/aligned_memory.h""12#include ""shared/source/image/image_surface_state.h""13#include ""shared/source/os_interface/os_context.h""14#include ""shared/test/common/helpers/debug_manager_state_restore.h""15#include ""shared/test/common/helpers/unit_test_helper.h""16#include ""shared/test/common/test_macros/test_checks_shared.h""17 18#include ""opencl/source/helpers/mipmap.h""19#include ""opencl/source/mem_obj/image.h""20#include ""opencl/source/mem_obj/mem_obj_helper.h""21#include ""opencl/test/unit_test/command_queue/command_queue_fixture.h""22#include ""opencl/test/unit_test/fixtures/cl_device_fixture.h""23#include ""opencl/test/unit_test/fixtures/image_fixture.h""24#include ""opencl/test/unit_test/fixtures/memory_management_fixture.h""25#include ""opencl/test/unit_test/fixtures/multi_root_device_fixture.h""26#include ""opencl/test/unit_test/helpers/kernel_binary_helper.h""27#include ""opencl/test/unit_test/mem_obj/image_compression_fixture.h""28#include ""opencl/test/unit_test/mocks/mock_allocation_properties.h""29#include ""opencl/test/unit_test/mocks/mock_context.h""30#include ""opencl/test/unit_test/mocks/mock_gmm.h""31#include ""opencl/test/unit_test/mocks/mock_memory_manager.h""32#include ""opencl/test/unit_test/mocks/mock_platform.h""33#include ""test.h""34 35using namespace NEO;36 37static const unsigned int testImageDimensions = 45;38auto channelType = CL_UNORM_INT8;39auto channelOrder = CL_RGBA;40auto const elementSize = 4; //sizeof CL_RGBA * CL_UNORM_INT841 42class CreateImageTest : public ClDeviceFixture,43                        public testing::TestWithParam<uint64_t /*cl_mem_flags*/>,44                        public CommandQueueHwFixture {45    typedef CommandQueueHwFixture CommandQueueFixture;46 47  public:48    CreateImageTest() {49    }50    Image *createImageWithFlags(cl_mem_flags flags) {51        auto surfaceFormat = Image::getSurfaceFormatFromTable(52            flags, &imageFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);53        return Image::create(context, MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()),54                             flags, 0, surfaceFormat, &imageDesc, nullptr, retVal);55    }56 57  protected:58    void SetUp() override {59        ClDeviceFixture::SetUp();60 61        CommandQueueFixture::SetUp(pClDevice, 0);62        flags = GetParam();63 64        // clang-format off65        imageFormat.image_channel_data_type = channelType;66        imageFormat.image_channel_order     = channelOrder;67 68        imageDesc.image_type        = CL_MEM_OBJECT_IMAGE2D;69        imageDesc.image_width       = testImageDimensions;70        imageDesc.image_height      = testImageDimensions;71        imageDesc.image_depth       = 0;72        imageDesc.image_array_size  = 1;73        imageDesc.image_row_pitch   = 0;74        imageDesc.image_slice_pitch = 0;75        imageDesc.num_mip_levels    = 0;76        imageDesc.num_samples       = 0;77        imageDesc.mem_object = NULL;78        // clang-format on79    }80 81    void TearDown() override {82        CommandQueueFixture::TearDown();83        ClDeviceFixture::TearDown();84    }85 86    cl_image_format imageFormat;87    cl_image_desc imageDesc;88    cl_int retVal = CL_SUCCESS;89    cl_mem_flags flags = 0;90    unsigned char pHostPtr[testImageDimensions * testImageDimensions * elementSize * 4];91};92 93typedef CreateImageTest CreateImageNoHostPtr;94 95TEST(TestSliceAndRowPitch, Given1dImageWithZeroRowPitchAndZeroSlicePitchWhenGettingHostPtrSlicePitchAndRowPitchThenCorrectValuesAreReturned) {96    DebugManagerStateRestore dbgRestorer;97    DebugManager.flags.ForceLinearImages.set(true);98 99    cl_image_format imageFormat;100    cl_image_desc imageDesc;101    cl_int retVal;102    MockContext context;103 104    const size_t width = 5;105    const size_t height = 3;106    const size_t depth = 2;107    char *hostPtr = (char *)alignedMalloc(width * height * depth * elementSize * 2, 64);108 109    imageFormat.image_channel_data_type = channelType;110    imageFormat.image_channel_order = channelOrder;111 112    imageDesc.num_mip_levels = 0;113    imageDesc.num_samples = 0;114    imageDesc.mem_object = NULL;115 116    // 1D image with 0 row_pitch and 0 slice_pitch117    imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D;118    imageDesc.image_width = width;119    imageDesc.image_height = 0;120    imageDesc.image_depth = 0;121    imageDesc.image_array_size = 0;122    imageDesc.image_row_pitch = 0;123    imageDesc.image_slice_pitch = 0;124 125    cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;126    auto surfaceFormat = Image::getSurfaceFormatFromTable(127        flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);128    auto image = Image::create(129        &context,130        MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),131        flags,132        0,133        surfaceFormat,134        &imageDesc,135        hostPtr,136        retVal);137    ASSERT_NE(nullptr, image);138 139    EXPECT_EQ(width * elementSize, image->getHostPtrRowPitch());140    EXPECT_EQ(0u, image->getHostPtrSlicePitch());141 142    delete image;143    alignedFree(hostPtr);144}145 146TEST(TestSliceAndRowPitch, Given1dImageWithNonZeroRowPitchAndZeroSlicePitchWhenGettingHostPtrSlicePitchAndRowPitchThenCorrectValuesAreReturned) {147    DebugManagerStateRestore dbgRestorer;148    DebugManager.flags.ForceLinearImages.set(true);149 150    cl_image_format imageFormat;151    cl_image_desc imageDesc;152    cl_int retVal;153    MockContext context;154 155    const size_t width = 5;156    const size_t height = 3;157    const size_t depth = 2;158    char *hostPtr = (char *)alignedMalloc(width * height * depth * elementSize * 2, 64);159 160    imageFormat.image_channel_data_type = channelType;161    imageFormat.image_channel_order = channelOrder;162 163    imageDesc.num_mip_levels = 0;164    imageDesc.num_samples = 0;165    imageDesc.mem_object = NULL;166 167    // 1D image with non-zero row_pitch and 0 slice_pitch168    imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D;169    imageDesc.image_width = width;170    imageDesc.image_height = 0;171    imageDesc.image_depth = 0;172    imageDesc.image_array_size = 0;173    imageDesc.image_row_pitch = (width + 1) * elementSize;174    imageDesc.image_slice_pitch = 0;175 176    cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;177    auto surfaceFormat = Image::getSurfaceFormatFromTable(178        flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);179    auto image = Image::create(180        &context,181        MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),182        flags,183        0,184        surfaceFormat,185        &imageDesc,186        hostPtr,187        retVal);188    ASSERT_NE(nullptr, image);189 190    EXPECT_EQ((width + 1) * elementSize, image->getHostPtrRowPitch());191    EXPECT_EQ(0u, image->getHostPtrSlicePitch());192 193    delete image;194    alignedFree(hostPtr);195}196 197TEST(TestSliceAndRowPitch, Given2dImageWithNonZeroRowPitchAndZeroSlicePitchWhenGettingHostPtrSlicePitchAndRowPitchThenCorrectValuesAreReturned) {198    DebugManagerStateRestore dbgRestorer;199    DebugManager.flags.ForceLinearImages.set(true);200 201    cl_image_format imageFormat;202    cl_image_desc imageDesc;203    cl_int retVal;204    MockContext context;205 206    const size_t width = 5;207    const size_t height = 3;208    const size_t depth = 2;209    char *hostPtr = (char *)alignedMalloc(width * height * depth * elementSize * 2, 64);210 211    imageFormat.image_channel_data_type = channelType;212    imageFormat.image_channel_order = channelOrder;213 214    imageDesc.num_mip_levels = 0;215    imageDesc.num_samples = 0;216    imageDesc.mem_object = NULL;217 218    // 2D image with non-zero row_pitch and 0 slice_pitch219    imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;220    imageDesc.image_width = width;221    imageDesc.image_height = height;222    imageDesc.image_depth = 0;223    imageDesc.image_array_size = 0;224    imageDesc.image_row_pitch = (width + 1) * elementSize;225    imageDesc.image_slice_pitch = 0;226 227    cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;228    auto surfaceFormat = Image::getSurfaceFormatFromTable(229        flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);230    auto image = Image::create(231        &context,232        MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),233        flags,234        0,235        surfaceFormat,236        &imageDesc,237        hostPtr,238        retVal);239    ASSERT_NE(nullptr, image);240 241    EXPECT_EQ((width + 1) * elementSize, image->getHostPtrRowPitch());242    EXPECT_EQ(0u, image->getHostPtrSlicePitch());243 244    delete image;245    alignedFree(hostPtr);246}247 248TEST(TestSliceAndRowPitch, Given1dArrayWithNonZeroRowPitchAndZeroSlicePitchWhenGettingHostPtrSlicePitchAndRowPitchThenCorrectValuesAreReturned) {249    DebugManagerStateRestore dbgRestorer;250    DebugManager.flags.ForceLinearImages.set(true);251 252    cl_image_format imageFormat;253    cl_image_desc imageDesc;254    cl_int retVal;255    MockContext context;256 257    const size_t width = 5;258    const size_t height = 3;259    const size_t depth = 2;260    char *hostPtr = (char *)alignedMalloc(width * height * depth * elementSize * 2, 64);261 262    imageFormat.image_channel_data_type = channelType;263    imageFormat.image_channel_order = channelOrder;264 265    imageDesc.num_mip_levels = 0;266    imageDesc.num_samples = 0;267    imageDesc.mem_object = NULL;268 269    // 1D ARRAY image with non-zero row_pitch and 0 slice_pitch270    imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;271    imageDesc.image_width = width;272    imageDesc.image_height = 0;273    imageDesc.image_depth = 0;274    imageDesc.image_array_size = 2;275    imageDesc.image_row_pitch = (width + 1) * elementSize;276    imageDesc.image_slice_pitch = 0;277 278    cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;279    auto surfaceFormat = Image::getSurfaceFormatFromTable(280        flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);281    auto image = Image::create(282        &context,283        MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),284        flags,285        0,286        surfaceFormat,287        &imageDesc,288        hostPtr,289        retVal);290    ASSERT_NE(nullptr, image);291 292    EXPECT_EQ((width + 1) * elementSize, image->getHostPtrRowPitch());293    EXPECT_EQ((width + 1) * elementSize, image->getHostPtrSlicePitch());294 295    delete image;296    alignedFree(hostPtr);297}298 299TEST(TestSliceAndRowPitch, Given2dArrayWithNonZeroRowPitchAndZeroSlicePitchWhenGettingHostPtrSlicePitchAndRowPitchThenCorrectValuesAreReturned) {300    DebugManagerStateRestore dbgRestorer;301    DebugManager.flags.ForceLinearImages.set(true);302 303    cl_image_format imageFormat;304    cl_image_desc imageDesc;305    cl_int retVal;306    MockContext context;307 308    const size_t width = 5;309    const size_t height = 3;310    const size_t depth = 2;311    char *hostPtr = (char *)alignedMalloc(width * height * depth * elementSize * 2, 64);312 313    imageFormat.image_channel_data_type = channelType;314    imageFormat.image_channel_order = channelOrder;315 316    imageDesc.num_mip_levels = 0;317    imageDesc.num_samples = 0;318    imageDesc.mem_object = NULL;319 320    // 2D ARRAY image with non-zero row_pitch and 0 slice_pitch321    imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;322    imageDesc.image_width = width;323    imageDesc.image_height = height;324    imageDesc.image_depth = 0;325    imageDesc.image_array_size = 2;326    imageDesc.image_row_pitch = (width + 1) * elementSize;327    imageDesc.image_slice_pitch = 0;328 329    cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;330    auto surfaceFormat = Image::getSurfaceFormatFromTable(331        flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);332    auto image = Image::create(333        &context,334        MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),335        flags,336        0,337        surfaceFormat,338        &imageDesc,339        hostPtr,340        retVal);341    ASSERT_NE(nullptr, image);342 343    EXPECT_EQ((width + 1) * elementSize, image->getHostPtrRowPitch());344    EXPECT_EQ((width + 1) * elementSize * height, image->getHostPtrSlicePitch());345 346    delete image;347    alignedFree(hostPtr);348}349 350TEST(TestSliceAndRowPitch, Given2dArrayWithZeroRowPitchAndNonZeroSlicePitchWhenGettingHostPtrSlicePitchAndRowPitchThenCorrectValuesAreReturned) {351    DebugManagerStateRestore dbgRestorer;352    DebugManager.flags.ForceLinearImages.set(true);353 354    cl_image_format imageFormat;355    cl_image_desc imageDesc;356    cl_int retVal;357    MockContext context;358 359    const size_t width = 5;360    const size_t height = 3;361    const size_t depth = 2;362    char *hostPtr = (char *)alignedMalloc(width * height * depth * elementSize * 2, 64);363 364    imageFormat.image_channel_data_type = channelType;365    imageFormat.image_channel_order = channelOrder;366 367    imageDesc.num_mip_levels = 0;368    imageDesc.num_samples = 0;369    imageDesc.mem_object = NULL;370 371    // 2D ARRAY image with zero row_pitch and non-zero slice_pitch372    imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;373    imageDesc.image_width = width;374    imageDesc.image_height = height;375    imageDesc.image_depth = 0;376    imageDesc.image_array_size = 2;377    imageDesc.image_row_pitch = 0;378    imageDesc.image_slice_pitch = (width + 1) * elementSize * height;379 380    cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;381    auto surfaceFormat = Image::getSurfaceFormatFromTable(382        flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);383    auto image = Image::create(384        &context,385        MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),386        flags,387        0,388        surfaceFormat,389        &imageDesc,390        hostPtr,391        retVal);392    ASSERT_NE(nullptr, image);393 394    EXPECT_EQ(width * elementSize, image->getHostPtrRowPitch());395    EXPECT_EQ((width + 1) * elementSize * height, image->getHostPtrSlicePitch());396 397    delete image;398    alignedFree(hostPtr);399}400 401TEST(TestSliceAndRowPitch, Given2dArrayWithNonZeroRowPitchAndNonZeroSlicePitchWhenGettingHostPtrSlicePitchAndRowPitchThenCorrectValuesAreReturned) {402    DebugManagerStateRestore dbgRestorer;403    DebugManager.flags.ForceLinearImages.set(true);404 405    cl_image_format imageFormat;406    cl_image_desc imageDesc;407    cl_int retVal;408    MockContext context;409 410    const size_t width = 5;411    const size_t height = 3;412    const size_t depth = 2;413    char *hostPtr = (char *)alignedMalloc(width * height * depth * elementSize * 2, 64);414 415    imageFormat.image_channel_data_type = channelType;416    imageFormat.image_channel_order = channelOrder;417 418    imageDesc.num_mip_levels = 0;419    imageDesc.num_samples = 0;420    imageDesc.mem_object = NULL;421 422    // 2D ARRAY image with non-zero row_pitch and non-zero slice_pitch423    imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;424    imageDesc.image_width = width;425    imageDesc.image_height = height;426    imageDesc.image_depth = 0;427    imageDesc.image_array_size = 2;428    imageDesc.image_row_pitch = (width + 1) * elementSize;429    imageDesc.image_slice_pitch = (width + 1) * elementSize * height;430 431    cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;432    auto surfaceFormat = Image::getSurfaceFormatFromTable(433        flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);434    auto image = Image::create(435        &context,436        MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),437        flags,438        0,439        surfaceFormat,440        &imageDesc,441        hostPtr,442        retVal);443    ASSERT_NE(nullptr, image);444 445    EXPECT_EQ((width + 1) * elementSize, image->getHostPtrRowPitch());446    EXPECT_EQ((width + 1) * elementSize * height, image->getHostPtrSlicePitch());447 448    delete image;449    alignedFree(hostPtr);450}451 452TEST(TestSliceAndRowPitch, Given2dArrayWithNonZeroRowPitchAndNonZeroSlicePitchGreaterThanRowPitchTimesHeightWhenGettingHostPtrSlicePitchAndRowPitchThenCorrectValuesAreReturned) {453    DebugManagerStateRestore dbgRestorer;454    DebugManager.flags.ForceLinearImages.set(true);455 456    cl_image_format imageFormat;457    cl_image_desc imageDesc;458    cl_int retVal;459    MockContext context;460 461    const size_t width = 5;462    const size_t height = 3;463    const size_t depth = 2;464    char *hostPtr = (char *)alignedMalloc(width * height * depth * elementSize * 2, 64);465 466    imageFormat.image_channel_data_type = channelType;467    imageFormat.image_channel_order = channelOrder;468 469    imageDesc.num_mip_levels = 0;470    imageDesc.num_samples = 0;471    imageDesc.mem_object = NULL;472 473    // 2D ARRAY image with non-zero row_pitch and non-zero slice_pitch > row_pitch * height474    imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;475    imageDesc.image_width = width;476    imageDesc.image_height = height;477    imageDesc.image_depth = 0;478    imageDesc.image_array_size = 2;479    imageDesc.image_row_pitch = (width + 1) * elementSize;480    imageDesc.image_slice_pitch = (width + 1) * elementSize * (height + 1);481 482    cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;483    auto surfaceFormat = Image::getSurfaceFormatFromTable(484        flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);485    auto image = Image::create(486        &context,487        MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),488        flags,489        0,490        surfaceFormat,491        &imageDesc,492        hostPtr,493        retVal);494    ASSERT_NE(nullptr, image);495 496    EXPECT_EQ((width + 1) * elementSize, image->getHostPtrRowPitch());497    EXPECT_EQ((width + 1) * elementSize * (height + 1), image->getHostPtrSlicePitch());498 499    delete image;500    alignedFree(hostPtr);501}502 503TEST(TestCreateImage, GivenSharedContextWhenImageIsCreatedThenRowAndSliceAreCorrect) {504    cl_image_format imageFormat;505    cl_image_desc imageDesc;506    cl_int retVal;507    MockContext context;508 509    context.isSharedContext = true;510 511    const size_t width = 5;512    const size_t height = 3;513    const size_t depth = 2;514    char *hostPtr = (char *)alignedMalloc(width * height * depth * elementSize * 2, 64);515 516    imageFormat.image_channel_data_type = channelType;517    imageFormat.image_channel_order = channelOrder;518 519    imageDesc.num_mip_levels = 0;520    imageDesc.num_samples = 0;521    imageDesc.mem_object = NULL;522 523    // 2D image with non-zero row_pitch and 0 slice_pitch524    imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;525    imageDesc.image_width = width;526    imageDesc.image_height = height;527    imageDesc.image_depth = 0;528    imageDesc.image_array_size = 0;529    imageDesc.image_row_pitch = (width + 1) * elementSize;530    imageDesc.image_slice_pitch = 0;531 532    cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;533    auto surfaceFormat = Image::getSurfaceFormatFromTable(534        flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);535 536    auto image = Image::create(537        &context,538        MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),539        flags,540        0,541        surfaceFormat,542        &imageDesc,543        hostPtr,544        retVal);545    ASSERT_NE(nullptr, image);546 547    EXPECT_EQ((width + 1) * elementSize, image->getHostPtrRowPitch());548    EXPECT_EQ(0u, image->getHostPtrSlicePitch());549    EXPECT_TRUE(image->isMemObjZeroCopy());550 551    delete image;552 553    alignedFree(hostPtr);554}555 556TEST(TestCreateImageUseHostPtr, GivenDifferenHostPtrAlignmentsWhenCheckingMemoryALignmentThenCorrectValueIsReturned) {557    KernelBinaryHelper kbHelper(KernelBinaryHelper::BUILT_INS_WITH_IMAGES);558 559    cl_image_format imageFormat;560    cl_image_desc imageDesc;561    cl_int retVal;562    MockContext context;563 564    const size_t width = 4;565    const size_t height = 32;566 567    imageFormat.image_channel_data_type = channelType;568    imageFormat.image_channel_order = channelOrder;569 570    imageDesc.num_mip_levels = 0;571    imageDesc.num_samples = 0;572    imageDesc.mem_object = NULL;573 574    // 2D image with 0 row_pitch and 0 slice_pitch575    imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;576    imageDesc.image_width = width;577    imageDesc.image_height = height;578    imageDesc.image_depth = 0;579    imageDesc.image_array_size = 0;580    imageDesc.image_row_pitch = alignUp(alignUp(width, 4) * 4, 0x80); //row pitch for tiled img581    imageDesc.image_slice_pitch = 0;582 583    void *pageAlignedPointer = alignedMalloc(imageDesc.image_row_pitch * height * 1 * 4 + 256, 4096);584    void *hostPtr[] = {ptrOffset(pageAlignedPointer, 16),   // 16 - byte alignment585                       ptrOffset(pageAlignedPointer, 32),   // 32 - byte alignment586                       ptrOffset(pageAlignedPointer, 64),   // 64 - byte alignment587                       ptrOffset(pageAlignedPointer, 128)}; // 128 - byte alignment588 589    bool result[] = {false,590                     false,591                     true,592                     true};593 594    cl_mem_flags flags = CL_MEM_HOST_NO_ACCESS | CL_MEM_USE_HOST_PTR;595    auto surfaceFormat = Image::getSurfaceFormatFromTable(596        flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);597    for (int i = 0; i < 4; i++) {598        auto image = Image::create(599            &context,600            MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),601            flags,602            0,603            surfaceFormat,604            &imageDesc,605            hostPtr[i],606            retVal);607        ASSERT_NE(nullptr, image);608 609        auto address = image->getCpuAddress();610        if (result[i] && image->isMemObjZeroCopy()) {611            EXPECT_EQ(hostPtr[i], address);612        } else {613            EXPECT_NE(hostPtr[i], address);614        }615        delete image;616    }617    alignedFree(pageAlignedPointer);618}619 620TEST(TestCreateImageUseHostPtr, givenZeroCopyImageValuesWhenUsingHostPtrThenZeroCopyImageIsCreated) {621    cl_int retVal = CL_SUCCESS;622    MockContext context;623    cl_image_desc imageDesc = {};624    imageDesc.image_width = 4096;625    imageDesc.image_height = 1;626    imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D;627 628    cl_image_format imageFormat = {};629    imageFormat.image_channel_data_type = CL_UNSIGNED_INT8;630    imageFormat.image_channel_order = CL_R;631 632    cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;633    auto surfaceFormat = Image::getSurfaceFormatFromTable(634        flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);635    auto hostPtr = alignedMalloc(imageDesc.image_width * surfaceFormat->surfaceFormat.ImageElementSizeInBytes,636                                 MemoryConstants::cacheLineSize);637 638    auto image = std::unique_ptr<Image>(Image::create(639        &context,640        MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),641        flags,642        0,643        surfaceFormat,644        &imageDesc,645        hostPtr,646        retVal));647 648    auto allocation = image->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex());649    EXPECT_NE(nullptr, image);650    EXPECT_EQ(CL_SUCCESS, retVal);651    EXPECT_TRUE(image->isMemObjZeroCopy());652    EXPECT_EQ(hostPtr, allocation->getUnderlyingBuffer());653    EXPECT_EQ(nullptr, image->getMapAllocation(context.getDevice(0)->getRootDeviceIndex()));654 655    alignedFree(hostPtr);656}657 658TEST(TestRedescribableFormatCheck, givenVariousOclFormatsWhenCheckingIfRedescribableThenReturnCorrectResults) {659    static const cl_image_format redescribeFormats[] = {660        {CL_R, CL_UNSIGNED_INT8},661        {CL_R, CL_UNSIGNED_INT16},662        {CL_R, CL_UNSIGNED_INT32},663        {CL_RG, CL_UNSIGNED_INT32},664        {CL_RGBA, CL_UNSIGNED_INT32},665    };666 667    const ArrayRef<const ClSurfaceFormatInfo> formats = SurfaceFormats::readWrite();668    for (const auto &format : formats) {669        const cl_image_format oclFormat = format.OCLImageFormat;670        bool expectedResult = true;671        for (const auto &nonRedescribableFormat : redescribeFormats) {672            expectedResult &= (memcmp(&oclFormat, &nonRedescribableFormat, sizeof(cl_image_format)) != 0);673        }674        EXPECT_EQ(expectedResult, Image::isFormatRedescribable(oclFormat));675    }676}677 678TEST_P(CreateImageNoHostPtr, GivenMissingPitchWhenImageIsCreatedThenConstructorFillsMissingData) {679    auto image = createImageWithFlags(flags);680 681    ASSERT_EQ(CL_SUCCESS, retVal);682    ASSERT_NE(nullptr, image);683 684    const auto &imageDesc = image->getImageDesc();685 686    // Sometimes the user doesn't pass image_row/slice_pitch during a create.687    // Ensure the driver fills in the missing data.688    EXPECT_NE(0u, imageDesc.image_row_pitch);689    EXPECT_GE(imageDesc.image_slice_pitch, imageDesc.image_row_pitch);690    delete image;691}692 693TEST_P(CreateImageNoHostPtr, whenImageIsCreatedThenItHasProperAccessAndCacheProperties) {694    auto image = createImageWithFlags(flags);695 696    ASSERT_EQ(CL_SUCCESS, retVal);697    ASSERT_NE(nullptr, image);698 699    auto allocation = image->getGraphicsAllocation(context->getDevice(0)->getRootDeviceIndex());700    EXPECT_TRUE(allocation->getAllocationType() == GraphicsAllocation::AllocationType::IMAGE);701 702    auto isImageWritable = !(flags & (CL_MEM_READ_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS));703    EXPECT_EQ(isImageWritable, allocation->isMemObjectsAllocationWithWritableFlags());704 705    auto isReadOnly = isValueSet(flags, CL_MEM_READ_ONLY);706    EXPECT_NE(isReadOnly, allocation->isFlushL3Required());707 708    delete image;709}710 711// Parameterized test that tests image creation with all flags that should be712// valid with a nullptr host ptr713static cl_mem_flags NoHostPtrFlags[] = {714    CL_MEM_READ_WRITE,715    CL_MEM_WRITE_ONLY,716    CL_MEM_READ_ONLY,717    CL_MEM_HOST_READ_ONLY,718    CL_MEM_HOST_WRITE_ONLY,719    CL_MEM_HOST_NO_ACCESS};720 721INSTANTIATE_TEST_CASE_P(722    CreateImageTest_Create,723    CreateImageNoHostPtr,724    testing::ValuesIn(NoHostPtrFlags));725 726struct CreateImageHostPtr727    : public CreateImageTest,728      public MemoryManagementFixture {729    typedef CreateImageTest BaseClass;730 731    CreateImageHostPtr() {732    }733 734    void SetUp() override {735        MemoryManagementFixture::SetUp();736        BaseClass::SetUp();737    }738 739    void TearDown() override {740        delete image;741        BaseClass::TearDown();742        platformsImpl->clear();743        MemoryManagementFixture::TearDown();744    }745 746    Image *createImage(cl_int &retVal) {747        auto surfaceFormat = Image::getSurfaceFormatFromTable(748            flags, &imageFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);749        return Image::create(750            context,751            MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()),752            flags,753            0,754            surfaceFormat,755            &imageDesc,756            pHostPtr,757            retVal);758    }759 760    cl_int retVal = CL_INVALID_VALUE;761    Image *image = nullptr;762};763 764TEST_P(CreateImageHostPtr, WhenImageIsCreatedThenResidencyIsFalse) {765    image = createImage(retVal);766    ASSERT_NE(nullptr, image);767 768    auto allocation = image->getGraphicsAllocation(context->getDevice(0)->getRootDeviceIndex());769    EXPECT_FALSE(allocation->isResident(pDevice->getDefaultEngine().osContext->getContextId()));770}771 772TEST_P(CreateImageHostPtr, WhenCheckingAddressThenAlllocationDependsOnSizeRelativeToPage) {773    image = createImage(retVal);774    auto allocation = image->getGraphicsAllocation(context->getDevice(0)->getRootDeviceIndex());775    ASSERT_NE(nullptr, image);776 777    auto address = image->getBasePtrForMap(0);778    EXPECT_NE(nullptr, address);779 780    if (!(flags & CL_MEM_USE_HOST_PTR)) {781        EXPECT_EQ(nullptr, image->getHostPtr());782    }783 784    if (flags & CL_MEM_USE_HOST_PTR) {785        //if size fits within a page then zero copy can be applied, if not RT needs to do a copy of image786        auto computedSize = imageDesc.image_width * elementSize * alignUp(imageDesc.image_height, 4) * imageDesc.image_array_size;787        auto ptrSize = imageDesc.image_width * elementSize * imageDesc.image_height * imageDesc.image_array_size;788        auto alignedRequiredSize = alignSizeWholePage(static_cast<void *>(pHostPtr), computedSize);789        auto alignedPtrSize = alignSizeWholePage(static_cast<void *>(pHostPtr), ptrSize);790 791        size_t HalignReq = imageDesc.image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY ? 64 : 1;792        auto rowPitch = imageDesc.image_width * elementSize;793        auto slicePitch = rowPitch * imageDesc.image_height;794        auto requiredRowPitch = alignUp(imageDesc.image_width, HalignReq) * elementSize;795        auto requiredSlicePitch = requiredRowPitch * alignUp(imageDesc.image_height, 4);796 797        bool copyRequired = (alignedRequiredSize > alignedPtrSize) | (requiredRowPitch != rowPitch) | (slicePitch != requiredSlicePitch);798 799        EXPECT_EQ(pHostPtr, address);800        EXPECT_EQ(pHostPtr, image->getHostPtr());801 802        if (copyRequired) {803            EXPECT_FALSE(image->isMemObjZeroCopy());804        }805    } else {806        EXPECT_NE(pHostPtr, address);807    }808 809    if (flags & CL_MEM_COPY_HOST_PTR && image->isMemObjZeroCopy()) {810        // Buffer should contain a copy of host memory811        EXPECT_EQ(0, memcmp(pHostPtr, allocation->getUnderlyingBuffer(), sizeof(testImageDimensions)));812    }813}814 815TEST_P(CreateImageHostPtr, WhenGettingImageDescThenCorrectValuesAreReturned) {816    image = createImage(retVal);817    ASSERT_NE(nullptr, image);818    auto allocation = image->getGraphicsAllocation(context->getDevice(0)->getRootDeviceIndex());819 820    const auto &imageDesc = image->getImageDesc();821    // clang-format off822    EXPECT_EQ(this->imageDesc.image_type,        imageDesc.image_type);823    EXPECT_EQ(this->imageDesc.image_width,       imageDesc.image_width);824    EXPECT_EQ(this->imageDesc.image_height,      imageDesc.image_height);825    EXPECT_EQ(this->imageDesc.image_depth,       imageDesc.image_depth);826    EXPECT_EQ(0u,                                imageDesc.image_array_size);827    EXPECT_NE(0u,                                imageDesc.image_row_pitch);828    EXPECT_GE(imageDesc.image_slice_pitch,       imageDesc.image_row_pitch);829    EXPECT_EQ(this->imageDesc.num_mip_levels,    imageDesc.num_mip_levels);830    EXPECT_EQ(this->imageDesc.num_samples,       imageDesc.num_samples);831    EXPECT_EQ(this->imageDesc.buffer,            imageDesc.buffer);832    EXPECT_EQ(this->imageDesc.mem_object,        imageDesc.mem_object);833    // clang-format on834 835    EXPECT_EQ(image->getHostPtrRowPitch(), static_cast<size_t>(imageDesc.image_width * elementSize));836    // Only 3D, and array images can have slice pitch837    int isArrayOr3DType = 0;838    if (this->imageDesc.image_type == CL_MEM_OBJECT_IMAGE3D ||839        this->imageDesc.image_type == CL_MEM_OBJECT_IMAGE2D_ARRAY ||840        this->imageDesc.image_type == CL_MEM_OBJECT_IMAGE2D_ARRAY) {841        isArrayOr3DType = 1;842    }843 844    EXPECT_EQ(image->getHostPtrSlicePitch(), static_cast<size_t>(imageDesc.image_width * elementSize * imageDesc.image_height) * isArrayOr3DType);845    EXPECT_EQ(image->getImageCount(), 1u);846    EXPECT_NE(0u, image->getSize());847    EXPECT_NE(nullptr, allocation);848}849 850TEST_P(CreateImageHostPtr, GivenFailedAllocationInjectionWhenCheckingAllocationThenOnlyFailedAllocationReturnsNull) {851    InjectedFunction method = [this](size_t failureIndex) {852        // System under test853        image = createImage(retVal);854 855        if (MemoryManagement::nonfailingAllocation == failureIndex) {856            EXPECT_EQ(CL_SUCCESS, retVal);857            EXPECT_NE(nullptr, image);858        } else {859            EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal) << ""for allocation "" << failureIndex;860            EXPECT_EQ(nullptr, image);861        }862 863        delete image;864        image = nullptr;865    };866    injectFailures(method, 4); // check only first 5 allocations - avoid checks on writeImg call allocations for tiled imgs867}868 869TEST_P(CreateImageHostPtr, givenLinearImageWhenFailedAtCreationThenReturnError) {870    DebugManagerStateRestore restore;871    DebugManager.flags.ForceLinearImages.set(true);872 873    InjectedFunction method = [this](size_t failureIndex) {874        // System under test875        image = createImage(retVal);876 877        if (MemoryManagement::nonfailingAllocation == failureIndex) {878            EXPECT_EQ(CL_SUCCESS, retVal);879            EXPECT_NE(nullptr, image);880        } else {881            EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal) << ""for allocation "" << failureIndex;882            EXPECT_EQ(nullptr, image);883        }884 885        delete image;886        image = nullptr;887    };888    injectFailures(method, 4); // check only first 5 allocations - avoid checks on writeImg call allocations for tiled imgs889}890 891TEST_P(CreateImageHostPtr, WhenWritingOutsideAllocatedMemoryWhileCreatingImageThenWriteIsHandledCorrectly) {892    auto mockMemoryManager = new MockMemoryManager(*pDevice->executionEnvironment);893    pDevice->injectMemoryManager(mockMemoryManager);894    context->memoryManager = mockMemoryManager;895    mockMemoryManager->redundancyRatio = 2;896    memset(pHostPtr, 1, testImageDimensions * testImageDimensions * elementSize * 4);897    imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;898    imageDesc.image_height = 1;899    imageDesc.image_row_pitch = elementSize * imageDesc.image_width + 1;900    image = createImage(retVal);901    auto allocation = image->getGraphicsAllocation(pDevice->getRootDeviceIndex());902 903    char *memory = reinterpret_cast<char *>(allocation->getUnderlyingBuffer());904    auto memorySize = allocation->getUnderlyingBufferSize() / 2;905    for (size_t i = 0; i < image->getHostPtrSlicePitch(); ++i) {906        if (i < imageDesc.image_width * elementSize) {907            EXPECT_EQ(1, memory[i]);908        } else {909            EXPECT_EQ(0, memory[i]);910        }911    }912    for (size_t i = 0; i < memorySize; ++i) {913        EXPECT_EQ(0, memory[memorySize + i]);914    }915 916    mockMemoryManager->redundancyRatio = 1;917}918 919struct ModifyableImage {920    enum { flags = 0 };921    static cl_image_format imageFormat;922    static cl_image_desc imageDesc;923    static void *hostPtr;924    static NEO::Context *context;925};926 927void *ModifyableImage::hostPtr = nullptr;928NEO::Context *ModifyableImage::context = nullptr;929cl_image_format ModifyableImage::imageFormat;930cl_image_desc ModifyableImage::imageDesc;931 932class ImageTransfer : public ::testing::Test {933  public:934    void SetUp() override {935        context = new MockContext();936        ASSERT_NE(context, nullptr);937        ModifyableImage::context = context;938        ModifyableImage::hostPtr = nullptr;939        ModifyableImage::imageFormat = {CL_R, CL_FLOAT};940        ModifyableImage::imageDesc = {CL_MEM_OBJECT_IMAGE1D, 512, 0, 0, 0, 0, 0, 0, 0, {nullptr}};941        hostPtr = nullptr;942        unalignedHostPtr = nullptr;943    }944 945    void TearDown() override {946        if (context)947            delete context;948        if (hostPtr)949            alignedFree(hostPtr);950    }951 952    void createHostPtrs(size_t imageSize) {953        hostPtr = alignedMalloc(imageSize + 100, 4096);954        unalignedHostPtr = (char *)hostPtr + 4;955        memset(hostPtr, 0, imageSize + 100);956        memset(unalignedHostPtr, 1, imageSize);957    }958 959    MockContext *context;960    void *hostPtr;961    void *unalignedHostPtr;962};963 964TEST_F(ImageTransfer, GivenNonZeroCopyImageWhenDataTransferedFromHostPtrToMemStorageThenNoOverflowOfHostPtr) {965    size_t imageSize = 512 * 4;966    createHostPtrs(imageSize);967 968    ModifyableImage::imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D;969    ModifyableImage::imageDesc.image_width = 512;970    ModifyableImage::imageDesc.image_height = 0;971    ModifyableImage::imageDesc.image_row_pitch = 0;972    ModifyableImage::imageDesc.image_array_size = 0;973    ModifyableImage::imageFormat.image_channel_order = CL_R;974    ModifyableImage::imageFormat.image_channel_data_type = CL_FLOAT;975 976    ModifyableImage::hostPtr = unalignedHostPtr;977    Image *imageNonZeroCopy = ImageHelper<ImageUseHostPtr<ModifyableImage>>::create();978 979    ASSERT_NE(nullptr, imageNonZeroCopy);980 981    void *memoryStorage = imageNonZeroCopy->getCpuAddress();982    size_t memoryStorageSize = imageNonZeroCopy->getSize();983 984    ASSERT_NE(memoryStorage, unalignedHostPtr);985 986    int result = memcmp(memoryStorage, unalignedHostPtr, imageSize);987    EXPECT_EQ(0, result);988 989    memset(memoryStorage, 0, memoryStorageSize);990    memset((char *)unalignedHostPtr + imageSize, 2, 100 - 4);991 992    auto &imgDesc = imageNonZeroCopy->getImageDesc();993    MemObjOffsetArray copyOffset = {{0, 0, 0}};994    MemObjSizeArray copySize = {{imgDesc.image_width, imgDesc.image_height, imgDesc.image_depth}};995    imageNonZeroCopy->transferDataFromHostPtr(copySize, copyOffset);996 997    void *foundData = memchr(memoryStorage, 2, memoryStorageSize);998    EXPECT_EQ(0, foundData);999    delete imageNonZeroCopy;1000}1001 1002TEST_F(ImageTransfer, GivenNonZeroCopyNonZeroRowPitchImageWhenDataIsTransferedFromHostPtrToMemStorageThenDestinationIsNotOverflowed) {1003    ModifyableImage::imageDesc.image_width = 16;1004    ModifyableImage::imageDesc.image_row_pitch = 65;1005    ModifyableImage::imageFormat.image_channel_data_type = CL_UNORM_INT8;1006 1007    size_t imageSize = ModifyableImage::imageDesc.image_row_pitch;1008    size_t imageWidth = ModifyableImage::imageDesc.image_width;1009 1010    createHostPtrs(imageSize);1011 1012    ModifyableImage::hostPtr = unalignedHostPtr;1013    Image *imageNonZeroCopy = ImageHelper<ImageUseHostPtr<ModifyableImage>>::create();1014 1015    ASSERT_NE(nullptr, imageNonZeroCopy);1016 1017    void *memoryStorage = imageNonZeroCopy->getCpuAddress();1018    size_t memoryStorageSize = imageNonZeroCopy->getSize();1019 1020    ASSERT_NE(memoryStorage, unalignedHostPtr);1021 1022    int result = memcmp(memoryStorage, unalignedHostPtr, imageWidth);1023    EXPECT_EQ(0, result);1024 1025    memset(memoryStorage, 0, memoryStorageSize);1026    memset((char *)unalignedHostPtr + imageSize, 2, 100 - 4);1027 1028    auto &imgDesc = imageNonZeroCopy->getImageDesc();1029    MemObjOffsetArray copyOffset = {{0, 0, 0}};1030    MemObjSizeArray copySize = {{imgDesc.image_width, imgDesc.image_height, imgDesc.image_depth}};1031    imageNonZeroCopy->transferDataFromHostPtr(copySize, copyOffset);1032 1033    void *foundData = memchr(memoryStorage, 2, memoryStorageSize);1034    EXPECT_EQ(0, foundData);1035    delete imageNonZeroCopy;1036}1037 1038TEST_F(ImageTransfer, GivenNonZeroCopyNonZeroRowPitchWithExtraBytes1DArrayImageWhenDataIsTransferedForthAndBackThenDataValidates) {1039    ModifyableImage::imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;1040    ModifyableImage::imageDesc.image_width = 5;1041    ModifyableImage::imageDesc.image_row_pitch = 28; // == (4 * 5) row bytes + (4 * 2) extra bytes1042    ModifyableImage::imageDesc.image_array_size = 3;1043    ModifyableImage::imageFormat.image_channel_order = CL_RGBA;1044    ModifyableImage::imageFormat.image_channel_data_type = CL_UNORM_INT8;1045 1046    const size_t imageWidth = ModifyableImage::imageDesc.image_width;1047    const size_t imageRowPitchInPixels = ModifyableImage::imageDesc.image_row_pitch / 4;1048    const size_t imageHeight = 1;1049    const size_t imageCount = ModifyableImage::imageDesc.image_array_size;1050 1051    size_t imageSize = ModifyableImage::imageDesc.image_row_pitch * imageHeight * imageCount;1052 1053    createHostPtrs(imageSize);1054 1055    uint32_t *row = static_cast<uint32_t *>(unalignedHostPtr);1056 1057    for (uint32_t arrayIndex = 0; arrayIndex < imageCount; ++arrayIndex) {1058        for (uint32_t pixelInRow = 0; pixelInRow < imageRowPitchInPixels; ++pixelInRow) {1059            if (pixelInRow < imageWidth) {1060                row[pixelInRow] = pixelInRow;1061            } else {1062                row[pixelInRow] = 66;1063            }1064        }1065        row = row + imageRowPitchInPixels;1066    }1067 1068    ModifyableImage::hostPtr = unalignedHostPtr;1069    Image *imageNonZeroCopy = ImageHelper<ImageUseHostPtr<ModifyableImage>>::create();1070 1071    ASSERT_NE(nullptr, imageNonZeroCopy);1072 1073    void *memoryStorage = imageNonZeroCopy->getCpuAddress();1074 1075    ASSERT_NE(memoryStorage, unalignedHostPtr);1076 1077    size_t internalSlicePitch = imageNonZeroCopy->getImageDesc().image_slice_pitch;1078 1079    // Check twice, once after image create, and second time after transfer from HostPtrToMemoryStorage1080    // when these paths are unified, only one check will be enough1081    for (size_t run = 0; run < 2; ++run) {1082 1083        row = static_cast<uint32_t *>(unalignedHostPtr);1084        unsigned char *internalRow = static_cast<unsigned char *>(memoryStorage);1085 1086        if (run == 1) {1087            auto &imgDesc = imageNonZeroCopy->getImageDesc();1088            MemObjOffsetArray copyOffset = {{0, 0, 0}};1089            MemObjSizeArray copySize = {{imgDesc.image_width, imgDesc.image_height, imgDesc.image_depth}};1090            imageNonZeroCopy->transferDataFromHostPtr(copySize, copyOffset);1091        }1092 1093        for (size_t arrayIndex = 0; arrayIndex < imageCount; ++arrayIndex) {1094            for (size_t pixelInRow = 0; pixelInRow < imageRowPitchInPixels; ++pixelInRow) {1095                if (pixelInRow < imageWidth) {1096                    if (memcmp(&row[pixelInRow], &internalRow[pixelInRow * 4], 4)) {1097                        EXPECT_FALSE(1) << ""Data in memory storage did not validate, row: "" << pixelInRow << "" array: "" << arrayIndex << ""\\n"";1098                    }1099                } else {1100                    // Change extra bytes pattern1101                    row[pixelInRow] = 55;1102                }1103            }1104            row = row + imageRowPitchInPixels;1105            internalRow = internalRow + internalSlicePitch;1106        }1107    }1108 1109    auto &imgDesc = imageNonZeroCopy->getImageDesc();1110    MemObjOffsetArray copyOffset = {{0, 0, 0}};1111    MemObjSizeArray copySize = {{imgDesc.image_width, imgDesc.image_height, imgDesc.image_depth}};1112    imageNonZeroCopy->transferDataToHostPtr(copySize, copyOffset);1113 1114    row = static_cast<uint32_t *>(unalignedHostPtr);1115 1116    for (size_t arrayIndex = 0; arrayIndex < imageCount; ++arrayIndex) {1117        for (size_t pixelInRow = 0; pixelInRow < imageRowPitchInPixels; ++pixelInRow) {1118            if (pixelInRow < imageWidth) {1119                if (row[pixelInRow] != pixelInRow) {1120                    EXPECT_FALSE(1) << ""Data under host_ptr did not validate, row: "" << pixelInRow << "" array: "" << arrayIndex << ""\\n"";1121                }1122            } else {1123                if (row[pixelInRow] != 55) {1124                    EXPECT_FALSE(1) << ""Data under host_ptr corrupted in extra bytes, row: "" << pixelInRow << "" array: "" << arrayIndex << ""\\n"";1125                }1126            }1127        }1128        row = row + imageRowPitchInPixels;1129    }1130 1131    delete imageNonZeroCopy;1132}1133 1134// Parameterized test that tests image creation with all flags that should be1135// valid with a valid host ptr1136static cl_mem_flags ValidHostPtrFlags[] = {1137    0 | CL_MEM_USE_HOST_PTR,1138    CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,1139    CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR,1140    CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,1141    CL_MEM_HOST_READ_ONLY | CL_MEM_USE_HOST_PTR,1142    CL_MEM_HOST_WRITE_ONLY | CL_MEM_USE_HOST_PTR,1143    CL_MEM_HOST_NO_ACCESS | CL_MEM_USE_HOST_PTR,1144    0 | CL_MEM_COPY_HOST_PTR,1145    CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,1146    CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR,1147    CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,1148    CL_MEM_HOST_READ_ONLY | CL_MEM_COPY_HOST_PTR,1149    CL_MEM_HOST_WRITE_ONLY | CL_MEM_COPY_HOST_PTR,1150    CL_MEM_HOST_NO_ACCESS | CL_MEM_COPY_HOST_PTR};1151 1152INSTANTIATE_TEST_CASE_P(1153    CreateImageTest_Create,1154    CreateImageHostPtr,1155    testing::ValuesIn(ValidHostPtrFlags));1156 1157TEST(ImageGetSurfaceFormatInfoTest, givenNullptrFormatWhenGetSurfaceFormatInfoIsCalledThenReturnsNullptr) {1158    MockContext context;1159    auto surfaceFormat = Image::getSurfaceFormatFromTable(0, nullptr, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);1160    EXPECT_EQ(nullptr, surfaceFormat);1161}1162 1163HWTEST_F(ImageCompressionTests, givenTiledImageWhenCreatingAllocationThenPreferRenderCompression) {1164    imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;1165    imageDesc.image_width = 5;1166    imageDesc.image_height = 5;1167    MockContext context;1168    auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);1169 1170    auto image = std::unique_ptr<Image>(Image::create(1171        mockContext.get(), MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),1172        flags, 0, surfaceFormat, &imageDesc, nullptr, retVal));1173    ASSERT_NE(nullptr, image);1174    EXPECT_EQ(UnitTestHelper<FamilyType>::tiledImagesSupported, image->isTiledAllocation());1175    EXPECT_TRUE(myMemoryManager->mockMethodCalled);1176    EXPECT_EQ(UnitTestHelper<FamilyType>::tiledImagesSupported, myMemoryManager->capturedImgInfo.preferRenderCompression);1177}1178 1179TEST_F(ImageCompressionTests, givenNonTiledImageWhenCreatingAllocationThenDontPreferRenderCompression) {1180    imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D;1181    imageDesc.image_width = 5;1182    MockContext context;1183    auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);1184 1185    auto image = std::unique_ptr<Image>(Image::create(1186        mockContext.get(), MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),1187        flags, 0, surfaceFormat, &imageDesc, nullptr, retVal));1188    ASSERT_NE(nullptr, image);1189    EXPECT_FALSE(image->isTiledAllocation());1190    EXPECT_TRUE(myMemoryManager->mockMethodCalled);1191    EXPECT_FALSE(myMemoryManager->capturedImgInfo.preferRenderCompression);1192}1193 1194TEST(ImageTest, givenImageWhenGettingCompressionOfImageThenCorrectValueIsReturned) {1195    MockContext context;1196    std::unique_ptr<Image> image(ImageHelper<Image3dDefaults>::create(&context));1197    EXPECT_NE(nullptr, image);1198 1199    auto allocation = image->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex());1200    allocation->getDefaultGmm()->isRenderCompressed = true;

Showing the first 1,200 of 92116 lines. Download the file for the rest.