use validateObject function for memObjs in win api

Change-Id: I1b54096b5a6fdb43a38c25a37560e88218671bd2
This commit is contained in:
Woloszyn, Wojciech
2018-04-20 11:55:22 +02:00
committed by sys_ocldev
parent 180de340d8
commit c0a84cad85
4 changed files with 101 additions and 54 deletions

View File

@ -1,24 +1,24 @@
/*
* 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.
*/
* Copyright (c) 2017 - 2018, 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 "runtime/helpers/base_object.h"
#include "runtime/helpers/validators.h"
@ -118,6 +118,18 @@ cl_int validateObject(const DeviceList &deviceList) {
return CL_SUCCESS;
}
cl_int validateObject(const MemObjList &memObjList) {
if ((!memObjList.first) != (!memObjList.second))
return CL_INVALID_VALUE;
for (cl_uint i = 0; i < memObjList.first; i++) {
if (validateObject(memObjList.second[i]) != CL_SUCCESS)
return CL_INVALID_MEM_OBJECT;
}
return CL_SUCCESS;
}
cl_int validateObject(const NonZeroBufferSize &nzbs) {
return nzbs ? CL_SUCCESS : CL_INVALID_BUFFER_SIZE;
}
@ -157,4 +169,4 @@ bool IsPackedYuvImage(const cl_image_format *imageFormat) {
bool IsNV12Image(const cl_image_format *imageFormat) {
return imageFormat->image_channel_order == CL_NV12_INTEL;
}
}
} // namespace OCLRT

View File

@ -1,24 +1,24 @@
/*
* 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.
*/
* Copyright (c) 2017 - 2018, 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.
*/
#pragma once
#include "runtime/api/cl_types.h"
@ -31,6 +31,7 @@ namespace OCLRT {
// Provide some aggregators...
typedef std::pair<uint32_t, const cl_event *> EventWaitList;
typedef std::pair<uint32_t, const cl_device_id *> DeviceList;
typedef std::pair<uint32_t, const cl_mem *> MemObjList;
// Custom validators
enum NonZeroBufferSize : size_t;
@ -62,6 +63,7 @@ cl_int validateObject(cl_program program);
cl_int validateObject(cl_kernel kernel);
cl_int validateObject(const EventWaitList &eventWaitList);
cl_int validateObject(const DeviceList &deviceList);
cl_int validateObject(const MemObjList &memObjList);
cl_int validateObject(const NonZeroBufferSize &nzbs);
cl_int validateObject(const PatternSize &ps);
@ -98,4 +100,4 @@ bool areNotNullptr(T t, RT... rt) {
cl_int validateYuvOperation(const size_t *origin, const size_t *region);
bool IsPackedYuvImage(const cl_image_format *imageFormat);
bool IsNV12Image(const cl_image_format *imageFormat);
}
} // namespace OCLRT

View File

@ -343,11 +343,13 @@ cl_int CL_API_CALL clEnqueueAcquireD3D10ObjectsKHR(cl_command_queue commandQueue
return retVal;
}
retVal = validateObjects(MemObjList(numObjects, memObjects));
if (retVal != CL_SUCCESS) {
return retVal;
}
for (unsigned int object = 0; object < numObjects; object++) {
auto memObj = castToObject<MemObj>(memObjects[object]);
if (memObj == nullptr) {
return CL_INVALID_MEM_OBJECT;
}
if (memObj->acquireCount >= 1) {
return CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR;
}
@ -365,11 +367,13 @@ cl_int CL_API_CALL clEnqueueReleaseD3D10ObjectsKHR(cl_command_queue commandQueue
return retVal;
}
retVal = validateObjects(MemObjList(numObjects, memObjects));
if (retVal != CL_SUCCESS) {
return retVal;
}
for (unsigned int object = 0; object < numObjects; object++) {
auto memObject = castToObject<MemObj>(memObjects[object]);
if (memObject == nullptr) {
return CL_INVALID_MEM_OBJECT;
}
if (memObject->acquireCount == 0) {
return CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR;
}
@ -504,11 +508,13 @@ cl_int CL_API_CALL clEnqueueAcquireD3D11ObjectsKHR(cl_command_queue commandQueue
return retVal;
}
retVal = validateObjects(MemObjList(numObjects, memObjects));
if (retVal != CL_SUCCESS) {
return retVal;
}
for (unsigned int object = 0; object < numObjects; object++) {
auto memObj = castToObject<MemObj>(memObjects[object]);
if (memObj == nullptr) {
return CL_INVALID_MEM_OBJECT;
}
if (memObj->acquireCount >= 1) {
return CL_D3D11_RESOURCE_ALREADY_ACQUIRED_KHR;
}
@ -526,11 +532,13 @@ cl_int CL_API_CALL clEnqueueReleaseD3D11ObjectsKHR(cl_command_queue commandQueue
return retVal;
}
retVal = validateObjects(MemObjList(numObjects, memObjects));
if (retVal != CL_SUCCESS) {
return retVal;
}
for (unsigned int object = 0; object < numObjects; object++) {
auto memObject = castToObject<MemObj>(memObjects[object]);
if (memObject == nullptr) {
return CL_INVALID_MEM_OBJECT;
}
if (memObject->acquireCount == 0) {
return CL_D3D11_RESOURCE_NOT_ACQUIRED_KHR;
}

View File

@ -27,6 +27,7 @@
#include "runtime/helpers/validators.h"
#include "runtime/platform/platform.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_buffer.h"
#include "gtest/gtest.h"
using namespace OCLRT;
@ -134,6 +135,30 @@ TEST(DeviceList, nonZeroCount_noNullPointer) {
EXPECT_EQ(CL_INVALID_DEVICE, validateObjects(DeviceList(1, &devList)));
}
TEST(MemObjList, zeroCount_nonNullPointer) {
cl_mem memList = static_cast<cl_mem>(ptrGarbage);
EXPECT_EQ(CL_INVALID_VALUE, validateObjects(MemObjList(0, &memList)));
}
TEST(MemObjList, zeroCount_nullPointer) {
EXPECT_EQ(CL_SUCCESS, validateObjects(MemObjList(0, nullptr)));
}
TEST(MemObjList, nonZeroCount_nullPointer) {
EXPECT_EQ(CL_INVALID_VALUE, validateObjects(MemObjList(1, nullptr)));
}
TEST(MemObjList, nonZeroCount_noNullPointer) {
cl_mem memList = static_cast<cl_mem>(ptrGarbage);
EXPECT_EQ(CL_INVALID_MEM_OBJECT, validateObjects(MemObjList(1, &memList)));
}
TEST(MemObjList, nonZeroCount_validPointer) {
std::unique_ptr<MockBuffer> buffer(new MockBuffer());
cl_mem memList = static_cast<cl_mem>(buffer.get());
EXPECT_EQ(CL_SUCCESS, validateObjects(MemObjList(1, &memList)));
}
TEST(NonZeroBufferSizeValidator, zero) {
auto bsv = (NonZeroBufferSize)0;
EXPECT_EQ(CL_INVALID_BUFFER_SIZE, validateObjects(bsv));