Initial commit

Change-Id: I4bf1707bd3dfeadf2c17b0a7daff372b1925ebbd
This commit is contained in:
Brandon Fliflet
2017-12-21 00:45:38 +01:00
commit 7e9ad41290
1350 changed files with 233156 additions and 0 deletions

View File

@ -0,0 +1,59 @@
# 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.
# We are setting all of the source/OpenCL/tests/fixtures files here and
# sending the variable up to the parent scope
set(IGDRCL_SRCS_tests_fixtures
"${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt"
"${CMAKE_CURRENT_SOURCE_DIR}/buffer_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/buffer_fixture.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/built_in_fixture.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/built_in_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/context_fixture.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/context_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/device_fixture.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/device_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/device_host_queue_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/device_host_queue_fixture.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/execution_model_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/execution_model_kernel_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/gmm_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/hello_world_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/hello_world_kernel_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/image_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/image_fixture.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/kernel_data_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/kernel_data_fixture.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/memory_allocator_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/memory_manager_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/memory_manager_fixture.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/memory_management_fixture.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/memory_management_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/platform_fixture.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/platform_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/program_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/program_fixture.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/run_kernel_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/scenario_test_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/simple_arg_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/simple_arg_kernel_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/two_walker_fixture.h"
PARENT_SCOPE
)

View File

@ -0,0 +1,36 @@
/*
* 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 "unit_tests/fixtures/buffer_fixture.h"
#include "unit_tests/mocks/mock_context.h"
using OCLRT::Context;
static char bufferMemory[] = {
0x00, 0x10, 0x20, 0x30,
0x01, 0x11, 0x21, 0x31,
0x02, 0x12, 0x22, 0x32,
0x03, 0x13, 0x23, 0x33,
};
void *BufferDefaults::hostPtr = bufferMemory;
const size_t BufferDefaults::sizeInBytes = sizeof(bufferMemory);
Context *BufferDefaults::context = nullptr;

View File

@ -0,0 +1,69 @@
/*
* 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.
*/
#pragma once
#include "runtime/mem_obj/buffer.h"
#include "unit_tests/mocks/mock_context.h"
#include "CL/cl.h"
#include <cassert>
#include <memory>
struct BufferDefaults {
enum { flags = CL_MEM_READ_WRITE };
static const size_t sizeInBytes;
static void *hostPtr;
static OCLRT::Context *context;
};
template <typename BaseClass = BufferDefaults>
struct BufferUseHostPtr : public BaseClass {
enum { flags = BaseClass::flags | CL_MEM_USE_HOST_PTR };
};
template <typename BaseClass = BufferDefaults>
struct BufferReadOnly : public BaseClass {
enum { flags = BaseClass::flags | CL_MEM_READ_ONLY };
};
template <typename BaseClass = BufferDefaults>
struct BufferWriteOnly : public BaseClass {
enum { flags = BaseClass::flags | CL_MEM_WRITE_ONLY };
};
template <typename Traits = BufferDefaults>
struct BufferHelper {
using Buffer = OCLRT::Buffer;
using Context = OCLRT::Context;
using MockContext = OCLRT::MockContext;
static Buffer *create(Context *context = Traits::context) {
auto retVal = CL_SUCCESS;
auto buffer = Buffer::create(
context ? context : std::shared_ptr<Context>(new MockContext).get(),
Traits::flags,
Traits::sizeInBytes,
Traits::hostPtr,
retVal);
assert(buffer != nullptr);
return buffer;
}
};

View File

@ -0,0 +1,69 @@
/*
* 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 "runtime/built_ins/built_ins.h"
#include "runtime/compiler_interface/compiler_interface.h"
#include "runtime/device/device.h"
#include "unit_tests/fixtures/built_in_fixture.h"
#include "unit_tests/helpers/kernel_binary_helper.h"
#include "unit_tests/helpers/test_files.h"
#include "unit_tests/global_environment.h"
using namespace OCLRT;
BuiltInFixture::BuiltInFixture() : pBuiltIns(nullptr) {
}
void BuiltInFixture::SetUp(Device *pDevice) {
CompilerInterface::getInstance();
// create an instance of the builtins
pBuiltIns = &BuiltIns::getInstance();
pBuiltIns->setCacheingEnableState(false);
// set mock compiler to return expected kernel...
MockCompilerDebugVars fclDebugVars;
MockCompilerDebugVars igcDebugVars;
std::string builtInFileRoot = testFiles + KernelBinaryHelper::BUILT_INS;
std::string builtInBcFile = builtInFileRoot + "_";
std::string builtInGenFile = builtInFileRoot + "_";
auto product = pDevice->getProductAbbrev();
builtInBcFile.append(product);
builtInGenFile.append(product);
builtInBcFile.append(".bc");
builtInGenFile.append(".gen");
fclDebugVars.fileName = builtInBcFile;
igcDebugVars.fileName = builtInGenFile;
gEnvironment->fclPushDebugVars(fclDebugVars);
gEnvironment->igcPushDebugVars(igcDebugVars);
}
void BuiltInFixture::TearDown() {
gEnvironment->igcPopDebugVars();
gEnvironment->fclPopDebugVars();
CompilerInterface::shutdown();
BuiltIns::shutDown();
}

View File

@ -0,0 +1,37 @@
/*
* 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.
*/
#pragma once
namespace OCLRT {
class BuiltIns;
}
class BuiltInFixture {
public:
BuiltInFixture();
void SetUp(OCLRT::Device *pDevice);
void TearDown();
OCLRT::BuiltIns *pBuiltIns;
};

View File

@ -0,0 +1,46 @@
/*
* 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 "config.h"
#include "context_fixture.h"
#include "unit_tests/mocks/mock_context.h"
#include "gtest/gtest.h"
namespace OCLRT {
ContextFixture::ContextFixture()
: pContext(nullptr) {
}
void ContextFixture::SetUp(cl_uint numDevices, cl_device_id *pDeviceList) {
auto retVal = CL_SUCCESS;
pContext = Context::create<MockContext>(nullptr, DeviceVector(pDeviceList, numDevices),
nullptr, nullptr, retVal);
ASSERT_NE(nullptr, pContext);
ASSERT_EQ(CL_SUCCESS, retVal);
}
void ContextFixture::TearDown() {
delete pContext;
pContext = nullptr;
}
} // namespace OCLRT

View File

@ -0,0 +1,39 @@
/*
* 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.
*/
#pragma once
#include "CL/cl.h"
namespace OCLRT {
class MockContext;
class ContextFixture {
public:
ContextFixture();
protected:
virtual void SetUp(cl_uint numDevices, cl_device_id *pDeviceList);
virtual void TearDown();
MockContext *pContext;
};
}

View File

@ -0,0 +1,58 @@
/*
* 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 "device_fixture.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/helpers/options.h"
#include "gtest/gtest.h"
#include "unit_tests/mocks/mock_ostime.h"
using OCLRT::Device;
using OCLRT::HardwareInfo;
using OCLRT::platformDevices;
using OCLRT::OSTime;
using OCLRT::MockOSTime;
void DeviceFixture::SetUp() {
SetUpImpl(nullptr);
}
void DeviceFixture::SetUpImpl(const OCLRT::HardwareInfo *hardwareInfo) {
pDevice = DeviceHelper<>::create(hardwareInfo);
ASSERT_NE(nullptr, pDevice);
auto &commandStreamReceiver = pDevice->getCommandStreamReceiver();
pTagMemory = commandStreamReceiver.getTagAddress();
ASSERT_NE(nullptr, const_cast<uint32_t *>(pTagMemory));
}
void DeviceFixture::TearDown() {
delete pDevice;
}
OCLRT::MockDevice *DeviceFixture::createWithUsDeviceId(unsigned short usDeviceId) {
hwInfoHelper = *platformDevices[0];
platformHelper = *platformDevices[0]->pPlatform;
platformHelper.usDeviceID = usDeviceId;
hwInfoHelper.pPlatform = &platformHelper;
return DeviceHelper<>::create(&hwInfoHelper);
}

View File

@ -0,0 +1,60 @@
/*
* 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.
*/
#pragma once
#include "unit_tests/mocks/mock_device.h"
#include "runtime/helpers/hw_info.h"
#include <cassert>
namespace OCLRT {
struct HardwareInfo;
extern const HardwareInfo **platformDevices;
} // namespace OCLRT
struct DeviceDefaults {
};
template <typename DeviceTraits = DeviceDefaults>
struct DeviceHelper {
static OCLRT::MockDevice *create(const OCLRT::HardwareInfo *hardwareInfo = nullptr) {
OCLRT::MockDevice *device = OCLRT::Device::create<OCLRT::MockDevice>(hardwareInfo);
assert(device != nullptr);
return device;
}
};
struct DeviceFixture {
DeviceFixture()
: pDevice(nullptr),
pTagMemory(nullptr) {
}
void SetUp();
void SetUpImpl(const OCLRT::HardwareInfo *hardwareInfo);
void TearDown();
OCLRT::MockDevice *createWithUsDeviceId(unsigned short usDeviceId);
OCLRT::MockDevice *pDevice;
volatile uint32_t *pTagMemory;
OCLRT::HardwareInfo hwInfoHelper;
PLATFORM platformHelper;
};

View File

@ -0,0 +1,118 @@
/*
* 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 "unit_tests/fixtures/device_host_queue_fixture.h"
using namespace OCLRT;
namespace DeviceHostQueue {
cl_queue_properties deviceQueueProperties::minimumProperties[5] = {
CL_QUEUE_PROPERTIES,
CL_QUEUE_ON_DEVICE | CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,
0, 0, 0};
cl_queue_properties deviceQueueProperties::minimumPropertiesWithProfiling[5] = {
CL_QUEUE_PROPERTIES,
CL_QUEUE_ON_DEVICE | CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_PROFILING_ENABLE,
0, 0, 0};
cl_queue_properties deviceQueueProperties::noProperties[5] = {0};
cl_queue_properties deviceQueueProperties::allProperties[5] = {
CL_QUEUE_PROPERTIES, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_PROFILING_ENABLE | CL_QUEUE_ON_DEVICE,
CL_QUEUE_SIZE, 128 * 1024,
0};
template <>
cl_command_queue DeviceHostQueueFixture<DeviceQueue>::create(cl_context ctx, cl_device_id device, cl_int &retVal,
cl_queue_properties properties[5]) {
cl_queue_properties qProps[5];
memcpy(qProps, properties, 5 * sizeof(cl_queue_properties));
qProps[0] = CL_QUEUE_PROPERTIES;
qProps[1] = qProps[1] | deviceQueueProperties::minimumProperties[1];
return clCreateCommandQueueWithProperties(ctx, device, qProps, &retVal);
}
template <>
cl_command_queue DeviceHostQueueFixture<CommandQueue>::create(cl_context ctx, cl_device_id device, cl_int &retVal,
cl_queue_properties properties[5]) {
return clCreateCommandQueueWithProperties(ctx, device, properties, &retVal);
}
IGIL_CommandQueue getExpectedInitIgilCmdQueue(DeviceQueue *deviceQueue) {
IGIL_CommandQueue igilCmdQueueInit;
auto queueBuffer = deviceQueue->getQueueBuffer();
memset(&igilCmdQueueInit, 0, sizeof(IGIL_CommandQueue));
igilCmdQueueInit.m_head = IGIL_DEVICE_QUEUE_HEAD_INIT;
igilCmdQueueInit.m_size = static_cast<uint32_t>(queueBuffer->getUnderlyingBufferSize() - sizeof(IGIL_CommandQueue));
igilCmdQueueInit.m_magic = IGIL_MAGIC_NUMBER;
igilCmdQueueInit.m_controls.m_SLBENDoffsetInBytes = -1;
return igilCmdQueueInit;
}
IGIL_CommandQueue getExpectedgilCmdQueueAfterReset(DeviceQueue *deviceQueue) {
auto queueBuffer = deviceQueue->getQueueBuffer();
auto stackBuffer = deviceQueue->getStackBuffer();
auto queueStorage = deviceQueue->getQueueStorageBuffer();
auto deviceQueueIgilCmdQueue = reinterpret_cast<IGIL_CommandQueue *>(queueBuffer->getUnderlyingBuffer());
IGIL_CommandQueue expectedIgilCmdQueue;
memcpy(&expectedIgilCmdQueue, deviceQueueIgilCmdQueue, sizeof(IGIL_CommandQueue));
expectedIgilCmdQueue.m_head = IGIL_DEVICE_QUEUE_HEAD_INIT;
expectedIgilCmdQueue.m_size = static_cast<uint32_t>(queueBuffer->getUnderlyingBufferSize() - sizeof(IGIL_CommandQueue));
expectedIgilCmdQueue.m_magic = IGIL_MAGIC_NUMBER;
expectedIgilCmdQueue.m_controls.m_SLBENDoffsetInBytes = -1;
expectedIgilCmdQueue.m_controls.m_StackSize =
static_cast<uint32_t>((stackBuffer->getUnderlyingBufferSize() / sizeof(cl_uint)) - 1);
expectedIgilCmdQueue.m_controls.m_StackTop =
static_cast<uint32_t>((stackBuffer->getUnderlyingBufferSize() / sizeof(cl_uint)) - 1);
expectedIgilCmdQueue.m_controls.m_PreviousHead = IGIL_DEVICE_QUEUE_HEAD_INIT;
expectedIgilCmdQueue.m_controls.m_IDTAfterFirstPhase = 1;
expectedIgilCmdQueue.m_controls.m_CurrentIDToffset = 1;
expectedIgilCmdQueue.m_controls.m_PreviousStorageTop = static_cast<uint32_t>(queueStorage->getUnderlyingBufferSize());
expectedIgilCmdQueue.m_controls.m_PreviousStackTop =
static_cast<uint32_t>((stackBuffer->getUnderlyingBufferSize() / sizeof(cl_uint)) - 1);
expectedIgilCmdQueue.m_controls.m_DebugNextBlockID = 0xFFFFFFFF;
expectedIgilCmdQueue.m_controls.m_QstorageSize = static_cast<uint32_t>(queueStorage->getUnderlyingBufferSize());
expectedIgilCmdQueue.m_controls.m_QstorageTop = static_cast<uint32_t>(queueStorage->getUnderlyingBufferSize());
expectedIgilCmdQueue.m_controls.m_IsProfilingEnabled = static_cast<uint32_t>(deviceQueue->isProfilingEnabled());
expectedIgilCmdQueue.m_controls.m_SLBENDoffsetInBytes = -1;
expectedIgilCmdQueue.m_controls.m_IsSimulation = static_cast<uint32_t>(deviceQueue->getDevice().isSimulation());
expectedIgilCmdQueue.m_controls.m_LastScheduleEventNumber = 0;
expectedIgilCmdQueue.m_controls.m_PreviousNumberOfQueues = 0;
expectedIgilCmdQueue.m_controls.m_EnqueueMarkerScheduled = 0;
expectedIgilCmdQueue.m_controls.m_SecondLevelBatchOffset = 0;
expectedIgilCmdQueue.m_controls.m_TotalNumberOfQueues = 0;
expectedIgilCmdQueue.m_controls.m_EventTimestampAddress = 0;
expectedIgilCmdQueue.m_controls.m_ErrorCode = 0;
expectedIgilCmdQueue.m_controls.m_CurrentScheduleEventNumber = 0;
expectedIgilCmdQueue.m_controls.m_DummyAtomicOperationPlaceholder = 0x00;
expectedIgilCmdQueue.m_controls.m_DebugNextBlockGWS = 0;
return expectedIgilCmdQueue;
}
}

View File

@ -0,0 +1,101 @@
/*
* 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.
*/
#pragma once
#include "unit_tests/api/cl_api_tests.h"
#include "runtime/command_queue/command_queue.h"
#include "runtime/device_queue/device_queue_hw.h"
#include "runtime/device_queue/device_queue.h"
#include "test.h"
using namespace OCLRT;
namespace DeviceHostQueue {
struct deviceQueueProperties {
static cl_queue_properties minimumProperties[5];
static cl_queue_properties minimumPropertiesWithProfiling[5];
static cl_queue_properties noProperties[5];
static cl_queue_properties allProperties[5];
};
IGIL_CommandQueue getExpectedInitIgilCmdQueue(DeviceQueue *deviceQueue);
IGIL_CommandQueue getExpectedgilCmdQueueAfterReset(DeviceQueue *deviceQueue);
template <typename T>
class DeviceHostQueueFixture : public api_fixture,
public ::testing::Test {
public:
void SetUp() override {
api_fixture::SetUp();
}
void TearDown() override {
api_fixture::TearDown();
}
cl_command_queue createClQueue(cl_queue_properties properties[5] = deviceQueueProperties::noProperties) {
return create(pContext, devices[0], retVal, properties);
}
T *createQueueObject(cl_queue_properties properties[5] = deviceQueueProperties::noProperties) {
using BaseType = typename T::BaseType;
cl_context context = (cl_context)(pContext);
auto clQueue = create(context, devices[0], retVal, properties);
return castToObject<T>(static_cast<BaseType *>(clQueue));
}
cl_command_queue create(cl_context ctx, cl_device_id device, cl_int &retVal,
cl_queue_properties properties[5] = deviceQueueProperties::noProperties);
};
class DeviceQueueHwTest : public DeviceHostQueueFixture<DeviceQueue> {
public:
using BaseClass = DeviceHostQueueFixture<DeviceQueue>;
void SetUp() override {
BaseClass::SetUp();
device = castToObject<Device>(devices[0]);
ASSERT_NE(device, nullptr);
}
void TearDown() override {
BaseClass::TearDown();
}
template <typename GfxFamily>
DeviceQueueHw<GfxFamily> *castToHwType(DeviceQueue *deviceQueue) {
return reinterpret_cast<DeviceQueueHw<GfxFamily> *>(deviceQueue);
}
template <typename GfxFamily>
size_t getMinimumSlbSize() {
return sizeof(typename GfxFamily::MEDIA_STATE_FLUSH) +
sizeof(typename GfxFamily::MEDIA_INTERFACE_DESCRIPTOR_LOAD) +
sizeof(typename GfxFamily::PIPE_CONTROL) +
sizeof(typename GfxFamily::GPGPU_WALKER) +
sizeof(typename GfxFamily::MEDIA_STATE_FLUSH) +
sizeof(typename GfxFamily::PIPE_CONTROL) +
DeviceQueueHw<GfxFamily>::getCSPrefetchSize(); // prefetch size
}
DeviceQueue *deviceQueue;
Device *device;
};
}

View File

@ -0,0 +1,120 @@
/*
* 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.
*/
#pragma once
#include "runtime/device_queue/device_queue.h"
#include "unit_tests/command_queue/command_queue_fixture.h"
#include "unit_tests/fixtures/execution_model_kernel_fixture.h"
#include "unit_tests/mocks/mock_kernel.h"
class DeviceQueueFixture {
public:
void SetUp(Context *context, Device *device) {
cl_int errcodeRet = 0;
cl_queue_properties properties[3];
properties[0] = CL_QUEUE_PROPERTIES;
properties[1] = CL_QUEUE_ON_DEVICE | CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE;
properties[2] = 0;
ASSERT_NE(nullptr, context);
ASSERT_NE(nullptr, device);
pDevQueue = DeviceQueue::create(context, device,
properties[0],
errcodeRet);
ASSERT_NE(nullptr, pDevQueue);
auto devQueue = context->getDefaultDeviceQueue();
ASSERT_NE(nullptr, devQueue);
EXPECT_EQ(pDevQueue, devQueue);
}
void TearDown() {
delete pDevQueue;
}
DeviceQueue *pDevQueue;
};
class ExecutionModelKernelTest : public ExecutionModelKernelFixture,
public CommandQueueHwFixture,
public DeviceQueueFixture {
public:
ExecutionModelKernelTest(){};
void SetUp() override {
ExecutionModelKernelFixture::SetUp();
CommandQueueHwFixture::SetUp(pDevice, 0);
DeviceQueueFixture::SetUp(context, pDevice);
}
void TearDown() override {
DeviceQueueFixture::TearDown();
CommandQueueHwFixture::TearDown();
ExecutionModelKernelFixture::TearDown();
}
};
class ExecutionModelSchedulerTest : public DeviceFixture,
public CommandQueueHwFixture,
public DeviceQueueFixture {
public:
ExecutionModelSchedulerTest(){};
void SetUp() override {
DeviceFixture::SetUp();
CommandQueueHwFixture::SetUp(pDevice, 0);
DeviceQueueFixture::SetUp(context, pDevice);
parentKernel = MockParentKernel::create(*pDevice);
ASSERT_NE(nullptr, parentKernel);
}
void TearDown() override {
delete parentKernel;
DeviceQueueFixture::TearDown();
CommandQueueHwFixture::TearDown();
DeviceFixture::TearDown();
}
MockParentKernel *parentKernel;
};
struct ParentKernelCommandQueueFixture : public CommandQueueHwFixture,
testing::Test {
void SetUp() override {
device = DeviceHelper<>::create();
CommandQueueHwFixture::SetUp(device, 0);
}
void TearDown() override {
CommandQueueHwFixture::TearDown();
BuiltIns::shutDown();
delete device;
}
MockDevice *device;
};

View File

@ -0,0 +1,98 @@
/*
* 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.
*/
#pragma once
#include "runtime/kernel/kernel.h"
#include "unit_tests/fixtures/platform_fixture.h"
#include "unit_tests/program/program_from_binary.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "test.h"
using namespace OCLRT;
class ExecutionModelKernelFixture : public ProgramFromBinaryTest,
public PlatformFixture {
public:
ExecutionModelKernelFixture() : pKernel(nullptr),
retVal(CL_SUCCESS) {
}
~ExecutionModelKernelFixture() override = default;
protected:
void SetUp() override {
PlatformFixture::SetUp(numPlatformDevices, platformDevices);
std::string temp;
temp.assign(pPlatform->getDevice(0)->getDeviceInfo().clVersion);
if (temp.find("OpenCL 1.2") != std::string::npos) {
pDevice = DeviceHelper<>::create();
return;
}
std::string options("-cl-std=CL2.0");
this->setOptions(options);
ProgramFromBinaryTest::SetUp();
ASSERT_NE(nullptr, pProgram);
ASSERT_EQ(CL_SUCCESS, retVal);
cl_device_id device = pDevice;
retVal = pProgram->build(
1,
&device,
nullptr,
nullptr,
nullptr,
false);
ASSERT_EQ(CL_SUCCESS, retVal);
// create a kernel
pKernel = Kernel::create<MockKernel>(
pProgram,
*pProgram->getKernelInfo(KernelName),
&retVal);
ASSERT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, pKernel);
}
void TearDown() override {
delete pKernel;
std::string temp;
temp.assign(pPlatform->getDevice(0)->getDeviceInfo().clVersion);
if (temp.find("OpenCL 1.2") != std::string::npos) {
delete pDevice;
pDevice = nullptr;
}
ProgramFromBinaryTest::TearDown();
PlatformFixture::TearDown();
}
Kernel *pKernel;
cl_int retVal;
};

View File

@ -0,0 +1,76 @@
/*
* 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.
*/
#pragma once
#include "gtest/gtest.h"
#include "runtime/helpers/aligned_memory.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "unit_tests/mocks/mock_gmm_resource_info.h"
using namespace OCLRT;
class GmmFixture {
public:
virtual void SetUp() {
}
virtual void TearDown() {
}
Gmm *getGmm(void *ptr, size_t size) {
size_t alignedSize = alignSizeWholePage(ptr, size);
void *alignedPtr = alignUp(ptr, 4096);
Gmm *gmm;
gmm = new Gmm;
EXPECT_NE(gmm, nullptr);
gmm->resourceParams.Type = RESOURCE_BUFFER;
gmm->resourceParams.Format = GMM_FORMAT_GENERIC_8BIT;
gmm->resourceParams.BaseWidth = (uint32_t)alignedSize;
gmm->resourceParams.BaseHeight = 1;
gmm->resourceParams.Depth = 1;
gmm->resourceParams.Usage = GMM_RESOURCE_USAGE_OCL_BUFFER;
gmm->resourceParams.pExistingSysMem = reinterpret_cast<GMM_VOIDPTR64>(alignedPtr);
gmm->resourceParams.ExistingSysMemSize = alignedSize;
gmm->resourceParams.BaseAlignment = 0;
gmm->resourceParams.Flags.Info.ExistingSysMem = 1;
gmm->resourceParams.Flags.Info.Linear = 1;
gmm->resourceParams.Flags.Info.Cacheable = 1;
gmm->resourceParams.Flags.Gpu.Texture = 1;
gmm->create();
EXPECT_NE(gmm->gmmResourceInfo.get(), nullptr);
return gmm;
}
void releaseGmm(Gmm *gmm) {
delete gmm;
}
};

View File

@ -0,0 +1,157 @@
/*
* 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.
*/
#pragma once
#include "config.h"
#include "test.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/helpers/aligned_memory.h"
#include "runtime/memory_manager/memory_manager.h"
#include "unit_tests/command_stream/command_stream_fixture.h"
#include "unit_tests/command_queue/command_queue_fixture.h"
#include "unit_tests/indirect_heap/indirect_heap_fixture.h"
#include "unit_tests/fixtures/built_in_fixture.h"
#include "unit_tests/fixtures/hello_world_kernel_fixture.h"
#include "unit_tests/fixtures/memory_management_fixture.h"
#include "gen_cmd_parse.h"
#include "unit_tests/fixtures/buffer_fixture.h"
namespace OCLRT {
// Factory used to pick various ingredients for use in aggregate tests
struct HelloWorldFixtureFactory {
typedef OCLRT::IndirectHeapFixture IndirectHeapFixture;
typedef OCLRT::CommandStreamFixture CommandStreamFixture;
typedef OCLRT::CommandQueueHwFixture CommandQueueFixture;
typedef OCLRT::HelloWorldKernelFixture KernelFixture;
};
// Instantiates a fixture based on the supplied fixture factory.
// Used by most tests for integration testing with command queues.
template <typename FixtureFactory>
struct HelloWorldFixture : public FixtureFactory::IndirectHeapFixture,
public FixtureFactory::CommandStreamFixture,
public FixtureFactory::CommandQueueFixture,
public FixtureFactory::KernelFixture,
public DeviceFixture,
public BuiltInFixture,
public MemoryManagementFixture {
typedef typename FixtureFactory::IndirectHeapFixture IndirectHeapFixture;
typedef typename FixtureFactory::CommandStreamFixture CommandStreamFixture;
typedef typename FixtureFactory::CommandQueueFixture CommandQueueFixture;
typedef typename FixtureFactory::KernelFixture KernelFixture;
using CommandQueueFixture::pCmdQ;
using CommandStreamFixture::pCS;
using KernelFixture::pKernel;
using IndirectHeapFixture::SetUp;
using BuiltInFixture::SetUp;
using HelloWorldKernelFixture::SetUp;
using CommandStreamFixture::SetUp;
using CommandQueueFixture::SetUp;
HelloWorldFixture() : pSrcMemory(nullptr),
pDestMemory(nullptr),
sizeUserMemory(128 * sizeof(float)),
kernelFilename("CopyBuffer_simd"),
kernelName("CopyBuffer") {
}
public:
virtual void SetUp() {
MemoryManagementFixture::SetUp();
DeviceFixture::SetUp();
ASSERT_NE(nullptr, pDevice);
BuiltInFixture::SetUp(pDevice);
ASSERT_NE(nullptr, pBuiltIns);
CommandQueueFixture::SetUp(pDevice, 0);
ASSERT_NE(nullptr, pCmdQ);
CommandStreamFixture::SetUp(pCmdQ);
ASSERT_NE(nullptr, pCS);
IndirectHeapFixture::SetUp(pCmdQ);
KernelFixture::SetUp(pDevice, kernelFilename, kernelName);
ASSERT_NE(nullptr, pKernel);
pDestMemory = alignedMalloc(sizeUserMemory, 4096);
ASSERT_NE(nullptr, pDestMemory);
pSrcMemory = alignedMalloc(sizeUserMemory, 4096);
ASSERT_NE(nullptr, pSrcMemory);
// Initialize user memory to known values
memset(pDestMemory, 0x11, sizeUserMemory);
memset(pSrcMemory, 0x22, sizeUserMemory);
pKernel->setArgSvm(0, sizeUserMemory, pSrcMemory);
pKernel->setArgSvm(1, sizeUserMemory, pDestMemory);
BufferDefaults::context = new MockContext(pDevice);
}
virtual void TearDown() {
delete BufferDefaults::context;
alignedFree(pSrcMemory);
alignedFree(pDestMemory);
KernelFixture::TearDown();
IndirectHeapFixture::TearDown();
CommandStreamFixture::TearDown();
CommandQueueFixture::TearDown();
BuiltInFixture::TearDown();
DeviceFixture::TearDown();
MemoryManagementFixture::TearDown();
}
void *pSrcMemory;
void *pDestMemory;
size_t sizeUserMemory;
const char *kernelFilename;
const char *kernelName;
cl_int callOneWorkItemNDRKernel(cl_event *eventWaitList = nullptr, cl_int waitListSize = 0, cl_event *returnEvent = nullptr) {
cl_uint workDim = 1;
size_t globalWorkOffset[3] = {0, 0, 0};
size_t globalWorkSize[3] = {1, 1, 1};
size_t localWorkSize[3] = {1, 1, 1};
return pCmdQ->enqueueKernel(
pKernel,
workDim,
globalWorkOffset,
globalWorkSize,
localWorkSize,
waitListSize,
eventWaitList,
returnEvent);
}
};
template <typename FixtureFactory>
struct HelloWorldTest : Test<HelloWorldFixture<FixtureFactory>> {
};
template <typename FixtureFactory>
struct HelloWorldTestWithParam : HelloWorldFixture<FixtureFactory> {
};
}

View File

@ -0,0 +1,118 @@
/*
* 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.
*/
#pragma once
#include "gtest/gtest.h"
#include "CL/cl.h"
#include "runtime/device/device.h"
#include "runtime/helpers/file_io.h"
#include "runtime/kernel/kernel.h"
#include "runtime/platform/platform.h"
#include "runtime/program/program.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_program.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "unit_tests/helpers/test_files.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/fixtures/program_fixture.h"
namespace OCLRT {
class Kernel;
class Program;
struct HelloWorldKernelFixture : public ProgramFixture {
using ProgramFixture::SetUp;
virtual void SetUp(Device *pDevice, const char *kernelFilenameStr, const char *kernelNameStr, const char *options = nullptr) {
ProgramFixture::SetUp();
pTestFilename = new std::string(kernelFilenameStr);
pKernelName = new std::string(kernelNameStr);
if (strstr(kernelFilenameStr, "_simd") != nullptr) {
pTestFilename->append(std::to_string(simd));
}
cl_device_id device = pDevice;
pContext = Context::create<MockContext>(nullptr, DeviceVector(&device, 1), nullptr, nullptr, retVal);
ASSERT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, pContext);
if (options) {
std::string optionsToProgram(options);
if (optionsToProgram.find("-cl-std=CL2.0") != std::string::npos) {
ASSERT_TRUE(pDevice->getSupportedClVersion() >= 20u);
}
CreateProgramFromBinary<Program>(
pContext,
&device,
*pTestFilename,
optionsToProgram);
} else {
CreateProgramFromBinary<Program>(
pContext,
&device,
*pTestFilename);
}
ASSERT_NE(nullptr, pProgram);
retVal = pProgram->build(
1,
&device,
nullptr,
nullptr,
nullptr,
false);
ASSERT_EQ(CL_SUCCESS, retVal);
// create a kernel
pKernel = Kernel::create<MockKernel>(
pProgram,
*pProgram->getKernelInfo(pKernelName->c_str()),
&retVal);
EXPECT_NE(nullptr, pKernel);
EXPECT_EQ(CL_SUCCESS, retVal);
}
virtual void TearDown() {
delete pKernelName;
delete pTestFilename;
delete pKernel;
pKernel = nullptr;
pContext->release();
ProgramFixture::TearDown();
}
std::string *pTestFilename = nullptr;
std::string *pKernelName = nullptr;
cl_uint simd = 32;
cl_int retVal = CL_SUCCESS;
Kernel *pKernel = nullptr;
MockContext *pContext = nullptr;
};
} // namespace OCLRT

View File

@ -0,0 +1,105 @@
/*
* 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 "unit_tests/fixtures/image_fixture.h"
#include "unit_tests/mocks/mock_context.h"
using OCLRT::MockContext;
static const size_t imageWidth = 7;
static const size_t imageHeight = 7;
static const size_t imageDepth = 7;
static const size_t imageArray = imageDepth;
const cl_image_format Image1dDefaults::imageFormat = {
CL_R,
CL_FLOAT};
const cl_image_format LuminanceImage::imageFormat = {
CL_LUMINANCE,
CL_FLOAT};
const cl_image_desc Image1dDefaults::imageDesc = {
CL_MEM_OBJECT_IMAGE1D,
imageWidth,
imageHeight,
1,
1,
0,
0,
0,
0,
{nullptr}};
const cl_image_desc Image2dDefaults::imageDesc = {
CL_MEM_OBJECT_IMAGE2D,
imageWidth,
imageHeight,
1,
1,
0,
0,
0,
0,
{nullptr}};
const cl_image_desc Image3dDefaults::imageDesc = {
CL_MEM_OBJECT_IMAGE3D,
imageWidth,
imageHeight,
imageDepth,
1,
0,
0,
0,
0,
{nullptr}};
const cl_image_desc Image2dArrayDefaults::imageDesc = {
CL_MEM_OBJECT_IMAGE2D_ARRAY,
imageWidth,
imageHeight,
0,
imageArray,
0,
0,
0,
0,
{nullptr}};
const cl_image_desc Image1dArrayDefaults::imageDesc = {
CL_MEM_OBJECT_IMAGE1D_ARRAY,
imageWidth,
0,
0,
imageArray,
0,
0,
0,
0,
{nullptr}};
static float imageMemory[imageWidth * imageHeight * imageDepth] = {};
void *Image1dDefaults::hostPtr = imageMemory;
OCLRT::Context *Image1dDefaults::context = nullptr;

View File

@ -0,0 +1,114 @@
/*
* 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.
*/
#pragma once
#include "runtime/mem_obj/image.h"
#include "unit_tests/mocks/mock_context.h"
#include "CL/cl.h"
#include <cassert>
#include <cstdio>
struct Image1dDefaults {
enum { flags = 0 };
static const cl_image_format imageFormat;
static const cl_image_desc imageDesc;
static void *hostPtr;
static OCLRT::Context *context;
};
struct Image2dDefaults : public Image1dDefaults {
static const cl_image_desc imageDesc;
};
struct Image3dDefaults : public Image2dDefaults {
static const cl_image_desc imageDesc;
};
struct Image2dArrayDefaults : public Image2dDefaults {
static const cl_image_desc imageDesc;
};
struct Image1dArrayDefaults : public Image2dDefaults {
static const cl_image_desc imageDesc;
};
struct LuminanceImage : public Image2dDefaults {
static const cl_image_format imageFormat;
};
template <typename BaseClass>
struct ImageUseHostPtr : public BaseClass {
enum { flags = BaseClass::flags | CL_MEM_USE_HOST_PTR };
};
template <typename BaseClass>
struct ImageReadOnly : public BaseClass {
enum { flags = BaseClass::flags | CL_MEM_READ_ONLY };
};
template <typename BaseClass>
struct ImageWriteOnly : public BaseClass {
enum { flags = BaseClass::flags | CL_MEM_WRITE_ONLY };
};
template <typename Traits>
struct ImageHelper {
using Context = OCLRT::Context;
using Image = OCLRT::Image;
using MockContext = OCLRT::MockContext;
static Image *create(Context *context = Traits::context, const cl_image_desc *imgDesc = &Traits::imageDesc,
const cl_image_format *imgFormat = &Traits::imageFormat) {
auto retVal = CL_INVALID_VALUE;
auto surfaceFormat = Image::getSurfaceFormatFromTable(Traits::flags, imgFormat);
auto image = Image::create(
context,
Traits::flags,
surfaceFormat,
imgDesc,
Traits::hostPtr,
retVal);
assert(image != nullptr);
return image;
}
};
template <typename Traits = Image1dDefaults>
struct Image1dHelper : public ImageHelper<Traits> {
};
template <typename Traits = Image2dDefaults>
struct Image2dHelper : public ImageHelper<Traits> {
};
template <typename Traits = Image3dDefaults>
struct Image3dHelper : public ImageHelper<Traits> {
};
template <typename Traits = Image2dArrayDefaults>
struct Image2dArrayHelper : public ImageHelper<Traits> {
};
template <typename Traits = Image1dArrayDefaults>
struct Image1dArrayHelper : public ImageHelper<Traits> {
};

View File

@ -0,0 +1,121 @@
/*
* 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 "runtime/helpers/aligned_memory.h"
#include "runtime/helpers/string.h"
#include "unit_tests/fixtures/kernel_data_fixture.h"
void KernelDataTest::buildAndDecode() {
cl_int error = CL_SUCCESS;
kernelBinaryHeader.CheckSum = checkSum;
kernelBinaryHeader.DynamicStateHeapSize = dshSize;
kernelBinaryHeader.GeneralStateHeapSize = gshSize;
kernelBinaryHeader.KernelHeapSize = kernelHeapSize;
kernelBinaryHeader.KernelNameSize = kernelNameSize;
kernelBinaryHeader.KernelUnpaddedSize = kernelUnpaddedSize;
kernelBinaryHeader.PatchListSize = patchListSize + sizeof(SPatchDataParameterStream);
kernelBinaryHeader.ShaderHashCode = shaderHashCode;
kernelBinaryHeader.SurfaceStateHeapSize = sshSize;
kernelDataSize = sizeof(SKernelBinaryHeaderCommon) +
kernelNameSize + sshSize + dshSize + gshSize + kernelHeapSize + patchListSize;
kernelDataSize += sizeof(SPatchDataParameterStream);
program.setDevice(pDevice);
pKernelData = reinterpret_cast<char *>(alignedMalloc(kernelDataSize, MemoryConstants::cacheLineSize));
ASSERT_NE(nullptr, pKernelData);
// kernel blob
pCurPtr = pKernelData;
// kernel header
// first clear it because sizeof() > sum of sizeof(fields). this is due to packing
memset(pCurPtr, 0, sizeof(SKernelBinaryHeaderCommon));
*(SKernelBinaryHeaderCommon *)pCurPtr = kernelBinaryHeader;
pCurPtr += sizeof(SKernelBinaryHeaderCommon);
// kernel name
memset(pCurPtr, 0, kernelNameSize);
strcpy_s(pCurPtr, strlen(kernelName.c_str()) + 1, kernelName.c_str());
pCurPtr += kernelNameSize;
// kernel heap
memcpy_s(pCurPtr, kernelHeapSize, pKernelHeap, kernelHeapSize);
pCurPtr += kernelHeapSize;
// general state heap
memcpy_s(pCurPtr, gshSize, pGsh, gshSize);
pCurPtr += gshSize;
// dynamic state heap
memcpy_s(pCurPtr, dshSize, pDsh, dshSize);
pCurPtr += dshSize;
// surface state heap
memcpy_s(pCurPtr, sshSize, pSsh, sshSize);
pCurPtr += sshSize;
// patch list
memcpy_s(pCurPtr, patchListSize, pPatchList, patchListSize);
pCurPtr += patchListSize;
// add a data stream member
iOpenCL::SPatchDataParameterStream dataParameterStream;
dataParameterStream.Token = PATCH_TOKEN_DATA_PARAMETER_STREAM;
dataParameterStream.Size = sizeof(SPatchDataParameterStream);
dataParameterStream.DataParameterStreamSize = 0x40;
memcpy_s(pCurPtr, sizeof(SPatchDataParameterStream),
&dataParameterStream, sizeof(SPatchDataParameterStream));
pCurPtr += sizeof(SPatchDataParameterStream);
// now build a program with this kernel data
error = program.build(pKernelData, kernelDataSize);
EXPECT_EQ(CL_SUCCESS, error);
// extract the kernel info
pKernelInfo = program.Program::getKernelInfo(kernelName.c_str());
// validate kernel info
// vaidate entire set of data
EXPECT_EQ(0, memcmp(pKernelInfo->heapInfo.pBlob, pKernelData, kernelDataSize));
// validate header
EXPECT_EQ(0, memcmp(pKernelInfo->heapInfo.pKernelHeader, &kernelBinaryHeader, sizeof(SKernelBinaryHeaderCommon)));
// validate name
EXPECT_STREQ(pKernelInfo->name.c_str(), kernelName.c_str());
// validate each heap
if (pKernelHeap != nullptr)
EXPECT_EQ(0, memcmp(pKernelInfo->heapInfo.pKernelHeap, pKernelHeap, kernelHeapSize));
if (pGsh != nullptr)
EXPECT_EQ(0, memcmp(pKernelInfo->heapInfo.pGsh, pGsh, gshSize));
if (pDsh != nullptr)
EXPECT_EQ(0, memcmp(pKernelInfo->heapInfo.pDsh, pDsh, dshSize));
if (pSsh != nullptr)
EXPECT_EQ(0, memcmp(pKernelInfo->heapInfo.pSsh, pSsh, sshSize));
if (pPatchList != nullptr)
EXPECT_EQ(0, memcmp(pKernelInfo->heapInfo.pPatchList, pPatchList, patchListSize));
}

View File

@ -0,0 +1,99 @@
/*
* 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.
*/
#pragma once
#include "gtest/gtest.h"
#include "runtime/program/kernel_info.h"
#include "unit_tests/mocks/mock_device.h"
#include "unit_tests/mocks/mock_program.h"
using namespace OCLRT;
using namespace iOpenCL;
class KernelDataTest : public testing::Test {
public:
KernelDataTest() {
memset(&kernelBinaryHeader, 0x00, sizeof(SKernelBinaryHeaderCommon));
pCurPtr = nullptr;
pKernelData = nullptr;
kernelName = "test";
pDsh = nullptr;
pGsh = nullptr;
pKernelHeap = nullptr;
pSsh = nullptr;
pPatchList = nullptr;
kernelDataSize = 0;
kernelNameSize = (uint32_t)alignUp(strlen(kernelName.c_str()) + 1, sizeof(uint32_t));
dshSize = 0;
gshSize = 0;
kernelHeapSize = 0;
sshSize = 0;
patchListSize = 0;
checkSum = 0;
shaderHashCode = 0;
kernelUnpaddedSize = 0;
pKernelInfo = nullptr;
}
void buildAndDecode();
protected:
void SetUp() override {
kernelBinaryHeader.KernelNameSize = kernelNameSize;
pDevice = Device::create<MockDevice>(nullptr);
}
void TearDown() override {
delete pDevice;
alignedFree(pKernelData);
}
char *pCurPtr;
char *pKernelData;
SKernelBinaryHeaderCommon kernelBinaryHeader;
std::string kernelName;
void *pDsh;
void *pGsh;
void *pKernelHeap;
void *pSsh;
void *pPatchList;
uint32_t kernelDataSize;
uint32_t kernelNameSize;
uint32_t dshSize;
uint32_t gshSize;
uint32_t kernelHeapSize;
uint32_t sshSize;
uint32_t patchListSize;
uint32_t checkSum;
uint64_t shaderHashCode;
uint32_t kernelUnpaddedSize;
MockProgram program;
MockDevice *pDevice;
const KernelInfo *pKernelInfo;
};

View File

@ -0,0 +1,44 @@
/*
* 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.
*/
#pragma once
#include "unit_tests/fixtures/memory_management_fixture.h"
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
using namespace OCLRT;
class MemoryAllocatorFixture : public MemoryManagementFixture {
protected:
MemoryManager *memoryManager;
public:
void SetUp() override {
MemoryManagementFixture::SetUp();
memoryManager = new OsAgnosticMemoryManager;
}
void TearDown() override {
delete memoryManager;
MemoryManagementFixture::TearDown();
}
};

View File

@ -0,0 +1,322 @@
/*
* 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 "runtime/helpers/options.h"
#include "unit_tests/fixtures/memory_management_fixture.h"
#include "unit_tests/helpers/memory_management.h"
#include <cinttypes>
#if defined(__linux__)
#include <cstdio>
#include <execinfo.h>
#include <cxxabi.h>
#include <dlfcn.h>
#elif defined(_WIN32)
#include <Windows.h>
#pragma warning(push) // Saves the current warning state.
#pragma warning(disable : 4091) // Temporarily disables warning 4091.
#include <DbgHelp.h>
#pragma warning(pop) // Restores the warning state.
#pragma comment(lib, "Dbghelp.lib")
#endif
namespace Os {
extern const char *frontEndDllName;
extern const char *igcDllName;
} // namespace Os
bool printMemoryOpCallStack = true;
void MemoryManagementFixture::SetUp() {
EXPECT_EQ(static_cast<size_t>(-1), MemoryManagement::failingAllocation);
MemoryManagement::indexAllocation = 0;
MemoryManagement::indexDeallocation = 0;
MemoryManagement::failingAllocation = -1;
previousAllocations = MemoryManagement::numAllocations.load();
MemoryManagement::logTraces = OCLRT::captureCallStacks;
}
void MemoryManagementFixture::TearDown() {
clearFailingAllocation();
checkForLeaks();
MemoryManagement::logTraces = false;
}
void MemoryManagementFixture::setFailingAllocation(size_t allocation) {
MemoryManagement::indexAllocation = 0;
MemoryManagement::failingAllocation = allocation;
}
void MemoryManagementFixture::clearFailingAllocation() {
MemoryManagement::failingAllocation = -1;
}
size_t MemoryManagementFixture::enumerateLeak(size_t indexAllocationTop, size_t indexDeallocationTop, bool lookFromBack, bool requireCallStack, bool fastLookup) {
using MemoryManagement::eventsAllocated;
using MemoryManagement::eventsDeallocated;
using MemoryManagement::AllocationEvent;
static auto start = invalidLeakIndex;
auto newIndex = start == invalidLeakIndex ? 0 : start;
bool potentialLeak = false;
auto potentialLeakIndex = newIndex;
for (; newIndex < indexAllocationTop; ++newIndex) {
auto currentIndex = lookFromBack ? indexAllocationTop - newIndex - 1 : newIndex;
auto &eventAllocation = eventsAllocated[currentIndex];
if (requireCallStack && eventAllocation.frames == 0) {
continue;
}
if (fastLookup && eventAllocation.fastLeakDetectionMode == 0) {
continue;
}
if (eventAllocation.event != AllocationEvent::EVENT_UNKNOWN) {
// Should be some sort of allocation
size_t deleteIndex = 0;
for (; deleteIndex < indexDeallocationTop; ++deleteIndex) {
auto &eventDeallocation = eventsDeallocated[deleteIndex];
if (eventDeallocation.address == eventAllocation.address &&
eventDeallocation.event != AllocationEvent::EVENT_UNKNOWN) {
//this memory was once freed, now it is allocated but not freed
if (requireCallStack && eventDeallocation.frames == 0) {
potentialLeak = true;
potentialLeakIndex = currentIndex;
continue;
}
//allocated with fast lookup, but deallocated other way, not a match
if (fastLookup && eventDeallocation.fastLeakDetectionMode != 1) {
continue;
}
// Clear the NEW and DELETE event.
eventAllocation.event = AllocationEvent::EVENT_UNKNOWN;
eventDeallocation.event = AllocationEvent::EVENT_UNKNOWN;
potentialLeak = false;
// Found a corresponding match
break;
}
}
if (potentialLeak) {
return potentialLeakIndex;
}
if (deleteIndex == indexDeallocationTop) {
start = newIndex + 1;
return currentIndex;
}
}
}
start = invalidLeakIndex;
return start;
}
std::string printCallStack(const MemoryManagement::AllocationEvent &event) {
std::string result = "";
printf("printCallStack.%d.%d\n", printMemoryOpCallStack, event.frames);
if (!OCLRT::captureCallStacks) {
printf("for detailed stack information turn on captureCallStacks in options.h\n");
}
if (printMemoryOpCallStack && event.frames > 0) {
#if defined(__linux__)
char **bt = backtrace_symbols(event.callstack, event.frames);
char *demangled;
int status;
char output[1024];
Dl_info info;
result += "\n";
for (int i = 0; i < event.frames; ++i) {
dladdr(event.callstack[i], &info);
if (info.dli_sname) {
demangled = nullptr;
status = -1;
if (info.dli_sname[0] == '_') {
demangled = abi::__cxa_demangle(info.dli_sname, nullptr, 0, &status);
}
snprintf(output, sizeof(output), "%-3d %*p %s + %zd\n",
(event.frames - i - 1), (int)(sizeof(void *) + 2), event.callstack[i],
status == 0 ? demangled : info.dli_sname == 0 ? bt[i] : info.dli_sname,
(char *)event.callstack[i] - (char *)info.dli_saddr);
free(demangled);
} else {
snprintf(output, sizeof(output), "%-3d %*p %s\n",
(event.frames - i - 1), (int)(sizeof(void *) + 2), event.callstack[i], bt[i]);
}
result += std::string(output);
}
result += "\n";
free(bt);
#elif defined(_WIN32)
SYMBOL_INFO *symbol;
HANDLE process;
process = GetCurrentProcess();
SymInitialize(process, NULL, TRUE);
symbol = (SYMBOL_INFO *)calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1);
symbol->MaxNameLen = 255;
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
for (int i = 0; i < event.frames; i++) {
SymFromAddr(process, (DWORD64)(event.callstack[i]), 0, symbol);
printf("%i: %s - 0x%0" PRIx64 "\n", event.frames - i - 1, symbol->Name, symbol->Address);
}
free(symbol);
#endif
}
return result;
}
::testing::AssertionResult MemoryManagementFixture::assertLeak(
const char *leakExpr,
size_t leakIndex) {
using MemoryManagement::eventsAllocated;
using MemoryManagement::AllocationEvent;
if (leakIndex == invalidLeakIndex) {
return ::testing::AssertionSuccess();
}
auto &event = eventsAllocated[leakIndex];
switch (event.event) {
case AllocationEvent::EVENT_DELETE:
return ::testing::AssertionFailure() << "event[" << leakIndex
<< "]: delete doesn't have corresponding new. allocation address="
<< event.address
<< ", allocation size=" << event.size << printCallStack(event);
break;
case AllocationEvent::EVENT_DELETE_ARRAY:
return ::testing::AssertionFailure() << "event[" << leakIndex
<< "]: delete[] doesn't have corresponding new[]. allocation address="
<< event.address
<< ", allocation size=" << event.size << printCallStack(event);
break;
case AllocationEvent::EVENT_NEW:
return ::testing::AssertionFailure() << "event[" << leakIndex
<< "]: new doesn't have corresponding delete. allocation address="
<< event.address
<< ", allocation size=" << event.size << printCallStack(event);
break;
case AllocationEvent::EVENT_NEW_NOTHROW:
return ::testing::AssertionFailure() << "event[" << leakIndex
<< "]: new (std::nothrow) doesn't have corresponding delete. allocation address="
<< event.address
<< ", allocation size=" << event.size << printCallStack(event);
break;
case AllocationEvent::EVENT_NEW_ARRAY:
return ::testing::AssertionFailure() << "event[" << leakIndex
<< "]: new [] doesn't have corresponding delete[]. allocation address="
<< event.address
<< ", allocation size=" << event.size << printCallStack(event);
break;
case AllocationEvent::EVENT_NEW_ARRAY_NOTHROW:
return ::testing::AssertionFailure() << "event[" << leakIndex
<< "] new (std::nothrow) [] doesn't have corresponding delete[]. allocation address="
<< event.address
<< ", allocation size=" << event.size << printCallStack(event);
break;
case AllocationEvent::EVENT_NEW_ARRAY_NOTHROW_FAIL:
case AllocationEvent::EVENT_NEW_ARRAY_FAIL:
case AllocationEvent::EVENT_NEW_NOTHROW_FAIL:
case AllocationEvent::EVENT_NEW_FAIL:
case AllocationEvent::EVENT_UNKNOWN:
default:
return ::testing::AssertionFailure() << "Unknown event[" << leakIndex << "] detected. allocation size=" << event.size;
break;
}
}
void MemoryManagementFixture::checkForLeaks() {
// We have to alias MemoryManagement::numAllocations because
// the following EXPECT_EQ actually allocates more memory :-)
auto currentAllocations = MemoryManagement::numAllocations.load();
auto indexAllocationTop = MemoryManagement::indexAllocation.load();
auto indexDellocationTop = MemoryManagement::indexDeallocation.load();
if (previousAllocations != currentAllocations) {
auto testInfo = ::testing::UnitTest::GetInstance()->current_test_info();
auto testResult = testInfo->result();
if (testResult->Passed()) {
//EXPECT_EQ(previousAllocations, currentAllocations);
size_t leakEventIndex;
do {
leakEventIndex = enumerateLeak(indexAllocationTop, indexDellocationTop);
EXPECT_PRED_FORMAT1(assertLeak, leakEventIndex);
auto invalidLeakIndexValues = invalidLeakIndex;
EXPECT_EQ(leakEventIndex, invalidLeakIndexValues);
} while (leakEventIndex != invalidLeakIndex);
} else {
printf("*** WARNING: Leaks found but dumping disabled during test failure ***\n");
}
}
}
void MemoryManagementFixture::injectFailures(InjectedFunction &method, uint32_t maxIndex) {
MemoryManagement::indexAllocation = 0;
method(-1);
auto numCurrentAllocations = MemoryManagement::indexAllocation.load();
for (auto i = 0u; i < numCurrentAllocations; i++) {
// Force a failure
MemoryManagement::indexAllocation = numCurrentAllocations;
MemoryManagement::failingAllocation = i + numCurrentAllocations;
if (MemoryManagement::eventsAllocated[i].event == MemoryManagement::AllocationEvent::EVENT_NEW ||
MemoryManagement::eventsAllocated[i].event == MemoryManagement::AllocationEvent::EVENT_NEW_ARRAY) {
continue;
}
if (maxIndex != 0 && i > maxIndex) {
break;
}
// Call the method under test
method(i);
// Restore allocations
MemoryManagement::failingAllocation = -1;
}
MemoryManagement::failingAllocation = -1;
}
void MemoryManagementFixture::injectFailureOnIndex(InjectedFunction &method, uint32_t index) {
MemoryManagement::indexAllocation = 0;
method(-1);
auto numCurrentAllocations = MemoryManagement::indexAllocation.load();
// Force a failure
MemoryManagement::indexAllocation = numCurrentAllocations;
MemoryManagement::failingAllocation = index + numCurrentAllocations;
// Call the method under test
method(index);
// Restore allocations
MemoryManagement::failingAllocation = -1;
}

View File

@ -0,0 +1,59 @@
/*
* 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.
*/
#pragma once
#include "gtest/gtest.h"
#include "unit_tests/helpers/memory_management.h"
#include <functional>
struct MemoryManagementFixture {
static const auto nonfailingAllocation = static_cast<size_t>(-1);
static const auto invalidLeakIndex = static_cast<size_t>(-1);
virtual ~MemoryManagementFixture(){};
// Typical Fixture methods
virtual void SetUp(void);
virtual void TearDown(void);
// Helper methods
void setFailingAllocation(size_t allocation);
void clearFailingAllocation(void);
static size_t enumerateLeak(size_t indexAllocationTop, size_t indexDeallocationTop, bool lookFromEnd = false, bool requireCallStack = false, bool fastLookup = false);
::testing::AssertionResult assertLeak(
const char *leak_expr,
size_t leakIndex);
void checkForLeaks(void);
typedef std::function<void(size_t)> InjectedFunction;
void injectFailures(InjectedFunction &method, uint32_t maxIndex = 0);
void injectFailureOnIndex(InjectedFunction &method, uint32_t Index);
// Used to keep track of # of allocations prior at SetUp time
// Gets compared to # at TearDown time
size_t previousAllocations;
};
std::string printCallStack(const MemoryManagement::AllocationEvent &event);

View File

@ -0,0 +1,42 @@
/*
* 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 "unit_tests/fixtures/memory_manager_fixture.h"
#include "unit_tests/mocks/mock_csr.h"
#include "unit_tests/mocks/mock_memory_manager.h"
using namespace OCLRT;
using ::testing::NiceMock;
void MemoryManagerWithCsrFixture::SetUp() {
gmockMemoryManager = new NiceMock<GMockMemoryManager>;
memoryManager = gmockMemoryManager;
ON_CALL(*gmockMemoryManager, cleanAllocationList(::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(gmockMemoryManager, &GMockMemoryManager::MemoryManagerCleanAllocationList));
csr.tagAddress = &taskCount;
memoryManager->csr = &csr;
}
void MemoryManagerWithCsrFixture::TearDown() {
delete memoryManager;
}

View File

@ -0,0 +1,47 @@
/*
* 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.
*/
#pragma once
#include "unit_tests/mocks/mock_csr.h"
using namespace OCLRT;
namespace OCLRT {
class MemoryManager;
class GMockMemoryManager;
}; // namespace OCLRT
class MemoryManagerWithCsrFixture {
public:
MemoryManager *memoryManager;
GMockMemoryManager *gmockMemoryManager;
MockCommandStreamReceiver csr;
uint32_t taskCount = 0;
MemoryManagerWithCsrFixture() {
}
~MemoryManagerWithCsrFixture() = default;
void SetUp();
void TearDown();
};

View File

@ -0,0 +1,62 @@
/*
* 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 "unit_tests/fixtures/platform_fixture.h"
#include "runtime/device/device.h"
#include "runtime/platform/platform.h"
#include "gtest/gtest.h"
namespace OCLRT {
PlatformFixture::PlatformFixture()
: pPlatform(nullptr), num_devices(0), devices(nullptr)
{
}
void PlatformFixture::SetUp(size_t numDevices, const HardwareInfo **pDevices) {
pPlatform = platform();
ASSERT_EQ(0u, pPlatform->getNumDevices());
// setup platform / context
bool isInitialized = pPlatform->initialize(numDevices, pDevices);
ASSERT_EQ(true, isInitialized);
num_devices = static_cast<cl_uint>(pPlatform->getNumDevices());
ASSERT_GT(num_devices, 0u);
auto allDev = pPlatform->getDevices();
ASSERT_NE(nullptr, allDev);
devices = new cl_device_id[num_devices];
for (cl_uint deviceOrdinal = 0; deviceOrdinal < num_devices; ++deviceOrdinal) {
auto device = allDev[deviceOrdinal];
ASSERT_NE(nullptr, device);
devices[deviceOrdinal] = device;
}
}
void PlatformFixture::TearDown() {
pPlatform->shutdown();
delete[] devices;
}
}

View File

@ -0,0 +1,44 @@
/*
* 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.
*/
#pragma once
#include "runtime/api/cl_types.h"
#include "runtime/platform/platform.h"
namespace OCLRT {
struct HardwareInfo;
class PlatformFixture {
public:
PlatformFixture();
protected:
void SetUp(size_t numDevices, const HardwareInfo **pDevices);
void TearDown();
Platform *pPlatform;
cl_uint num_devices;
cl_device_id *devices;
};
}

View File

@ -0,0 +1,36 @@
/*
* 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 "runtime/program/create.inl"
#include "unit_tests/fixtures/program_fixture.inl"
#include "unit_tests/mocks/mock_program.h"
namespace OCLRT {
template OCLRT::MockProgram *Program::create<MockProgram>(cl_context, cl_uint, const char **, const size_t *, cl_int &);
template OCLRT::MockProgram *Program::create<MockProgram>(cl_context, cl_uint, const cl_device_id *, const size_t *, const unsigned char **, cl_int *, cl_int &);
template OCLRT::MockProgram *Program::create<MockProgram>(const char *, Context *, Device &, bool, cl_int *);
template void ProgramFixture::CreateProgramFromBinary<Program>(cl_context, cl_device_id *, const std::string &, const std::string &);
template void ProgramFixture::CreateProgramFromBinary<Program>(cl_context, cl_device_id *, const std::string &, cl_int &, const std::string &);
template void ProgramFixture::CreateProgramFromBinary<MockProgram>(cl_context, cl_device_id *, const std::string &, const std::string &);
template void ProgramFixture::CreateProgramFromBinary<MockProgram>(cl_context, cl_device_id *, const std::string &, cl_int &, const std::string &);
}

View File

@ -0,0 +1,106 @@
/*
* 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.
*/
#pragma once
#include "gtest/gtest.h"
#include "runtime/device/device.h"
#include "runtime/helpers/file_io.h"
#include "runtime/platform/platform.h"
#include "runtime/program/program.h"
#include "unit_tests/helpers/test_files.h"
namespace OCLRT {
class ProgramFixture {
public:
ProgramFixture() : pProgram(nullptr),
knownSource(nullptr),
knownSourceSize(0) {}
template <typename T>
void CreateProgramFromBinary(cl_context context,
cl_device_id *pDeviceList,
const std::string &binaryFileName,
cl_int &retVal,
const std::string &options = "");
template <typename T>
void CreateProgramFromBinary(cl_context pContext,
cl_device_id *pDeviceList,
const std::string &binaryFileName,
const std::string &options = "");
template <typename T = Program>
void CreateProgramWithSource(cl_context pContext,
cl_device_id *pDeviceList,
const std::string &SourceFileName) {
Cleanup();
cl_int retVal = CL_SUCCESS;
std::string testFile;
testFile.append(clFiles);
testFile.append(SourceFileName);
ASSERT_EQ(true, fileExists(testFile));
knownSourceSize = loadDataFromFile(
testFile.c_str(),
knownSource);
ASSERT_NE(0u, knownSourceSize);
ASSERT_NE(nullptr, knownSource);
pProgram = Program::create<T>(
pContext,
1,
(const char **)(&knownSource),
&knownSourceSize,
retVal);
ASSERT_NE(nullptr, pProgram);
ASSERT_EQ(CL_SUCCESS, retVal);
}
protected:
virtual void SetUp() {
}
virtual void TearDown() {
Cleanup();
}
void Cleanup() {
if (pProgram != nullptr) {
delete pProgram;
pProgram = nullptr;
}
if (knownSource != nullptr) {
deleteDataReadFromFile(knownSource);
knownSource = nullptr;
}
}
Program *pProgram;
void *knownSource;
size_t knownSourceSize;
};
} // namespace OCLRT

View File

@ -0,0 +1,80 @@
/*
* 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 "unit_tests/fixtures/program_fixture.h"
namespace OCLRT {
template <typename T>
void ProgramFixture::CreateProgramFromBinary(cl_context context,
cl_device_id *pDeviceList,
const std::string &binaryFileName,
cl_int &retVal,
const std::string &options) {
Cleanup();
std::string testFile;
retVal = CL_SUCCESS;
Context *pContext = castToObject<Context>(context);
testFile.append(testFiles);
testFile.append(binaryFileName);
testFile.append("_");
testFile.append(pContext->getDevice(0)->getProductAbbrev());
testFile.append(".bin");
testFile.append(options);
ASSERT_EQ(true, fileExists(testFile));
knownSourceSize = loadDataFromFile(
testFile.c_str(),
knownSource);
ASSERT_NE(0u, knownSourceSize);
ASSERT_NE(nullptr, knownSource);
pProgram = Program::create<T>(
context,
1,
pDeviceList,
&knownSourceSize,
(const unsigned char **)&knownSource,
nullptr,
retVal);
}
template <typename T>
void ProgramFixture::CreateProgramFromBinary(cl_context pContext,
cl_device_id *pDeviceList,
const std::string &binaryFileName,
const std::string &options) {
Cleanup();
cl_int retVal = CL_SUCCESS;
CreateProgramFromBinary<T>(
pContext,
pDeviceList,
binaryFileName,
retVal,
options);
ASSERT_NE(nullptr, pProgram);
ASSERT_EQ(CL_SUCCESS, retVal);
}
}

View File

@ -0,0 +1,73 @@
/*
* 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.
*/
#pragma once
#include "runtime/device/device.h"
#include "unit_tests/global_environment.h"
#include "unit_tests/helpers/test_files.h"
namespace OCLRT {
struct CommandQueueHwFixture;
struct CommandStreamFixture;
// helper functions to enforce MockCompiler input files
inline void overwriteBuiltInBinaryName(
Device *pDevice,
const char *filename,
bool appendOptionsToFileName = false) {
// set mock compiler to return expected kernel...
MockCompilerDebugVars fclDebugVars;
MockCompilerDebugVars igcDebugVars;
std::string builtInFileRoot = testFiles;
builtInFileRoot.append(filename);
std::string builtInBcFile = builtInFileRoot + "_";
std::string builtInGenFile = builtInFileRoot + "_";
auto product = pDevice->getProductAbbrev();
builtInBcFile.append(product);
builtInGenFile.append(product);
builtInBcFile.append(".bc");
builtInGenFile.append(".gen");
fclDebugVars.fileName = builtInBcFile;
fclDebugVars.appendOptionsToFileName = appendOptionsToFileName;
igcDebugVars.fileName = builtInGenFile;
igcDebugVars.appendOptionsToFileName = appendOptionsToFileName;
gEnvironment->fclPushDebugVars(fclDebugVars);
gEnvironment->igcPushDebugVars(igcDebugVars);
}
inline void restoreBuiltInBinaryName(Device *pDevice) {
gEnvironment->igcPopDebugVars();
gEnvironment->fclPopDebugVars();
}
struct RunKernelFixtureFactory {
typedef OCLRT::CommandStreamFixture CommandStreamFixture;
typedef OCLRT::CommandQueueHwFixture CommandQueueFixture;
};
} // namespace OCLRT

View File

@ -0,0 +1,80 @@
/*
* 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.
*/
#pragma once
#include "unit_tests/fixtures/platform_fixture.h"
#include "unit_tests/fixtures/built_in_fixture.h"
#include "unit_tests/mocks/mock_command_queue.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "runtime/helpers/options.h"
#include "gtest/gtest.h"
#include "test.h"
using namespace OCLRT;
class ScenarioTest : public ::testing::Test,
public PlatformFixture,
public BuiltInFixture {
using BuiltInFixture::SetUp;
using PlatformFixture::SetUp;
public:
ScenarioTest() {
}
protected:
void SetUp() override {
PlatformFixture::SetUp(numPlatformDevices, platformDevices);
auto pDevice = pPlatform->getDevice(0);
ASSERT_NE(nullptr, pDevice);
cl_device_id clDevice = pDevice;
context = Context::create<MockContext>(nullptr, DeviceVector(&clDevice, 1), nullptr, nullptr, retVal);
commandQueue = new MockCommandQueue(context, pDevice, 0);
program = new MockProgram(context);
kernelInternals = new MockKernelWithInternals(*pDevice, context);
kernel = kernelInternals->mockKernel;
ASSERT_NE(nullptr, kernel);
BuiltInFixture::SetUp(pDevice);
}
void TearDown() override {
delete kernelInternals;
delete commandQueue;
context->release();
program->release();
BuiltInFixture::TearDown();
PlatformFixture::TearDown();
}
cl_int retVal;
MockCommandQueue *commandQueue = nullptr;
MockContext *context = nullptr;
MockKernelWithInternals *kernelInternals = nullptr;
MockKernel *kernel = nullptr;
MockProgram *program = nullptr;
};

View File

@ -0,0 +1,40 @@
/*
* 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.
*/
#pragma once
#include "runtime/command_stream/command_stream_receiver.h"
#include "unit_tests/command_stream/command_stream_fixture.h"
#include "unit_tests/command_queue/command_queue_fixture.h"
#include "unit_tests/indirect_heap/indirect_heap_fixture.h"
#include "unit_tests/fixtures/simple_arg_kernel_fixture.h"
#include "unit_tests/fixtures/memory_management_fixture.h"
namespace OCLRT {
struct SimpleArgFixtureFactory {
typedef OCLRT::IndirectHeapFixture IndirectHeapFixture;
typedef OCLRT::CommandStreamFixture CommandStreamFixture;
typedef OCLRT::CommandQueueHwFixture CommandQueueFixture;
typedef OCLRT::SimpleArgKernelFixture KernelFixture;
};
}

View File

@ -0,0 +1,148 @@
/*
* 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.
*/
#pragma once
#include "config.h"
#include "gtest/gtest.h"
#include "CL/cl.h"
#include "runtime/device/device.h"
#include "runtime/helpers/file_io.h"
#include "runtime/kernel/kernel.h"
#include "runtime/program/program.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_program.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/fixtures/program_fixture.h"
namespace OCLRT {
class Kernel;
class Program;
template <typename T>
inline const char *type_name(T &) {
return "unknown";
}
template <>
inline const char *type_name(char &) {
return "char";
}
template <>
inline const char *type_name(int &) {
return "int";
}
template <>
inline const char *type_name(float &) {
return "float";
}
template <>
inline const char *type_name(short &) {
return "short";
}
template <>
inline const char *type_name(unsigned char &) {
return "unsigned char";
}
template <>
inline const char *type_name(unsigned int &) {
return "unsigned int";
}
template <>
inline const char *type_name(unsigned short &) {
return "unsigned short";
}
class SimpleArgKernelFixture : public ProgramFixture {
public:
using ProgramFixture::SetUp;
SimpleArgKernelFixture()
: retVal(CL_SUCCESS), pKernel(nullptr) {
}
protected:
virtual void SetUp(Device *pDevice) {
ProgramFixture::SetUp();
std::string testFile;
int forTheName = 0;
testFile.append("simple_arg_");
testFile.append(type_name(forTheName));
auto pos = testFile.find(" ");
if (pos != (size_t)-1) {
testFile.replace(pos, 1, "_");
}
cl_device_id device = pDevice;
pContext = Context::create<MockContext>(nullptr, DeviceVector(&device, 1), nullptr, nullptr, retVal);
ASSERT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, pContext);
CreateProgramFromBinary<Program>(
pContext,
&device,
testFile);
ASSERT_NE(nullptr, pProgram);
retVal = pProgram->build(
1,
&device,
nullptr,
nullptr,
nullptr,
false);
ASSERT_EQ(CL_SUCCESS, retVal);
// create a kernel
pKernel = Kernel::create<MockKernel>(
pProgram,
*pProgram->getKernelInfo("SimpleArg"),
&retVal);
ASSERT_NE(nullptr, pKernel);
ASSERT_EQ(CL_SUCCESS, retVal);
}
virtual void TearDown() {
delete pKernel;
pKernel = nullptr;
pContext->release();
ProgramFixture::TearDown();
}
cl_int retVal;
Kernel *pKernel;
MockContext *pContext;
};
} // namespace OCLRT

View File

@ -0,0 +1,82 @@
/*
* 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.
*/
#pragma once
#include "hello_world_fixture.h"
#include "unit_tests/command_queue/enqueue_fixture.h"
#include "unit_tests/helpers/hw_parse.h"
namespace OCLRT {
// Generates two back-to-back walkers using the same kernel for testing purposes
template <typename FactoryType>
struct TwoWalkerTest
: public HelloWorldTest<FactoryType>,
public HardwareParse {
typedef HelloWorldTest<FactoryType> Parent;
using Parent::pCmdQ;
using Parent::pCS;
using Parent::pKernel;
using Parent::pCmdBuffer;
template <typename FamilyType>
void enqueueTwoKernels() {
auto retVal = EnqueueKernelHelper<>::enqueueKernel(
pCmdQ,
pKernel);
ASSERT_EQ(CL_SUCCESS, retVal);
// We have to parse after each enqueue* because
// the CSR CS may insert commands in between
parseCommands<FamilyType>(*pCmdQ);
retVal = EnqueueKernelHelper<>::enqueueKernel(
pCmdQ,
pKernel);
ASSERT_EQ(CL_SUCCESS, retVal);
parseCommands<FamilyType>(*pCmdQ);
itorWalker1 = find<typename FamilyType::GPGPU_WALKER *>(cmdList.begin(), cmdList.end());
ASSERT_NE(cmdList.end(), itorWalker1);
itorWalker2 = itorWalker1;
++itorWalker2;
itorWalker2 = find<typename FamilyType::GPGPU_WALKER *>(itorWalker2, cmdList.end());
ASSERT_NE(cmdList.end(), itorWalker2);
}
void SetUp() override {
Parent::SetUp();
HardwareParse::SetUp();
}
void TearDown() override {
HardwareParse::TearDown();
Parent::TearDown();
}
GenCmdList::iterator itorWalker1;
GenCmdList::iterator itorWalker2;
};
}