Skip to content

Commit

Permalink
Add get_info<Info>() specializations
Browse files Browse the repository at this point in the history
  • Loading branch information
kylelutz committed Jul 3, 2014
1 parent bfe2bdd commit dd62500
Show file tree
Hide file tree
Showing 13 changed files with 302 additions and 3 deletions.
23 changes: 23 additions & 0 deletions include/boost/compute/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,34 @@ class buffer : public memory_object
return get_memory_info<T>(info);
}

/// \overload
template<int Enum>
typename detail::get_object_info_type<buffer, Enum>::type
get_info() const;

/// Creates a new buffer with a copy of the data in \c *this. Uses
/// \p queue to perform the copy.
buffer clone(command_queue &queue) const;
};

// define get_info() specializations for buffer
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(buffer,
((cl_mem_object_type, CL_MEM_TYPE))
((cl_mem_flags, CL_MEM_FLAGS))
((size_t, CL_MEM_SIZE))
((void *, CL_MEM_HOST_PTR))
((cl_uint, CL_MEM_MAP_COUNT))
((cl_uint, CL_MEM_REFERENCE_COUNT))
((cl_context, CL_MEM_CONTEXT))
)

#ifdef CL_VERSION_1_1
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(buffer,
((cl_mem, CL_MEM_ASSOCIATED_MEMOBJECT))
((size_t, CL_MEM_OFFSET))
)
#endif // CL_VERSION_1_1

namespace detail {

// set_kernel_arg specialization for buffer
Expand Down
13 changes: 13 additions & 0 deletions include/boost/compute/command_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ class command_queue
return detail::get_object_info<T>(clGetCommandQueueInfo, m_queue, info);
}

/// \overload
template<int Enum>
typename detail::get_object_info_type<command_queue, Enum>::type
get_info() const;

/// Returns the properties for the command queue.
cl_command_queue_properties get_properties() const
{
Expand Down Expand Up @@ -1429,6 +1434,14 @@ inline image2d image2d::clone(command_queue &queue) const
return copy;
}

// define get_info() specializations for command_queue
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(command_queue,
((cl_context, CL_QUEUE_CONTEXT))
((cl_device_id, CL_QUEUE_DEVICE))
((uint_, CL_QUEUE_REFERENCE_COUNT))
((cl_command_queue_properties, CL_QUEUE_PROPERTIES))
)

} // end compute namespace
} // end boost namespace

Expand Down
18 changes: 18 additions & 0 deletions include/boost/compute/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ class context
return detail::get_object_info<T>(clGetContextInfo, m_context, info);
}

/// \overload
template<int Enum>
typename detail::get_object_info_type<context, Enum>::type
get_info() const;

/// Returns \c true if the context is the same at \p other.
bool operator==(const context &other) const
{
Expand Down Expand Up @@ -222,6 +227,19 @@ class context
cl_context m_context;
};

// define get_info() specializations for context
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(context,
((cl_uint, CL_CONTEXT_REFERENCE_COUNT))
((std::vector<cl_device_id>, CL_CONTEXT_DEVICES))
((std::vector<cl_context_properties>, CL_CONTEXT_PROPERTIES))
)

#ifdef CL_VERSION_1_1
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(context,
((cl_uint, CL_CONTEXT_NUM_DEVICES))
)
#endif // CL_VERSION_1_1

} // end compute namespace
} // end boost namespace

Expand Down
27 changes: 27 additions & 0 deletions include/boost/compute/detail/get_object_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,33 @@ inline T get_object_info(Function f, Object o, Info i)
return _get_object_info_impl<T, Function, Object, Info>()(f, o, i);
}

// returns the value type for the clGet*Info() call on Object with Enum.
template<class Object, int Enum>
struct get_object_info_type;

// defines the object::get_info<Enum>() specialization
#define BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATION(object_type, result_type, value) \
namespace detail { \
template<> struct get_object_info_type<object_type, value> { typedef result_type type; }; \
} \
template<> inline result_type object_type::get_info<value>() const \
{ \
return get_info<result_type>(value); \
}

// used by BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS()
#define BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_IMPL(r, data, elem) \
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATION( \
data, BOOST_PP_TUPLE_ELEM(2, 0, elem), BOOST_PP_TUPLE_ELEM(2, 1, elem) \
)

// defines the object::get_info<Enum>() specialization for each
// (result_type, value) tuple in seq for object_type.
#define BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(object_type, seq) \
BOOST_PP_SEQ_FOR_EACH( \
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_IMPL, object_type, seq \
)

} // end detail namespace
} // end compute namespace
} // end boost namespace
Expand Down
109 changes: 109 additions & 0 deletions include/boost/compute/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,29 @@ class device

/// Returns information about the device.
///
/// For example, to get the number of compute units:
/// \code
/// device.get_info<cl_uint>(CL_DEVICE_MAX_COMPUTE_UNITS);
/// \endcode
///
/// Alternatively, the template-specialized version can be used which
/// automatically determines the result type:
/// \code
/// device.get_info<CL_DEVICE_MAX_COMPUTE_UNITS>();
/// \endcode
///
/// \see_opencl_ref{clGetDeviceInfo}
template<class T>
T get_info(cl_device_info info) const
{
return detail::get_object_info<T>(clGetDeviceInfo, m_id, info);
}

/// \overload
template<int Enum>
typename detail::get_object_info_type<device, Enum>::type
get_info() const;

#if defined(CL_VERSION_1_2) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
/// Partitions the device into multiple sub-devices according to
/// \p properties.
Expand Down Expand Up @@ -407,6 +423,99 @@ inline uint_ device::preferred_vector_width<double_>() const
return get_info<uint_>(CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE);
}

// define get_info() specializations for device
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(device,
((cl_uint, CL_DEVICE_ADDRESS_BITS))
((bool, CL_DEVICE_AVAILABLE))
((bool, CL_DEVICE_COMPILER_AVAILABLE))
((bool, CL_DEVICE_ENDIAN_LITTLE))
((bool, CL_DEVICE_ERROR_CORRECTION_SUPPORT))
((cl_device_exec_capabilities, CL_DEVICE_EXECUTION_CAPABILITIES))
((std::string, CL_DEVICE_EXTENSIONS))
((cl_ulong, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE))
((cl_device_mem_cache_type, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE))
((cl_ulong, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE))
((cl_ulong, CL_DEVICE_GLOBAL_MEM_SIZE))
((bool, CL_DEVICE_IMAGE_SUPPORT))
((size_t, CL_DEVICE_IMAGE2D_MAX_HEIGHT))
((size_t, CL_DEVICE_IMAGE2D_MAX_WIDTH))
((size_t, CL_DEVICE_IMAGE3D_MAX_DEPTH))
((size_t, CL_DEVICE_IMAGE3D_MAX_HEIGHT))
((size_t, CL_DEVICE_IMAGE3D_MAX_WIDTH))
((cl_ulong, CL_DEVICE_LOCAL_MEM_SIZE))
((cl_device_local_mem_type, CL_DEVICE_LOCAL_MEM_TYPE))
((cl_uint, CL_DEVICE_MAX_CLOCK_FREQUENCY))
((cl_uint, CL_DEVICE_MAX_COMPUTE_UNITS))
((cl_uint, CL_DEVICE_MAX_CONSTANT_ARGS))
((cl_ulong, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE))
((cl_ulong, CL_DEVICE_MAX_MEM_ALLOC_SIZE))
((size_t, CL_DEVICE_MAX_PARAMETER_SIZE))
((cl_uint, CL_DEVICE_MAX_READ_IMAGE_ARGS))
((cl_uint, CL_DEVICE_MAX_SAMPLERS))
((size_t, CL_DEVICE_MAX_WORK_GROUP_SIZE))
((cl_uint, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS))
((std::vector<size_t>, CL_DEVICE_MAX_WORK_ITEM_SIZES))
((cl_uint, CL_DEVICE_MAX_WRITE_IMAGE_ARGS))
((cl_uint, CL_DEVICE_MEM_BASE_ADDR_ALIGN))
((cl_uint, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE))
((std::string, CL_DEVICE_NAME))
((cl_platform_id, CL_DEVICE_PLATFORM))
((cl_uint, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR))
((cl_uint, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT))
((cl_uint, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT))
((cl_uint, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG))
((cl_uint, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT))
((cl_uint, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE))
((std::string, CL_DEVICE_PROFILE))
((size_t, CL_DEVICE_PROFILING_TIMER_RESOLUTION))
((cl_command_queue_properties, CL_DEVICE_QUEUE_PROPERTIES))
((cl_device_fp_config, CL_DEVICE_SINGLE_FP_CONFIG))
((cl_device_type, CL_DEVICE_TYPE))
((std::string, CL_DEVICE_VENDOR))
((cl_uint, CL_DEVICE_VENDOR_ID))
((std::string, CL_DEVICE_VERSION))
((std::string, CL_DRIVER_VERSION))
)
#ifdef CL_DEVICE_DOUBLE_FP_CONFIG
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(device,
((cl_device_fp_config, CL_DEVICE_DOUBLE_FP_CONFIG))
)
#endif

#ifdef CL_DEVICE_HALF_FP_CONFIG
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(device,
((cl_device_fp_config, CL_DEVICE_HALF_FP_CONFIG))
)
#endif

#ifdef CL_VERSION_1_1
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(device,
((bool, CL_DEVICE_HOST_UNIFIED_MEMORY))
((cl_uint, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR))
((cl_uint, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT))
((cl_uint, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT))
((cl_uint, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG))
((cl_uint, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT))
((cl_uint, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE))
((std::string, CL_DEVICE_OPENCL_C_VERSION))
)
#endif // CL_VERSION_1_1

#ifdef CL_VERSION_1_2
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(device,
((std::string, CL_DEVICE_BUILT_IN_KERNELS))
((bool, CL_DEVICE_LINKER_AVAILABLE))
((cl_device_id, CL_DEVICE_PARENT_DEVICE))
((cl_uint, CL_DEVICE_PARTITION_MAX_SUB_DEVICES))
((cl_device_partition_property, CL_DEVICE_PARTITION_PROPERTIES))
((cl_device_affinity_domain, CL_DEVICE_PARTITION_AFFINITY_DOMAIN))
((cl_device_partition_property, CL_DEVICE_PARTITION_TYPE))
((size_t, CL_DEVICE_PRINTF_BUFFER_SIZE))
((bool, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC))
((cl_uint, CL_DEVICE_REFERENCE_COUNT))
)
#endif // CL_VERSION_1_2

} // end compute namespace
} // end boost namespace

Expand Down
19 changes: 19 additions & 0 deletions include/boost/compute/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ class event
return detail::get_object_info<T>(clGetEventInfo, m_event, info);
}

/// \overload
template<int Enum>
typename detail::get_object_info_type<event, Enum>::type
get_info() const;

/// Returns profiling information for the event.
///
/// \see event::duration()
Expand Down Expand Up @@ -294,6 +299,20 @@ class event
cl_event m_event;
};

// define get_info() specializations for event
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(event,
((cl_command_queue, CL_EVENT_COMMAND_QUEUE))
((cl_command_type, CL_EVENT_COMMAND_TYPE))
((cl_int, CL_EVENT_COMMAND_EXECUTION_STATUS))
((cl_uint, CL_EVENT_REFERENCE_COUNT))
)

#ifdef CL_VERSION_1_1
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(event,
((cl_context, CL_EVENT_CONTEXT))
)
#endif

} // end compute namespace
} // end boost namespace

Expand Down
14 changes: 14 additions & 0 deletions include/boost/compute/image_sampler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ class image_sampler
return detail::get_object_info<T>(clGetSamplerInfo, m_sampler, info);
}

/// \overload
template<int Enum>
typename detail::get_object_info_type<image_sampler, Enum>::type
get_info() const;

operator cl_sampler() const
{
return m_sampler;
Expand All @@ -147,6 +152,15 @@ class image_sampler
cl_sampler m_sampler;
};

// define get_info() specializations for image_sampler
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(image_sampler,
((cl_uint, CL_SAMPLER_REFERENCE_COUNT))
((cl_context, CL_SAMPLER_CONTEXT))
((cl_addressing_mode, CL_SAMPLER_ADDRESSING_MODE))
((cl_filter_mode, CL_SAMPLER_FILTER_MODE))
((bool, CL_SAMPLER_NORMALIZED_COORDS))
)

namespace detail {

// set_kernel_arg specialization for image samplers
Expand Down
20 changes: 20 additions & 0 deletions include/boost/compute/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ class kernel
return detail::get_object_info<T>(clGetKernelInfo, m_kernel, info);
}

/// \overload
template<int Enum>
typename detail::get_object_info_type<kernel, Enum>::type
get_info() const;

#if defined(CL_VERSION_1_2) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
/// Returns information about the argument at \p index.
///
Expand Down Expand Up @@ -306,6 +311,21 @@ inline kernel program::create_kernel(const std::string &name) const
return kernel(*this, name);
}

// define get_info() specializations for kernel
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(kernel,
((std::string, CL_KERNEL_FUNCTION_NAME))
((cl_uint, CL_KERNEL_NUM_ARGS))
((cl_uint, CL_KERNEL_REFERENCE_COUNT))
((cl_context, CL_KERNEL_CONTEXT))
((cl_program, CL_KERNEL_PROGRAM))
)

#ifdef CL_VERSION_1_2
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(kernel,
((std::string, CL_KERNEL_ATTRIBUTES))
)
#endif // CL_VERSION_1_2

namespace detail {

// set_kernel_arg implementation for built-in types
Expand Down
14 changes: 14 additions & 0 deletions include/boost/compute/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ class platform
return detail::get_object_info<T>(clGetPlatformInfo, m_platform, info);
}

/// \overload
template<int Enum>
typename detail::get_object_info_type<platform, Enum>::type
get_info() const;

/// Returns the address of the \p function_name extension
/// function. Returns \c 0 if \p function_name is invalid.
void* get_extension_function_address(const char *function_name) const
Expand All @@ -184,6 +189,15 @@ class platform
cl_platform_id m_platform;
};

// define get_info() specializations for platform
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(platform,
((std::string, CL_PLATFORM_PROFILE))
((std::string, CL_PLATFORM_VERSION))
((std::string, CL_PLATFORM_NAME))
((std::string, CL_PLATFORM_VENDOR))
((std::string, CL_PLATFORM_EXTENSIONS))
)

} // end compute namespace
} // end boost namespace

Expand Down
Loading

0 comments on commit dd62500

Please sign in to comment.