Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:34:41

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_IMAGE1D_HPP
0012 #define BOOST_COMPUTE_IMAGE_IMAGE1D_HPP
0013 
0014 #include <boost/throw_exception.hpp>
0015 
0016 #include <boost/compute/config.hpp>
0017 #include <boost/compute/exception/opencl_error.hpp>
0018 #include <boost/compute/image/image_format.hpp>
0019 #include <boost/compute/image/image_object.hpp>
0020 #include <boost/compute/type_traits/type_name.hpp>
0021 #include <boost/compute/utility/extents.hpp>
0022 
0023 namespace boost {
0024 namespace compute {
0025 
0026 // forward declarations
0027 class command_queue;
0028 
0029 /// \class image1d
0030 /// \brief An OpenCL 1D image object
0031 ///
0032 /// \opencl_version_warning{1,2}
0033 ///
0034 /// \see image_format, image2d
0035 class image1d : public image_object
0036 {
0037 public:
0038     /// Creates a null image1d object.
0039     image1d()
0040         : image_object()
0041     {
0042     }
0043 
0044     /// Creates a new image1d object.
0045     ///
0046     /// \see_opencl_ref{clCreateImage}
0047     image1d(const context &context,
0048             size_t image_width,
0049             const image_format &format,
0050             cl_mem_flags flags = read_write,
0051             void *host_ptr = 0)
0052     {
0053     #ifdef BOOST_COMPUTE_CL_VERSION_1_2
0054         cl_image_desc desc;
0055         desc.image_type = CL_MEM_OBJECT_IMAGE1D;
0056         desc.image_width = image_width;
0057         desc.image_height = 1;
0058         desc.image_depth = 1;
0059         desc.image_array_size = 0;
0060         desc.image_row_pitch = 0;
0061         desc.image_slice_pitch = 0;
0062         desc.num_mip_levels = 0;
0063         desc.num_samples = 0;
0064     #ifdef BOOST_COMPUTE_CL_VERSION_2_0
0065         desc.mem_object = 0;
0066     #else
0067         desc.buffer = 0;
0068     #endif
0069 
0070         cl_int error = 0;
0071 
0072         m_mem = clCreateImage(
0073             context, flags, format.get_format_ptr(), &desc, host_ptr, &error
0074         );
0075 
0076         if(!m_mem){
0077             BOOST_THROW_EXCEPTION(opencl_error(error));
0078         }
0079     #else
0080         // image1d objects are only supported in OpenCL 1.2 and later
0081         BOOST_THROW_EXCEPTION(opencl_error(CL_IMAGE_FORMAT_NOT_SUPPORTED));
0082     #endif
0083     }
0084 
0085     /// Creates a new image1d as a copy of \p other.
0086     image1d(const image1d &other)
0087       : image_object(other)
0088     {
0089     }
0090 
0091     /// Copies the image1d from \p other.
0092     image1d& operator=(const image1d &other)
0093     {
0094         image_object::operator=(other);
0095 
0096         return *this;
0097     }
0098 
0099     #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
0100     /// Move-constructs a new image object from \p other.
0101     image1d(image1d&& other) BOOST_NOEXCEPT
0102         : image_object(std::move(other))
0103     {
0104     }
0105 
0106     /// Move-assigns the image from \p other to \c *this.
0107     image1d& operator=(image1d&& other) BOOST_NOEXCEPT
0108     {
0109         image_object::operator=(std::move(other));
0110 
0111         return *this;
0112     }
0113     #endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
0114 
0115     /// Destroys the image1d object.
0116     ~image1d()
0117     {
0118     }
0119 
0120     /// Returns the size (width) of the image.
0121     extents<1> size() const
0122     {
0123         extents<1> size;
0124         size[0] = get_info<size_t>(CL_IMAGE_WIDTH);
0125         return size;
0126     }
0127 
0128     /// Returns the origin of the image (\c 0).
0129     extents<1> origin() const
0130     {
0131         return extents<1>();
0132     }
0133 
0134     /// Returns information about the image.
0135     ///
0136     /// \see_opencl_ref{clGetImageInfo}
0137     template<class T>
0138     T get_info(cl_image_info info) const
0139     {
0140         return get_image_info<T>(info);
0141     }
0142 
0143     /// \overload
0144     template<int Enum>
0145     typename detail::get_object_info_type<image1d, Enum>::type
0146     get_info() const;
0147 
0148     /// Returns the supported image formats for the context.
0149     ///
0150     /// \see_opencl_ref{clGetSupportedImageFormats}
0151     static std::vector<image_format>
0152     get_supported_formats(const context &context, cl_mem_flags flags = read_write)
0153     {
0154     #ifdef BOOST_COMPUTE_CL_VERSION_1_2
0155         return image_object::get_supported_formats(context, CL_MEM_OBJECT_IMAGE1D, flags);
0156     #else
0157         return std::vector<image_format>();
0158     #endif
0159     }
0160 
0161     /// Returns \c true if \p format is a supported 1D image format for
0162     /// \p context.
0163     static bool is_supported_format(const image_format &format,
0164                                     const context &context,
0165                                     cl_mem_flags flags = read_write)
0166     {
0167     #ifdef BOOST_COMPUTE_CL_VERSION_1_2
0168         return image_object::is_supported_format(
0169             format, context, CL_MEM_OBJECT_IMAGE1D, flags
0170         );
0171     #else
0172         return false;
0173     #endif
0174     }
0175 
0176     /// Creates a new image with a copy of the data in \c *this. Uses \p queue
0177     /// to perform the copy operation.
0178     image1d clone(command_queue &queue) const;
0179 };
0180 
0181 /// \internal_ define get_info() specializations for image1d
0182 BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(image1d,
0183     ((cl_image_format, CL_IMAGE_FORMAT))
0184     ((size_t, CL_IMAGE_ELEMENT_SIZE))
0185     ((size_t, CL_IMAGE_ROW_PITCH))
0186     ((size_t, CL_IMAGE_SLICE_PITCH))
0187     ((size_t, CL_IMAGE_WIDTH))
0188     ((size_t, CL_IMAGE_HEIGHT))
0189     ((size_t, CL_IMAGE_DEPTH))
0190 )
0191 
0192 namespace detail {
0193 
0194 // set_kernel_arg() specialization for image1d
0195 template<>
0196 struct set_kernel_arg<image1d> : public set_kernel_arg<image_object> { };
0197 
0198 } // end detail namespace
0199 } // end compute namespace
0200 } // end boost namespace
0201 
0202 BOOST_COMPUTE_TYPE_NAME(boost::compute::image1d, image1d_t)
0203 
0204 #endif // BOOST_COMPUTE_IMAGE_IMAGE1D_HPP