2 # Permission is hereby granted, free of charge, to any person obtaining a
3 # copy of this software and associated documentation files (the "Software"),
4 # to deal in the Software without restriction, including without limitation
5 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
6 # and/or sell copies of the Software, and to permit persons to whom the
7 # Software is furnished to do so, subject to the following conditions:
9 # The above copyright notice and this permission notice (including the next
10 # paragraph) shall be included in all copies or substantial portions of the
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
16 # THE 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 THE
26 from modules
import utils
27 from genclbuiltins
import MAX_VALUES
43 VEC_SIZES
= ['2', '4', '8', '16']
46 DIR_NAME
= os
.path
.join("cl", "builtin", "misc")
49 def gen_array(size
, m
):
50 return [random
.randint(0, m
) for i
in range(size
)]
53 def permute(data1
, data2
, mask
, ssize
, dsize
):
55 for i
, m
in enumerate(mask
):
56 src
= data1
if (m
% (2 * ssize
)) < ssize
else data2
57 ret
.append(src
[(m
% ssize
) + ((i
// dsize
) * ssize
)])
61 def ext_req(type_name
):
62 if type_name
[:6] == "double":
63 return "require_device_extensions: cl_khr_fp64"
64 if type_name
[:4] == "half":
65 return "require_device_extensions: cl_khr_fp16"
69 def print_config(f
, type_name
, utype_name
):
70 f
.write(textwrap
.dedent(("""\
73 name: shuffle2 {type_name} {utype_name}
75 """ + ext_req(type_name
))
76 .format(type_name
=type_name
, utype_name
=utype_name
)))
79 def begin_test(type_name
, utype_name
):
80 fileName
= os
.path
.join(DIR_NAME
, 'builtin-shuffle2-{}-{}.cl'.format(type_name
, utype_name
))
82 f
= open(fileName
, 'w')
83 print_config(f
, type_name
, utype_name
)
89 utils
.safe_makedirs(DIR_NAME
)
91 for t
, ut
in TYPES
.items():
93 for ss
, ds
in itertools
.product(VEC_SIZES
, VEC_SIZES
):
94 ssize
= int(ss
) * ELEMENTS
95 dsize
= int(ds
) * ELEMENTS
99 data1
= gen_array(ssize
, MAX_VALUES
['ushort'])
100 data2
= gen_array(ssize
, MAX_VALUES
['ushort'])
101 mask
= gen_array(dsize
, MAX_VALUES
[ut
])
102 perm
= permute(data1
, data2
, mask
, int(ss
), int(ds
))
103 f
.write(textwrap
.dedent("""
105 name: shuffle2 {stype_name} {utype_name}
106 global_size: {elements} 0 0
107 kernel_name: test_shuffle2_{stype_name}_{utype_name}
108 arg_out: 0 buffer {dtype_name}[{elements}] {perm}
109 arg_in: 1 buffer {stype_name}[{elements}] {data1}
110 arg_in: 2 buffer {stype_name}[{elements}] {data2}
111 arg_in: 3 buffer {utype_name}[{elements}] {mask}
112 """.format(stype_name
=stype_name
, utype_name
=utype_name
,
113 dtype_name
=dtype_name
, elements
=ELEMENTS
,
114 perm
=' '.join([str(x
) for x
in perm
]),
115 data1
=' '.join([str(x
) for x
in data1
]),
116 data2
=' '.join([str(x
) for x
in data2
]),
117 mask
=' '.join([str(x
) for x
in mask
]))))
119 f
.write(textwrap
.dedent("""!*/"""))
122 f
.write(textwrap
.dedent("""
123 #pragma OPENCL EXTENSION cl_khr_fp64: enable
126 f
.write(textwrap
.dedent("""
127 #pragma OPENCL EXTENSION cl_khr_fp16: enable
130 for ss
, ds
in itertools
.product(VEC_SIZES
, VEC_SIZES
):
133 f
.write(textwrap
.dedent("""
134 kernel void test_shuffle2_{type_name}{ssize}_{utype_name}{dsize}(global {type_name}* out, global {type_name}* in1, global {type_name}* in2, global {utype_name}* mask) {{
135 vstore{dsize}(shuffle2(vload{ssize}(get_global_id(0), in1), vload{ssize}(get_global_id(0), in2), vload{dsize}(get_global_id(0), mask)), get_global_id(0), out);
137 """.format(type_name
=t
, utype_name
=ut
, ssize
=ss
, dsize
=ds
)))
142 if __name__
== '__main__':