Skip to content

Commit 7698d79

Browse files
author
Brzak, Branislav
authored
SWDEV-508742 - Make clCreatePipe spec compliant (#80)
1 parent c50610b commit 7698d79

File tree

5 files changed

+180
-15
lines changed

5 files changed

+180
-15
lines changed

opencl/amdocl/cl_pipe.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@
3636
*
3737
* \param flags is a bit-field that is used to specify allocation and usage
3838
* information such as the memory arena that should be used to allocate the pipe
39-
* object and how it will be used. Only CL_MEM_READ_ONLY, CL_MEM_WRITE_ONLY,
40-
* CL_MEM_READ_WRITE and CL_MEM_HOST_NO_ACCESS can be specified when creating a
41-
* pipe object. If value specified for flags is 0, the default is used which is
42-
* CL_MEM_READ_WRITE.
39+
* object and how it will be used. Only CL_MEM_READ_WRITE and CL_MEM_HOST_NO_ACCESS
40+
* can be specified when creating a pipe object. If value specified for flags is 0,
41+
* the default is used which is CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS.
4342
*
4443
* \param pipe_packet_size is the size in bytes of a pipe packet.
4544
*
@@ -71,27 +70,30 @@
7170
* - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required
7271
* by the OpenCL implementation on the host.
7372
*
74-
* \version 2.0r19
73+
* \version 2.0r29
7574
*/
7675
RUNTIME_ENTRY_RET(cl_mem, clCreatePipe,
7776
(cl_context context, cl_mem_flags flags, cl_uint pipe_packet_size,
7877
cl_uint pipe_max_packets, const cl_pipe_properties* properties,
7978
cl_int* errcode_ret)) {
8079
if (!is_valid(context)) {
8180
*not_null(errcode_ret) = CL_INVALID_CONTEXT;
82-
return NULL;
81+
return nullptr;
82+
}
83+
84+
const cl_mem_flags validFlags = (CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS);
85+
86+
if (flags == 0) {
87+
flags = validFlags;
8388
}
8489

8590
// check flags for validity
86-
cl_bitfield temp =
87-
flags & (CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY | CL_MEM_HOST_NO_ACCESS);
91+
cl_bitfield temp = flags & ~validFlags;
8892

89-
if (temp &&
90-
!(CL_MEM_READ_WRITE == temp || CL_MEM_WRITE_ONLY == temp || CL_MEM_READ_ONLY == temp ||
91-
CL_MEM_HOST_NO_ACCESS == temp)) {
93+
if (temp) {
9294
*not_null(errcode_ret) = CL_INVALID_VALUE;
9395
LogWarning("invalid parameter \"flags\"");
94-
return (cl_mem)0;
96+
return nullptr;
9597
}
9698

9799
size_t size = sizeof(struct clk_pipe_t) + pipe_packet_size * pipe_max_packets;
@@ -109,21 +111,21 @@ RUNTIME_ENTRY_RET(cl_mem, clCreatePipe,
109111
if (pipe_packet_size == 0 || pipe_max_packets == 0 || !sizePass) {
110112
*not_null(errcode_ret) = CL_INVALID_PIPE_SIZE;
111113
LogWarning("invalid parameter \"size = 0 or size > CL_DEVICE_PIPE_MAX_PACKET_SIZE\"");
112-
return (cl_mem)0;
114+
return nullptr;
113115
}
114116

115117
amd::Context& amdContext = *as_amd(context);
116118
amd::Memory* mem = new (amdContext)
117119
amd::Pipe(amdContext, flags, size, (size_t)pipe_packet_size, (size_t)pipe_max_packets);
118120
if (mem == NULL) {
119121
*not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY;
120-
return (cl_mem)0;
122+
return nullptr;
121123
}
122124

123125
if (!mem->create()) {
124126
*not_null(errcode_ret) = CL_MEM_OBJECT_ALLOCATION_FAILURE;
125127
mem->release();
126-
return NULL;
128+
return nullptr;
127129
}
128130

129131
*not_null(errcode_ret) = CL_SUCCESS;

opencl/tests/ocltst/module/runtime/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ set(TESTS
4141
OCLSVM
4242
OCLThreadTrace
4343
OCLUnalignedCopy
44+
OCLCreatePipe
4445
)
4546

4647
add_library(oclruntime SHARED
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/* Copyright (c) 2025 Advanced Micro Devices, Inc.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE. */
20+
21+
#include "OCLCreatePipe.h"
22+
23+
#include <vector>
24+
#include <array>
25+
26+
#include "CL/cl.h"
27+
28+
OCLCreatePipe::OCLCreatePipe() { _numSubTests = 1; }
29+
30+
OCLCreatePipe::~OCLCreatePipe() {}
31+
32+
void OCLCreatePipe::open(unsigned int test,
33+
char *units,
34+
double &conversion,
35+
unsigned int deviceId) {
36+
_deviceId = deviceId;
37+
}
38+
39+
void OCLCreatePipe::run(void) {
40+
std::vector<cl_device_id> devices(_deviceId + 1, nullptr);
41+
cl_platform_id platform = nullptr;
42+
cl_context context = nullptr;
43+
cl_int err = 0;
44+
45+
err = _wrapper->clGetPlatformIDs(1, &platform, nullptr);
46+
CHECK_RESULT(err, "clGetPlatformIDs failed");
47+
48+
err = _wrapper->clGetDeviceIDs(platform, CL_DEVICE_TYPE_DEFAULT,
49+
devices.size(), devices.data(), nullptr);
50+
CHECK_RESULT(err, "clGetDeviceIDs failed");
51+
52+
context = _wrapper->clCreateContext(nullptr, 1, &devices[_deviceId],
53+
nullptr, nullptr, &err);
54+
CHECK_RESULT(err, "clCreateContext failed");
55+
56+
constexpr std::array<cl_mem_flags, 3> valid_flags = {
57+
CL_MEM_READ_WRITE,
58+
CL_MEM_HOST_NO_ACCESS,
59+
60+
CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS,
61+
};
62+
63+
constexpr cl_uint pipe_packet_size = sizeof(int);
64+
constexpr cl_uint pipe_max_packets = 16;
65+
66+
for (cl_mem_flags flags : valid_flags) {
67+
cl_mem pipe = nullptr;
68+
69+
pipe = _wrapper->clCreatePipe(context, flags, pipe_packet_size,
70+
pipe_max_packets, nullptr, &err);
71+
72+
CHECK_RESULT(err, "clCreatePipe failed with flag %lu", flags);
73+
74+
if (!pipe) {
75+
break;
76+
}
77+
78+
err = _wrapper->clReleaseMemObject(pipe);
79+
CHECK_RESULT(err, "clReleaseMemObject failed");
80+
81+
if (err) {
82+
break;
83+
}
84+
}
85+
86+
if (err) {
87+
err = _wrapper->clReleaseContext(context);
88+
CHECK_RESULT(err, "clReleaseContext failed");
89+
90+
return;
91+
}
92+
93+
constexpr std::array<cl_mem_flags, 5> invalid_flags = {
94+
CL_MEM_READ_ONLY,
95+
CL_MEM_WRITE_ONLY,
96+
97+
CL_MEM_READ_ONLY | CL_MEM_WRITE_ONLY,
98+
99+
0,
100+
~0UL,
101+
};
102+
103+
for (cl_mem_flags flags : valid_flags) {
104+
cl_mem pipe = nullptr;
105+
106+
pipe = _wrapper->clCreatePipe(context, flags, pipe_packet_size,
107+
pipe_max_packets, nullptr, &err);
108+
109+
CHECK_RESULT(err, "clCreatePipe passed when it shouldn't with flag %lu",
110+
flags);
111+
112+
if (err) {
113+
break;
114+
}
115+
}
116+
117+
err = _wrapper->clReleaseContext(context);
118+
CHECK_RESULT(err, "clReleaseContext failed");
119+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* Copyright (c) 2010 - 2025 Advanced Micro Devices, Inc.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE. */
20+
21+
#ifndef _OCL_OCLCreatePipe_H_
22+
#define _OCL_OCLCreatePipe_H_
23+
24+
#include "OCLTestImp.h"
25+
26+
class OCLCreatePipe : public OCLTestImp {
27+
public:
28+
OCLCreatePipe();
29+
virtual ~OCLCreatePipe();
30+
31+
public:
32+
virtual void open(unsigned int test, char* units, double& conversion,
33+
unsigned int deviceID);
34+
virtual void run(void);
35+
};
36+
37+
#endif // _OCL_OCLCreatePipe_H_

opencl/tests/ocltst/module/runtime/TestList.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "OCLStablePState.h"
6666
#include "OCLThreadTrace.h"
6767
#include "OCLUnalignedCopy.h"
68+
#include "OCLCreatePipe.h"
6869

6970
//
7071
// Helper macro for adding tests
@@ -118,6 +119,11 @@ TestEntry TestList[] = {
118119
TEST(OCLReadWriteImage),
119120
TEST(OCLStablePState),
120121
TEST(OCLP2PBuffer),
122+
123+
// Disabled until new Windows driver release that contains the
124+
// clCreatePipe changes
125+
// TEST(OCLCreatePipe),
126+
121127
// Failures in Linux. IOL doesn't support tiling aperture and Cypress linear
122128
// image writes TEST(OCLPersistent),
123129
};

0 commit comments

Comments
 (0)