ViennaCL - The Vienna Computing Library  1.5.1
viennacl/ocl/utils.hpp
Go to the documentation of this file.
00001 #ifndef VIENNACL_OCL_UTILS_HPP_
00002 #define VIENNACL_OCL_UTILS_HPP_
00003 
00004 /* =========================================================================
00005    Copyright (c) 2010-2014, Institute for Microelectronics,
00006                             Institute for Analysis and Scientific Computing,
00007                             TU Wien.
00008    Portions of this software are copyright by UChicago Argonne, LLC.
00009 
00010                             -----------------
00011                   ViennaCL - The Vienna Computing Library
00012                             -----------------
00013 
00014    Project Head:    Karl Rupp                   rupp@iue.tuwien.ac.at
00015 
00016    (A list of authors and contributors can be found in the PDF manual)
00017 
00018    License:         MIT (X11), see file LICENSE in the base directory
00019 ============================================================================= */
00020 
00025 #include <vector>
00026 #include <string>
00027 #include "viennacl/ocl/backend.hpp"
00028 #include "viennacl/ocl/device.hpp"
00029 
00030 namespace viennacl
00031 {
00032   namespace ocl
00033   {
00034 
00037     template <typename ScalarType>
00038     struct DOUBLE_PRECISION_CHECKER
00039     {
00040       static void apply(viennacl::ocl::context const &) {}
00041     };
00042 
00044     template <>
00045     struct DOUBLE_PRECISION_CHECKER<double>
00046     {
00047       static void apply(viennacl::ocl::context const & ctx)
00048       {
00049         if (!ctx.current_device().double_support())
00050           throw viennacl::ocl::double_precision_not_provided_error();
00051       }
00052     };
00056     template <typename T>
00057     struct type_to_string;
00058 
00060     template <> struct type_to_string<char>   { static std::string apply() { return "char";  } };
00061     template <> struct type_to_string<short>  { static std::string apply() { return "short"; } };
00062     template <> struct type_to_string<int>    { static std::string apply() { return "int";   } };
00063     template <> struct type_to_string<long>   { static std::string apply() { return "long";  } };
00064 
00065     template <> struct type_to_string<unsigned char>   { static std::string apply() { return "uchar";  } };
00066     template <> struct type_to_string<unsigned short>  { static std::string apply() { return "ushort"; } };
00067     template <> struct type_to_string<unsigned int>    { static std::string apply() { return "uint";   } };
00068     template <> struct type_to_string<unsigned long>   { static std::string apply() { return "ulong";  } };
00069 
00070     template <> struct type_to_string<float>  { static std::string apply() { return "float";  } };
00071     template <> struct type_to_string<double> { static std::string apply() { return "double"; } };
00074     template <typename T>
00075     void append_double_precision_pragma(viennacl::ocl::context const & /*ctx*/, std::string & /*source*/) {}
00076 
00077     template <>
00078     inline void append_double_precision_pragma<double>(viennacl::ocl::context const & ctx, std::string & source)
00079     {
00080       source.append("#pragma OPENCL EXTENSION " + ctx.current_device().double_support_extension() + " : enable\n\n");
00081     }
00082 
00083   } //ocl
00084 } //viennacl
00085 #endif