spla
cl_map.hpp
Go to the documentation of this file.
1 /**********************************************************************************/
2 /* This file is part of spla project */
3 /* https://github.com/JetBrains-Research/spla */
4 /**********************************************************************************/
5 /* MIT License */
6 /* */
7 /* Copyright (c) 2023 SparseLinearAlgebra */
8 /* */
9 /* Permission is hereby granted, free of charge, to any person obtaining a copy */
10 /* of this software and associated documentation files (the "Software"), to deal */
11 /* in the Software without restriction, including without limitation the rights */
12 /* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
13 /* copies of the Software, and to permit persons to whom the Software is */
14 /* furnished to do so, subject to the following conditions: */
15 /* */
16 /* The above copyright notice and this permission notice shall be included in all */
17 /* copies or substantial portions of the Software. */
18 /* */
19 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
20 /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
21 /* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
22 /* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
23 /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
24 /* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
25 /* SOFTWARE. */
26 /**********************************************************************************/
27 
28 #ifndef SPLA_CL_MAP_HPP
29 #define SPLA_CL_MAP_HPP
30 
33 #include <spla/op.hpp>
34 
35 namespace spla {
36 
37  template<typename T>
38  void cl_map(cl::CommandQueue& queue, const cl::Buffer& source, cl::Buffer& dest, uint n, const ref_ptr<TOpUnary<T, T>>& op) {
39  if (n == 0) return;
40 
41  auto* acc = get_acc_cl();
42 
43  CLProgramBuilder builder;
44  builder
45  .set_name("map")
46  .set_source(source_map)
47  .add_type("TYPE", get_ttype<T>().template as<Type>())
48  .add_op("OP_UNARY", op.template as<OpUnary>())
49  .acquire();
50 
51  auto kernel = builder.make_kernel("map");
52  kernel.setArg(0, dest);
53  kernel.setArg(1, source);
54  kernel.setArg(2, n);
55 
56  cl::NDRange global(align(n, acc->get_default_wgs()));
57  cl::NDRange local(acc->get_default_wgs());
58  queue.enqueueNDRangeKernel(kernel, cl::NullRange, global, local);
59  }
60 
61 }// namespace spla
62 
63 #endif//SPLA_CL_MAP_HPP
Runtime opencl program builder.
Definition: cl_program_builder.hpp:55
CLProgramBuilder & add_op(const char *name, const ref_ptr< OpUnary > &op)
Definition: cl_program_builder.cpp:49
CLProgramBuilder & set_name(const char *name)
Definition: cl_program_builder.cpp:37
CLProgramBuilder & add_type(const char *alias, const ref_ptr< Type > &type)
Definition: cl_program_builder.cpp:45
cl::Kernel make_kernel(const char *name)
Definition: cl_program_builder.hpp:67
CLProgramBuilder & set_source(const char *source)
Definition: cl_program_builder.cpp:61
void acquire()
Definition: cl_program_builder.cpp:65
Definition: top.hpp:125
Automates reference counting and behaves as shared smart pointer.
Definition: ref.hpp:117
std::uint32_t uint
Library index and size type.
Definition: config.hpp:56
Definition: algorithm.hpp:37
void cl_map(cl::CommandQueue &queue, const cl::Buffer &source, cl::Buffer &dest, uint n, const ref_ptr< TOpUnary< T, T >> &op)
Definition: cl_map.hpp:38