28 #ifndef SPLA_CL_FORMAT_DENSE_VEC_HPP
29 #define SPLA_CL_FORMAT_DENSE_VEC_HPP
48 const std::size_t buffer_size = n_rows *
sizeof(T);
49 const auto flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
51 cl::Buffer buffer(get_acc_cl()->get_context(), flags, buffer_size);
52 storage.
Ax = std::move(buffer);
59 cl_fill_value<T>(get_acc_cl()->get_queue_default(), storage.
Ax, n_rows, value);
68 const std::size_t buffer_size = n_rows *
sizeof(T);
69 const auto flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS | CL_MEM_COPY_HOST_PTR;
71 cl::Buffer buffer(get_acc_cl()->get_context(), flags, buffer_size, (
void*) values);
72 storage.
Ax = std::move(buffer);
79 cl::CommandQueue& queue,
80 cl_mem_flags staging_flags = CL_MEM_READ_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_ALLOC_HOST_PTR,
81 bool blocking =
true) {
82 const std::size_t buffer_size = n_rows *
sizeof(T);
83 cl::Buffer staging(get_acc_cl()->get_context(), staging_flags, buffer_size);
85 queue.enqueueCopyBuffer(storage.
Ax, staging, 0, 0, buffer_size);
86 queue.enqueueReadBuffer(staging, blocking, 0, buffer_size, values);
94 cl::CommandQueue& queue) {
98 .
add_type(
"TYPE", get_ttype<T>().
template as<Type>())
102 auto* acc = get_acc_cl();
105 cl::Buffer temp_Ri(acc->get_context(), CL_MEM_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS, n_rows *
sizeof(
uint));
106 cl::Buffer temp_Rx(acc->get_context(), CL_MEM_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS, n_rows *
sizeof(T));
108 cl_count.
set(queue, 0);
110 uint block_size = acc->get_default_wgs();
113 cl::NDRange global(block_size * n_groups_to_dispatch);
114 cl::NDRange local(block_size);
116 auto kernel = builder.
make_kernel(
"dense_to_sparse");
117 kernel.setArg(0, in.
Ax);
118 kernel.setArg(1, temp_Ri);
119 kernel.setArg(2, temp_Rx);
120 kernel.setArg(3, cl_count.
buffer());
121 kernel.setArg(4,
uint(n_rows));
122 kernel.setArg(5, fill_value);
124 queue.enqueueNDRangeKernel(kernel, cl::NDRange(), global, local);
125 uint count = cl_count.
get(queue);
131 out.
Ai = cl::Buffer();
132 out.
Ax = cl::Buffer();
137 out.
Ai = cl::Buffer(acc->get_context(), CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS, count *
sizeof(
uint));
138 out.
Ax = cl::Buffer(acc->get_context(), CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS, count *
sizeof(T));
140 queue.enqueueCopyBuffer(temp_Ri, out.
Ai, 0, 0, count *
sizeof(
uint));
141 queue.enqueueCopyBuffer(temp_Rx, out.
Ax, 0, 0, count *
sizeof(T));
#define CL_FINISH(queue)
Definition: cl_debug.hpp:34
OpenCL list-of-coordinates sparse vector representation.
Definition: cl_formats.hpp:77
cl::Buffer Ax
Definition: cl_formats.hpp:84
cl::Buffer Ai
Definition: cl_formats.hpp:83
Definition: cl_counter.hpp:58
uint get(cl::CommandQueue &queue, cl::Event *event=nullptr)
Definition: cl_counter.cpp:53
cl::Buffer & buffer()
Definition: cl_counter.cpp:59
void set(cl::CommandQueue &queue, uint value, cl::Event *event=nullptr)
Definition: cl_counter.cpp:56
OpenCL one-dim array for dense vector representation.
Definition: cl_formats.hpp:61
cl::Buffer Ax
Definition: cl_formats.hpp:67
Runtime opencl program builder.
Definition: cl_program_builder.hpp:55
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
uint values
Definition: tdecoration.hpp:58
void cl_dense_vec_to_coo(const std::size_t n_rows, const T fill_value, const CLDenseVec< T > &in, CLCooVec< T > &out, cl::CommandQueue &queue)
Definition: cl_format_dense_vec.hpp:90
void cl_dense_vec_read(const std::size_t n_rows, T *values, CLDenseVec< T > &storage, cl::CommandQueue &queue, cl_mem_flags staging_flags=CL_MEM_READ_ONLY|CL_MEM_HOST_READ_ONLY|CL_MEM_ALLOC_HOST_PTR, bool blocking=true)
Definition: cl_format_dense_vec.hpp:76
void cl_dense_vec_init(const std::size_t n_rows, const T *values, CLDenseVec< T > &storage)
Definition: cl_format_dense_vec.hpp:63
void cl_dense_vec_fill_value(const std::size_t n_rows, const T value, CLDenseVec< T > &storage)
Definition: cl_format_dense_vec.hpp:56
void cl_dense_vec_resize(const std::size_t n_rows, CLDenseVec< T > &storage)
Definition: cl_format_dense_vec.hpp:46
std::uint32_t uint
Library index and size type.
Definition: config.hpp:56
#define LOG_MSG(status, msg)
Definition: logger.hpp:66
Definition: algorithm.hpp:37
T min(T a, T b)
Definition: op.cpp:152
T max(T a, T b)
Definition: op.cpp:155