2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-01-14 21:32:11 +08:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-02-07 01:57:00 +08:00
|
|
|
#include "core/device/device.h"
|
2020-01-28 00:28:10 +08:00
|
|
|
#include "core/helpers/array_count.h"
|
2019-10-17 04:21:04 +08:00
|
|
|
#include "core/helpers/file_io.h"
|
2019-09-09 18:35:44 +08:00
|
|
|
#include "core/unit_tests/helpers/debug_manager_state_restore.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "unit_tests/fixtures/device_fixture.h"
|
|
|
|
#include "unit_tests/fixtures/program_fixture.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "unit_tests/mocks/mock_context.h"
|
|
|
|
#include "unit_tests/mocks/mock_kernel.h"
|
|
|
|
#include "unit_tests/mocks/mock_program.h"
|
|
|
|
|
|
|
|
#include "CL/cl.h"
|
2019-12-01 23:13:21 +08:00
|
|
|
#include "compiler_options.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "gtest/gtest.h"
|
2020-02-22 16:28:27 +08:00
|
|
|
#include "kernel/kernel.h"
|
|
|
|
#include "program/program.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2019-02-22 18:51:48 +08:00
|
|
|
#include <type_traits>
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
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:
|
2020-01-14 21:32:11 +08:00
|
|
|
virtual void SetUp(ClDevice *pDevice) {
|
2017-12-21 07:45:38 +08:00
|
|
|
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;
|
2020-01-14 21:32:11 +08:00
|
|
|
pContext = Context::create<MockContext>(nullptr, ClDeviceVector(&device, 1), nullptr, nullptr, retVal);
|
2017-12-21 07:45:38 +08:00
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
ASSERT_NE(nullptr, pContext);
|
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
CreateProgramFromBinary(
|
2017-12-21 07:45:38 +08:00
|
|
|
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() {
|
2018-10-17 06:37:07 +08:00
|
|
|
if (pKernel) {
|
|
|
|
delete pKernel;
|
|
|
|
pKernel = nullptr;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
pContext->release();
|
|
|
|
|
|
|
|
ProgramFixture::TearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
cl_int retVal;
|
|
|
|
Kernel *pKernel;
|
|
|
|
MockContext *pContext;
|
|
|
|
};
|
2018-10-17 06:37:07 +08:00
|
|
|
|
|
|
|
class SimpleArgNonUniformKernelFixture : public ProgramFixture {
|
|
|
|
public:
|
|
|
|
using ProgramFixture::SetUp;
|
|
|
|
SimpleArgNonUniformKernelFixture()
|
|
|
|
: retVal(CL_SUCCESS), kernel(nullptr) {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2020-01-14 21:32:11 +08:00
|
|
|
void SetUp(ClDevice *device, Context *context) {
|
2018-10-17 06:37:07 +08:00
|
|
|
ProgramFixture::SetUp();
|
|
|
|
|
|
|
|
cl_device_id deviceId = device;
|
|
|
|
cl_context clContext = context;
|
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
CreateProgramFromBinary(
|
2018-10-17 06:37:07 +08:00
|
|
|
clContext,
|
|
|
|
&deviceId,
|
|
|
|
"simple_nonuniform",
|
|
|
|
"-cl-std=CL2.0");
|
|
|
|
ASSERT_NE(nullptr, pProgram);
|
|
|
|
|
|
|
|
retVal = pProgram->build(
|
|
|
|
1,
|
|
|
|
&deviceId,
|
|
|
|
"-cl-std=CL2.0",
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
false);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
kernel = Kernel::create<MockKernel>(
|
|
|
|
pProgram,
|
|
|
|
*pProgram->getKernelInfo("simpleNonUniform"),
|
|
|
|
&retVal);
|
|
|
|
ASSERT_NE(nullptr, kernel);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void TearDown() {
|
|
|
|
if (kernel) {
|
|
|
|
delete kernel;
|
|
|
|
kernel = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgramFixture::TearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
cl_int retVal;
|
|
|
|
Kernel *kernel;
|
|
|
|
};
|
|
|
|
|
2018-10-24 06:49:00 +08:00
|
|
|
class SimpleKernelFixture : public ProgramFixture {
|
|
|
|
public:
|
|
|
|
using ProgramFixture::SetUp;
|
|
|
|
|
|
|
|
protected:
|
2020-01-14 21:32:11 +08:00
|
|
|
void SetUp(ClDevice *device, Context *context) {
|
2018-10-24 06:49:00 +08:00
|
|
|
ProgramFixture::SetUp();
|
|
|
|
|
|
|
|
cl_device_id deviceId = device;
|
|
|
|
cl_context clContext = context;
|
|
|
|
std::string programName("simple_kernels");
|
2019-08-29 21:10:51 +08:00
|
|
|
CreateProgramFromBinary(
|
2018-10-24 06:49:00 +08:00
|
|
|
clContext,
|
|
|
|
&deviceId,
|
|
|
|
programName);
|
|
|
|
ASSERT_NE(nullptr, pProgram);
|
|
|
|
|
|
|
|
retVal = pProgram->build(
|
|
|
|
1,
|
|
|
|
&deviceId,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
false);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
2019-02-22 18:51:48 +08:00
|
|
|
for (size_t i = 0; i < maxKernelsCount; i++) {
|
2018-10-24 06:49:00 +08:00
|
|
|
if ((1 << i) & kernelIds) {
|
|
|
|
std::string kernelName("simple_kernel_");
|
|
|
|
kernelName.append(std::to_string(i));
|
2018-10-27 06:02:28 +08:00
|
|
|
kernels[i].reset(Kernel::create<MockKernel>(
|
2018-10-24 06:49:00 +08:00
|
|
|
pProgram,
|
|
|
|
*pProgram->getKernelInfo(kernelName.c_str()),
|
2018-10-27 06:02:28 +08:00
|
|
|
&retVal));
|
2018-10-24 06:49:00 +08:00
|
|
|
ASSERT_NE(nullptr, kernels[i]);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void TearDown() {
|
2019-02-22 18:51:48 +08:00
|
|
|
for (size_t i = 0; i < maxKernelsCount; i++) {
|
2018-10-24 06:49:00 +08:00
|
|
|
if (kernels[i]) {
|
2018-10-27 06:02:28 +08:00
|
|
|
kernels[i].reset(nullptr);
|
2018-10-24 06:49:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgramFixture::TearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t kernelIds = 0;
|
2019-02-22 18:51:48 +08:00
|
|
|
static constexpr size_t maxKernelsCount = std::numeric_limits<decltype(kernelIds)>::digits;
|
|
|
|
cl_int retVal = CL_SUCCESS;
|
|
|
|
std::array<std::unique_ptr<Kernel>, maxKernelsCount> kernels;
|
2018-10-24 06:49:00 +08:00
|
|
|
};
|
|
|
|
|
2019-09-09 18:35:44 +08:00
|
|
|
class SimpleKernelStatelessFixture : public ProgramFixture {
|
|
|
|
public:
|
|
|
|
DebugManagerStateRestore restorer;
|
|
|
|
using ProgramFixture::SetUp;
|
|
|
|
SimpleKernelStatelessFixture() = default;
|
|
|
|
|
|
|
|
protected:
|
2020-01-14 21:32:11 +08:00
|
|
|
void SetUp(ClDevice *device, Context *context) {
|
2019-09-09 18:35:44 +08:00
|
|
|
ProgramFixture::SetUp();
|
|
|
|
cl_device_id deviceId = device;
|
|
|
|
cl_context clContext = context;
|
|
|
|
DebugManager.flags.DisableStatelessToStatefulOptimization.set(true);
|
|
|
|
DebugManager.flags.EnableStatelessToStatefulBufferOffsetOpt.set(false);
|
|
|
|
|
2019-08-29 21:10:51 +08:00
|
|
|
CreateProgramFromBinary(
|
2019-09-09 18:35:44 +08:00
|
|
|
clContext,
|
|
|
|
&deviceId,
|
|
|
|
"stateless_kernel");
|
|
|
|
ASSERT_NE(nullptr, pProgram);
|
|
|
|
|
|
|
|
retVal = pProgram->build(
|
|
|
|
1,
|
|
|
|
&deviceId,
|
2019-12-01 23:13:21 +08:00
|
|
|
CompilerOptions::greaterThan4gbBuffersRequired,
|
2019-09-09 18:35:44 +08:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
false);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
kernel.reset(Kernel::create<MockKernel>(
|
|
|
|
pProgram,
|
|
|
|
*pProgram->getKernelInfo("statelessKernel"),
|
|
|
|
&retVal));
|
|
|
|
ASSERT_NE(nullptr, kernel);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() {
|
|
|
|
ProgramFixture::TearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Kernel> kernel = nullptr;
|
|
|
|
cl_int retVal = CL_SUCCESS;
|
|
|
|
};
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|