File: cl_function_pointers_tests.inl

package info (click to toggle)
intel-compute-runtime 20.44.18297-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 34,780 kB
  • sloc: cpp: 379,729; lisp: 4,931; python: 299; sh: 196; makefile: 8
file content (121 lines) | stat: -rw-r--r-- 5,122 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * Copyright (C) 2017-2020 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "opencl/test/unit_test/mocks/mock_program.h"

#include "cl_api_tests.h"

using namespace NEO;

using clGetDeviceGlobalVariablePointer = api_tests;
using clGetDeviceFunctionPointer = api_tests;

TEST_F(clGetDeviceGlobalVariablePointer, GivenNullMandatoryArgumentsThenReturnInvalidArgError) {
    auto &symbols = pProgram->buildInfos[testedRootDeviceIndex].symbols;
    symbols["A"].gpuAddress = 7U;
    symbols["A"].symbol.size = 64U;
    symbols["A"].symbol.segment = NEO::SegmentType::GlobalVariables;

    void *globalRet = 0;
    auto ret = clGetDeviceGlobalVariablePointerINTEL(this->pContext->getDevice(0), this->pProgram, "A", nullptr, &globalRet);
    EXPECT_EQ(CL_SUCCESS, ret);
    EXPECT_EQ(7U, reinterpret_cast<uintptr_t>(globalRet));

    ret = clGetDeviceGlobalVariablePointerINTEL(this->pContext->getDevice(0), this->pProgram, "A", nullptr, nullptr);
    EXPECT_EQ(CL_INVALID_ARG_VALUE, ret);

    ret = clGetDeviceGlobalVariablePointerINTEL(this->pContext->getDevice(0), nullptr, "A", nullptr, &globalRet);
    EXPECT_EQ(CL_INVALID_PROGRAM, ret);

    ret = clGetDeviceGlobalVariablePointerINTEL(nullptr, this->pProgram, "A", nullptr, &globalRet);
    EXPECT_EQ(CL_INVALID_DEVICE, ret);
}

TEST_F(clGetDeviceGlobalVariablePointer, GivenValidSymbolNameThenReturnProperAddressAndSize) {
    auto &symbols = pProgram->buildInfos[testedRootDeviceIndex].symbols;
    symbols["A"].gpuAddress = 7U;
    symbols["A"].symbol.size = 64U;
    symbols["A"].symbol.segment = NEO::SegmentType::GlobalVariables;

    void *globalRet = 0;
    size_t sizeRet = 0;
    auto ret = clGetDeviceGlobalVariablePointerINTEL(this->pContext->getDevice(0), this->pProgram, "A", &sizeRet, &globalRet);
    EXPECT_EQ(CL_SUCCESS, ret);
    EXPECT_EQ(7U, reinterpret_cast<uintptr_t>(globalRet));
    EXPECT_EQ(64U, sizeRet);
}

TEST_F(clGetDeviceGlobalVariablePointer, GivenFunctionSymbolNameThenReturnInvalidArgError) {
    auto &symbols = pProgram->buildInfos[testedRootDeviceIndex].symbols;
    symbols["A"].gpuAddress = 7U;
    symbols["A"].symbol.size = 64U;
    symbols["A"].symbol.segment = NEO::SegmentType::Instructions;

    void *globalRet = 0;
    auto ret = clGetDeviceGlobalVariablePointerINTEL(this->pContext->getDevice(0), this->pProgram, "A", nullptr, &globalRet);
    EXPECT_EQ(CL_INVALID_ARG_VALUE, ret);
}

TEST_F(clGetDeviceGlobalVariablePointer, GivenUnknownSymbolNameThenReturnInvalidArgError) {
    void *globalRet = 0;
    auto ret = clGetDeviceGlobalVariablePointerINTEL(this->pContext->getDevice(0), this->pProgram, "A", nullptr, &globalRet);
    EXPECT_EQ(CL_INVALID_ARG_VALUE, ret);
}

TEST_F(clGetDeviceFunctionPointer, GivenNullMandatoryArgumentsThenReturnInvalidArgError) {
    auto &symbols = pProgram->buildInfos[testedRootDeviceIndex].symbols;
    symbols["A"].gpuAddress = 7U;
    symbols["A"].symbol.size = 64U;
    symbols["A"].symbol.segment = NEO::SegmentType::Instructions;

    cl_ulong fptrRet = 0;
    auto ret = clGetDeviceFunctionPointerINTEL(this->pContext->getDevice(0), this->pProgram, "A", &fptrRet);
    EXPECT_EQ(CL_SUCCESS, ret);
    EXPECT_EQ(7U, fptrRet);

    ret = clGetDeviceFunctionPointerINTEL(this->pContext->getDevice(0), this->pProgram, "A", nullptr);
    EXPECT_EQ(CL_INVALID_ARG_VALUE, ret);

    ret = clGetDeviceFunctionPointerINTEL(this->pContext->getDevice(0), nullptr, "A", &fptrRet);
    EXPECT_EQ(CL_INVALID_PROGRAM, ret);

    ret = clGetDeviceFunctionPointerINTEL(nullptr, this->pProgram, "A", &fptrRet);
    EXPECT_EQ(CL_INVALID_DEVICE, ret);
}

TEST_F(clGetDeviceFunctionPointer, GivenValidSymbolNameThenReturnProperAddress) {
    auto &symbols = pProgram->buildInfos[testedRootDeviceIndex].symbols;
    symbols["A"].gpuAddress = 7U;
    symbols["A"].symbol.size = 64U;
    symbols["A"].symbol.segment = NEO::SegmentType::Instructions;

    cl_ulong fptrRet = 0;
    auto ret = clGetDeviceFunctionPointerINTEL(this->pContext->getDevice(0), this->pProgram, "A", &fptrRet);
    EXPECT_EQ(CL_SUCCESS, ret);
    EXPECT_EQ(7U, fptrRet);
}

TEST_F(clGetDeviceFunctionPointer, GivenGlobalSymbolNameThenReturnInvalidArgError) {
    auto &symbols = pProgram->buildInfos[testedRootDeviceIndex].symbols;
    symbols["A"].gpuAddress = 7U;
    symbols["A"].symbol.size = 64U;
    symbols["A"].symbol.segment = NEO::SegmentType::GlobalVariables;
    symbols["B"].gpuAddress = 7U;
    symbols["B"].symbol.size = 64U;
    symbols["B"].symbol.segment = NEO::SegmentType::GlobalConstants;

    cl_ulong fptrRet = 0;
    auto ret = clGetDeviceFunctionPointerINTEL(this->pContext->getDevice(0), this->pProgram, "A", &fptrRet);
    EXPECT_EQ(CL_INVALID_ARG_VALUE, ret);
    ret = clGetDeviceFunctionPointerINTEL(this->pContext->getDevice(0), this->pProgram, "B", &fptrRet);
    EXPECT_EQ(CL_INVALID_ARG_VALUE, ret);
}
TEST_F(clGetDeviceFunctionPointer, GivenUnknownSymbolNameThenReturnInvalidArgError) {
    cl_ulong fptrRet = 0;
    auto ret = clGetDeviceFunctionPointerINTEL(this->pContext->getDevice(0), this->pProgram, "A", &fptrRet);
    EXPECT_EQ(CL_INVALID_ARG_VALUE, ret);
}