Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:01

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013-2015 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_IMAGE_IMAGE_OBJECT_HPP
0012 #define BOOST_COMPUTE_IMAGE_IMAGE_OBJECT_HPP
0013 
0014 #include <algorithm>
0015 #include <vector>
0016 
0017 #include <boost/compute/config.hpp>
0018 #include <boost/compute/memory_object.hpp>
0019 #include <boost/compute/detail/get_object_info.hpp>
0020 #include <boost/compute/image/image_format.hpp>
0021 
0022 namespace boost {
0023 namespace compute {
0024 
0025 /// \class image_object
0026 /// \brief Base-class for image objects.
0027 ///
0028 /// The image_object class is the base-class for image objects on compute
0029 /// devices.
0030 ///
0031 /// \see image1d, image2d, image3d
0032 class image_object : public memory_object
0033 {
0034 public:
0035     image_object()
0036         : memory_object()
0037     {
0038     }
0039 
0040     explicit image_object(cl_mem mem, bool retain = true)
0041         : memory_object(mem, retain)
0042     {
0043     }
0044 
0045     image_object(const image_object &other)
0046         : memory_object(other)
0047     {
0048     }
0049 
0050     image_object& operator=(const image_object &other)
0051     {
0052         if(this != &other){
0053             memory_object::operator=(other);
0054         }
0055 
0056         return *this;
0057     }
0058 
0059     #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
0060     image_object(image_object&& other) BOOST_NOEXCEPT
0061         : memory_object(std::move(other))
0062     {
0063     }
0064 
0065     /// \internal_
0066     image_object& operator=(image_object&& other) BOOST_NOEXCEPT
0067     {
0068         memory_object::operator=(std::move(other));
0069 
0070         return *this;
0071     }
0072     #endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
0073 
0074     /// Destroys the image object.
0075     ~image_object()
0076     {
0077     }
0078 
0079     /// Returns information about the image object.
0080     ///
0081     /// \see_opencl_ref{clGetImageInfo}
0082     template<class T>
0083     T get_image_info(cl_mem_info info) const
0084     {
0085         return detail::get_object_info<T>(clGetImageInfo, m_mem, info);
0086     }
0087 
0088     /// Returns the format for the image.
0089     image_format format() const
0090     {
0091         return image_format(get_image_info<cl_image_format>(CL_IMAGE_FORMAT));
0092     }
0093 
0094     /// \internal_ (deprecated)
0095     image_format get_format() const
0096     {
0097         return format();
0098     }
0099 
0100     /// Returns the width of the image.
0101     size_t width() const
0102     {
0103         return get_image_info<size_t>(CL_IMAGE_WIDTH);
0104     }
0105 
0106     /// Returns the height of the image.
0107     ///
0108     /// For 1D images, this function will return \c 1.
0109     size_t height() const
0110     {
0111         return get_image_info<size_t>(CL_IMAGE_HEIGHT);
0112     }
0113 
0114     /// Returns the depth of the image.
0115     ///
0116     /// For 1D and 2D images, this function will return \c 1.
0117     size_t depth() const
0118     {
0119         return get_image_info<size_t>(CL_IMAGE_DEPTH);
0120     }
0121 
0122     /// Returns the supported image formats for the \p type in \p context.
0123     ///
0124     /// \see_opencl_ref{clGetSupportedImageFormats}
0125     static std::vector<image_format>
0126     get_supported_formats(const context &context,
0127                           cl_mem_object_type type,
0128                           cl_mem_flags flags = read_write)
0129     {
0130         cl_uint count = 0;
0131         clGetSupportedImageFormats(context, flags, type, 0, 0, &count);
0132 
0133         std::vector<cl_image_format> cl_formats(count);
0134         clGetSupportedImageFormats(context, flags, type, count, &cl_formats[0], 0);
0135 
0136         std::vector<image_format> formats;
0137         formats.reserve(count);
0138 
0139         for(cl_uint i = 0; i < count; i++){
0140             formats.push_back(image_format(cl_formats[i]));
0141         }
0142 
0143         return formats;
0144     }
0145 
0146     /// Returns \c true if \p format is a supported image format for
0147     /// \p type in \p context with \p flags.
0148     static bool is_supported_format(const image_format &format,
0149                                     const context &context,
0150                                     cl_mem_object_type type,
0151                                     cl_mem_flags flags = read_write)
0152     {
0153         const std::vector<image_format> formats =
0154             get_supported_formats(context, type, flags);
0155 
0156         return std::find(formats.begin(), formats.end(), format) != formats.end();
0157     }
0158 };
0159 
0160 namespace detail {
0161 
0162 // set_kernel_arg() specialization for image_object
0163 template<>
0164 struct set_kernel_arg<image_object> : public set_kernel_arg<memory_object> { };
0165 
0166 } // end detail namespace
0167 } // end compute namespace
0168 } // end boost namespace
0169 
0170 #endif // BOOST_COMPUTE_IMAGE_IMAGE_OBJECT_HPP