All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bisect_kernel_calls.hpp
Go to the documentation of this file.
#ifndef VIENNACL_LINALG_OPENCL_BISECT_KERNEL_CALLS_HPP_
#define VIENNACL_LINALG_OPENCL_BISECT_KERNEL_CALLS_HPP_
/* =========================================================================
Copyright (c) 2010-2016, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
-----------------
ViennaCL - The Vienna Computing Library
-----------------
Project Head: Karl Rupp rupp@iue.tuwien.ac.at
(A list of authors and contributors can be found in the manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
// includes, project
#include "viennacl/linalg/opencl/kernels/bisect.hpp"
#include "viennacl/linalg/detail/bisect/structs.hpp"
#include "viennacl/linalg/detail/bisect/config.hpp"
#include "viennacl/linalg/detail/bisect/util.hpp"
namespace viennacl
{
namespace linalg
{
namespace opencl
{
const std::string BISECT_KERNEL_SMALL = "bisectKernelSmall";
const std::string BISECT_KERNEL_LARGE = "bisectKernelLarge";
const std::string BISECT_KERNEL_LARGE_ONE_INTERVALS = "bisectKernelLarge_OneIntervals";
const std::string BISECT_KERNEL_LARGE_MULT_INTERVALS = "bisectKernelLarge_MultIntervals";
template<typename NumericT>
void bisectSmall(const viennacl::linalg::detail::InputData<NumericT> &input,
viennacl::linalg::detail::ResultDataSmall<NumericT> &result,
const unsigned int mat_size,
const NumericT lg, const NumericT ug,
const NumericT precision)
{
viennacl::ocl::context & ctx = const_cast<viennacl::ocl::context &>(viennacl::traits::opencl_handle(input.g_a).context());
viennacl::linalg::opencl::kernels::bisect_kernel<NumericT>::init(ctx);
viennacl::ocl::kernel& kernel = ctx.get_kernel(viennacl::linalg::opencl::kernels::bisect_kernel<NumericT>::program_name(), BISECT_KERNEL_SMALL);
kernel.global_work_size(0, 1 * VIENNACL_BISECT_MAX_THREADS_BLOCK_SMALL_MATRIX);
kernel.local_work_size(0, VIENNACL_BISECT_MAX_THREADS_BLOCK_SMALL_MATRIX);
viennacl::ocl::enqueue(kernel(viennacl::traits::opencl_handle(input.g_a),
viennacl::traits::opencl_handle(input.g_b),
static_cast<cl_uint>(mat_size),
viennacl::traits::opencl_handle(result.vcl_g_left),
viennacl::traits::opencl_handle(result.vcl_g_right),
viennacl::traits::opencl_handle(result.vcl_g_left_count),
viennacl::traits::opencl_handle(result.vcl_g_right_count),
static_cast<NumericT>(lg),
static_cast<NumericT>(ug),
static_cast<cl_uint>(0),
static_cast<cl_uint>(mat_size),
static_cast<NumericT>(precision)
));
}
template<typename NumericT>
void bisectLarge(const viennacl::linalg::detail::InputData<NumericT> &input,
viennacl::linalg::detail::ResultDataLarge<NumericT> &result,
const unsigned int mat_size,
const NumericT lg, const NumericT ug,
const NumericT precision)
{
viennacl::ocl::context & ctx = const_cast<viennacl::ocl::context &>(viennacl::traits::opencl_handle(input.g_a).context());
viennacl::linalg::opencl::kernels::bisect_kernel<NumericT>::init(ctx);
viennacl::ocl::kernel& kernel = ctx.get_kernel(viennacl::linalg::opencl::kernels::bisect_kernel<NumericT>::program_name(), BISECT_KERNEL_LARGE);
kernel.global_work_size(0, mat_size > 512 ? VIENNACL_BISECT_MAX_THREADS_BLOCK : VIENNACL_BISECT_MAX_THREADS_BLOCK / 2); // Use only 128 threads for 256 < n <= 512, this
kernel.local_work_size(0, mat_size > 512 ? VIENNACL_BISECT_MAX_THREADS_BLOCK : VIENNACL_BISECT_MAX_THREADS_BLOCK / 2); // is reasoned
viennacl::ocl::enqueue(kernel(viennacl::traits::opencl_handle(input.g_a),
viennacl::traits::opencl_handle(input.g_b),
static_cast<cl_uint>(mat_size),
static_cast<NumericT>(lg),
static_cast<NumericT>(ug),
static_cast<cl_uint>(0),
static_cast<cl_uint>(mat_size),
static_cast<NumericT>(precision),
viennacl::traits::opencl_handle(result.g_num_one),
viennacl::traits::opencl_handle(result.g_num_blocks_mult),
viennacl::traits::opencl_handle(result.g_left_one),
viennacl::traits::opencl_handle(result.g_right_one),
viennacl::traits::opencl_handle(result.g_pos_one),
viennacl::traits::opencl_handle(result.g_left_mult),
viennacl::traits::opencl_handle(result.g_right_mult),
viennacl::traits::opencl_handle(result.g_left_count_mult),
viennacl::traits::opencl_handle(result.g_right_count_mult),
viennacl::traits::opencl_handle(result.g_blocks_mult),
viennacl::traits::opencl_handle(result.g_blocks_mult_sum)
));
}
template<typename NumericT>
void bisectLargeOneIntervals(const viennacl::linalg::detail::InputData<NumericT> &input,
viennacl::linalg::detail::ResultDataLarge<NumericT> &result,
const unsigned int mat_size,
const NumericT precision)
{
unsigned int num_one_intervals = result.g_num_one;
unsigned int num_blocks = viennacl::linalg::detail::getNumBlocksLinear(num_one_intervals,
mat_size > 512 ? VIENNACL_BISECT_MAX_THREADS_BLOCK: VIENNACL_BISECT_MAX_THREADS_BLOCK / 2);
viennacl::ocl::context & ctx = const_cast<viennacl::ocl::context &>(viennacl::traits::opencl_handle(input.g_a).context());
viennacl::linalg::opencl::kernels::bisect_kernel<NumericT>::init(ctx);
viennacl::ocl::kernel& kernel = ctx.get_kernel(viennacl::linalg::opencl::kernels::bisect_kernel<NumericT>::program_name(), BISECT_KERNEL_LARGE_ONE_INTERVALS);
kernel.global_work_size(0, num_blocks * (mat_size > 512 ? VIENNACL_BISECT_MAX_THREADS_BLOCK : VIENNACL_BISECT_MAX_THREADS_BLOCK / 2));
kernel.local_work_size(0, mat_size > 512 ? VIENNACL_BISECT_MAX_THREADS_BLOCK : VIENNACL_BISECT_MAX_THREADS_BLOCK / 2);
viennacl::ocl::enqueue(kernel(viennacl::traits::opencl_handle(input.g_a),
viennacl::traits::opencl_handle(input.g_b),
static_cast<cl_uint>(mat_size),
static_cast<cl_uint>(num_one_intervals),
viennacl::traits::opencl_handle(result.g_left_one),
viennacl::traits::opencl_handle(result.g_right_one),
viennacl::traits::opencl_handle(result.g_pos_one),
static_cast<NumericT>(precision)
));
}
template<typename NumericT>
void bisectLargeMultIntervals(const viennacl::linalg::detail::InputData<NumericT> &input,
viennacl::linalg::detail::ResultDataLarge<NumericT> &result,
const unsigned int mat_size,
const NumericT precision)
{
unsigned int num_blocks_mult = result.g_num_blocks_mult;
viennacl::ocl::context & ctx = const_cast<viennacl::ocl::context &>(viennacl::traits::opencl_handle(input.g_a).context());
viennacl::linalg::opencl::kernels::bisect_kernel<NumericT>::init(ctx);
viennacl::ocl::kernel& kernel = ctx.get_kernel(viennacl::linalg::opencl::kernels::bisect_kernel<NumericT>::program_name(), BISECT_KERNEL_LARGE_MULT_INTERVALS);
kernel.global_work_size(0, num_blocks_mult * (mat_size > 512 ? VIENNACL_BISECT_MAX_THREADS_BLOCK : VIENNACL_BISECT_MAX_THREADS_BLOCK / 2));
kernel.local_work_size(0, mat_size > 512 ? VIENNACL_BISECT_MAX_THREADS_BLOCK : VIENNACL_BISECT_MAX_THREADS_BLOCK / 2);
viennacl::ocl::enqueue(kernel(viennacl::traits::opencl_handle(input.g_a),
viennacl::traits::opencl_handle(input.g_b),
static_cast<cl_uint>(mat_size),
viennacl::traits::opencl_handle(result.g_blocks_mult),
viennacl::traits::opencl_handle(result.g_blocks_mult_sum),
viennacl::traits::opencl_handle(result.g_left_mult),
viennacl::traits::opencl_handle(result.g_right_mult),
viennacl::traits::opencl_handle(result.g_left_count_mult),
viennacl::traits::opencl_handle(result.g_right_count_mult),
viennacl::traits::opencl_handle(result.g_lambda_mult),
viennacl::traits::opencl_handle(result.g_pos_mult),
static_cast<NumericT>(precision)
));
}
} // namespace opencl
} // namespace linalg
} // namespace viennacl
#endif
viennacl::linalg::opencl::kernels::bisect_kernel::init
static void init(viennacl::ocl::context &ctx)
Definition: bisect.hpp:2573
viennacl::linalg::detail::InputData::g_b
viennacl::vector< NumericT > g_b
device side representation of superdiagonal
Definition: structs.hpp:62
viennacl::linalg::opencl::bisectLargeMultIntervals
void bisectLargeMultIntervals(const viennacl::linalg::detail::InputData< NumericT > &input, viennacl::linalg::detail::ResultDataLarge< NumericT > &result, const unsigned int mat_size, const NumericT precision)
Definition: bisect_kernel_calls.hpp:145
viennacl::linalg::detail::ResultDataLarge::g_left_mult
viennacl::vector< NumericT > g_left_mult
left interval limits of intervals containing multiple eigenvalues after the first iteration step ...
Definition: structs.hpp:146
viennacl::linalg::opencl::bisectSmall
void bisectSmall(const viennacl::linalg::detail::InputData< NumericT > &input, viennacl::linalg::detail::ResultDataSmall< NumericT > &result, const unsigned int mat_size, const NumericT lg, const NumericT ug, const NumericT precision)
Definition: bisect_kernel_calls.hpp:49
VIENNACL_BISECT_MAX_THREADS_BLOCK
#define VIENNACL_BISECT_MAX_THREADS_BLOCK
Definition: config.hpp:32
structs.hpp
Helper structures to simplify variable handling.
viennacl::linalg::detail::ResultDataLarge::g_left_one
viennacl::vector< NumericT > g_left_one
left interval limits of intervals containing one eigenvalue after the first iteration step ...
Definition: structs.hpp:137
viennacl::ocl::kernel
Represents an OpenCL kernel within ViennaCL.
Definition: kernel.hpp:58
viennacl::ocl::kernel::local_work_size
size_type local_work_size(int index=0) const
Returns the local work size at the respective dimension.
Definition: kernel.hpp:742
viennacl::linalg::detail::ResultDataLarge::g_num_blocks_mult
viennacl::scalar< unsigned int > g_num_blocks_mult
number of (thread) blocks of intervals containing multiple eigenvalues after the first steo ...
Definition: structs.hpp:134
viennacl::ocl::context
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
Definition: context.hpp:55
util.hpp
Utility functions.
viennacl::linalg::detail::ResultDataLarge::g_blocks_mult
viennacl::vector< unsigned int > g_blocks_mult
start addresses in g_left_mult etc. of blocks of intervals containing more than one eigenvalue after ...
Definition: structs.hpp:156
viennacl::linalg::detail::ResultDataLarge::g_left_count_mult
viennacl::vector< unsigned int > g_left_count_mult
number of eigenvalues less than the left limit of the eigenvalue intervals containing multiple eigenv...
Definition: structs.hpp:151
config.hpp
Global configuration parameters.
viennacl::linalg::opencl::BISECT_KERNEL_SMALL
const std::string BISECT_KERNEL_SMALL
Definition: bisect_kernel_calls.hpp:43
NumericT
float NumericT
Definition: bisect.cpp:40
viennacl::linalg::opencl::BISECT_KERNEL_LARGE_ONE_INTERVALS
const std::string BISECT_KERNEL_LARGE_ONE_INTERVALS
Definition: bisect_kernel_calls.hpp:45
viennacl::linalg::detail::ResultDataLarge::g_right_count_mult
viennacl::vector< unsigned int > g_right_count_mult
number of eigenvalues less than the right limit of the eigenvalue intervals containing multiple eigen...
Definition: structs.hpp:154
viennacl::linalg::opencl::BISECT_KERNEL_LARGE
const std::string BISECT_KERNEL_LARGE
Definition: bisect_kernel_calls.hpp:44
viennacl::linalg::detail::InputData
In this class the input matrix is stored.
Definition: structs.hpp:53
viennacl::linalg::opencl::bisectLargeOneIntervals
void bisectLargeOneIntervals(const viennacl::linalg::detail::InputData< NumericT > &input, viennacl::linalg::detail::ResultDataLarge< NumericT > &result, const unsigned int mat_size, const NumericT precision)
Definition: bisect_kernel_calls.hpp:116
viennacl::ocl::context::get_kernel
viennacl::ocl::kernel & get_kernel(std::string const &program_name, std::string const &kernel_name)
Convenience function for retrieving the kernel of a program directly from the context.
Definition: context.hpp:605
viennacl::linalg::detail::getNumBlocksLinear
unsigned int getNumBlocksLinear(const unsigned int num_threads, const unsigned int num_threads_block)
Definition: util.hpp:96
viennacl::linalg::detail::ResultDataSmall::vcl_g_right
viennacl::vector< NumericT > vcl_g_right
right interval limits at the end of the computation
Definition: structs.hpp:103
viennacl::linalg::detail::ResultDataLarge::g_lambda_mult
viennacl::vector< NumericT > g_lambda_mult
eigenvalues that have been generated in the second step from intervals that still contained multiple ...
Definition: structs.hpp:162
viennacl::linalg::detail::ResultDataSmall::vcl_g_left
viennacl::vector< NumericT > vcl_g_left
left interval limits at the end of the computation
Definition: structs.hpp:101
viennacl::linalg::detail::ResultDataSmall::vcl_g_left_count
viennacl::vector< unsigned int > vcl_g_left_count
number of eigenvalues smaller than the left interval limit
Definition: structs.hpp:105
viennacl::linalg::detail::ResultDataLarge::g_pos_one
viennacl::vector< unsigned int > g_pos_one
interval indices (position in sorted listed of eigenvalues) of intervals containing one eigenvalue af...
Definition: structs.hpp:143
bisect.hpp
OpenCL kernels for the bisection algorithm for eigenvalues.
VIENNACL_BISECT_MAX_THREADS_BLOCK_SMALL_MATRIX
#define VIENNACL_BISECT_MAX_THREADS_BLOCK_SMALL_MATRIX
Definition: config.hpp:38
viennacl::linalg::opencl::BISECT_KERNEL_LARGE_MULT_INTERVALS
const std::string BISECT_KERNEL_LARGE_MULT_INTERVALS
Definition: bisect_kernel_calls.hpp:46
viennacl::linalg::detail::ResultDataLarge::g_right_one
viennacl::vector< NumericT > g_right_one
right interval limits of intervals containing one eigenvalue after the first iteration step ...
Definition: structs.hpp:140
viennacl::ocl::enqueue
void enqueue(KernelType &k, viennacl::ocl::command_queue const &queue)
Enqueues a kernel in the provided queue.
Definition: enqueue.hpp:50
viennacl::linalg::detail::ResultDataLarge::g_pos_mult
viennacl::vector< unsigned int > g_pos_mult
eigenvalue index of intervals that have been generated in the second processing step ...
Definition: structs.hpp:165
viennacl::linalg::detail::ResultDataSmall::vcl_g_right_count
viennacl::vector< unsigned int > vcl_g_right_count
number of eigenvalues bigger than the right interval limit
Definition: structs.hpp:107
viennacl::linalg::detail::ResultDataLarge
In this class the data of the result for large matrices is stored.
Definition: structs.hpp:125
viennacl::ocl::kernel::global_work_size
size_type global_work_size(int index=0) const
Returns the global work size at the respective dimension.
Definition: kernel.hpp:751
viennacl::linalg::detail::ResultDataLarge::g_blocks_mult_sum
viennacl::vector< unsigned int > g_blocks_mult_sum
accumulated number of intervals in g_left_mult etc. of blocks of intervals containing more than one e...
Definition: structs.hpp:159
viennacl::linalg::detail::ResultDataLarge::g_num_one
viennacl::scalar< unsigned int > g_num_one
number of intervals containing one eigenvalue after the first step
Definition: structs.hpp:131
viennacl::linalg::detail::ResultDataSmall
In this class the data of the result for small matrices is stored.
Definition: structs.hpp:96
viennacl::linalg::opencl::kernels::bisect_kernel
Main kernel class for the generation of the bisection kernels and utilities.
Definition: bisect.hpp:2566
viennacl::linalg::opencl::bisectLarge
void bisectLarge(const viennacl::linalg::detail::InputData< NumericT > &input, viennacl::linalg::detail::ResultDataLarge< NumericT > &result, const unsigned int mat_size, const NumericT lg, const NumericT ug, const NumericT precision)
Definition: bisect_kernel_calls.hpp:79
viennacl::linalg::detail::InputData::g_a
viennacl::vector< NumericT > g_a
device side representation of diagonal
Definition: structs.hpp:60
viennacl::linalg::detail::ResultDataLarge::g_right_mult
viennacl::vector< NumericT > g_right_mult
right interval limits of intervals containing multiple eigenvalues after the first iteration step ...
Definition: structs.hpp:148