Пример #1
0
          static void init(viennacl::ocl::context & ctx)
          {
            viennacl::ocl::DOUBLE_PRECISION_CHECKER<TYPE>::apply(ctx);
            std::string numeric_string = viennacl::ocl::type_to_string<TYPE>::apply();

            static std::map<cl_context, bool> init_done;
            if (!init_done[ctx.handle().get()])
            {
              std::string source;
              source.reserve(8192);

              viennacl::ocl::append_double_precision_pragma<TYPE>(ctx, source);

              // fully parametrized kernels:
              generate_asbs(source, numeric_string);
              generate_scalar_swap(source, numeric_string);


              std::string prog_name = program_name();
              #ifdef VIENNACL_BUILD_INFO
              std::cout << "Creating program " << prog_name << std::endl;
              #endif
              ctx.add_program(source, prog_name);
              init_done[ctx.handle().get()] = true;
            } //if
          } //init
Пример #2
0
          static void init(viennacl::ocl::context & ctx)
          {
            viennacl::ocl::DOUBLE_PRECISION_CHECKER<NumericT>::apply(ctx);
            std::string numeric_string = viennacl::ocl::type_to_string<NumericT>::apply();

            static std::map<cl_context, bool> init_done;
            if (!init_done[ctx.handle().get()])
            {
              std::string source;
              source.reserve(1024);

              viennacl::ocl::append_double_precision_pragma<NumericT>(ctx, source);

              generate_coordinate_matrix_vec_mul(source, numeric_string);
              generate_coordinate_matrix_dense_matrix_multiplication(source, numeric_string);
              generate_coordinate_matrix_row_info_extractor(source, numeric_string);

              std::string prog_name = program_name();
              #ifdef VIENNACL_BUILD_INFO
              std::cout << "Creating program " << prog_name << std::endl;
              #endif
              ctx.add_program(source, prog_name);
              init_done[ctx.handle().get()] = true;
            } //if
          } //init
Пример #3
0
          static void init(viennacl::ocl::context & ctx)
          {
            viennacl::ocl::DOUBLE_PRECISION_CHECKER<NumericT>::apply(ctx);
            std::string numeric_string = viennacl::ocl::type_to_string<NumericT>::apply();

            static std::map<cl_context, bool> init_done;
            if (!init_done[ctx.handle().get()])
            {
              std::string source;
              source.reserve(8192);

              viennacl::ocl::append_double_precision_pragma<NumericT>(ctx, source);

              // only generate for floating points (forces error for integers)
              if (numeric_string == "float" || numeric_string == "double")
              {
                generate_nmf_el_wise_mul_div(source, numeric_string);
              }

              std::string prog_name = program_name();
              #ifdef VIENNACL_BUILD_INFO
              std::cout << "Creating program " << prog_name << std::endl;
              #endif
              ctx.add_program(source, prog_name);
              init_done[ctx.handle().get()] = true;
            } //if
          } //init
Пример #4
0
  static void init(viennacl::ocl::context & ctx)
  {
    viennacl::ocl::DOUBLE_PRECISION_CHECKER<NumericT>::apply(ctx);
    std::string numeric_string = viennacl::ocl::type_to_string<NumericT>::apply();

    static std::map<cl_context, bool> init_done;
    if (!init_done[ctx.handle().get()])
    {
      std::string source;
      source.reserve(8192);
      bool is_row_major = viennacl::is_row_major<F>::value;

      viennacl::ocl::append_double_precision_pragma<NumericT>(ctx, source);

      // unary operations
      if (numeric_string == "float" || numeric_string == "double")
      {
        generate_matrix_unary_element_ops(source, numeric_string, "acos",  is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "acosh", is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "asin",  is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "asinh", is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "atan",  is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "atanh", is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "ceil",  is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "cos",   is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "cosh",  is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "erf",   is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "erfc",  is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "exp",   is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "exp2",  is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "exp10", is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "fabs",  is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "floor", is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "log",   is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "log2",  is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "log10", is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "round", is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "rsqrt", is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "sign",  is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "sin",   is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "sinh",  is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "sqrt",  is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "tan",   is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "tanh",  is_row_major);
        generate_matrix_unary_element_ops(source, numeric_string, "trunc", is_row_major);
      }
      else
      {
        generate_matrix_unary_element_ops(source, numeric_string, "abs", is_row_major);
      }

      std::string prog_name = program_name();
      #ifdef VIENNACL_BUILD_INFO
      std::cout << "Creating program " << prog_name << std::endl;
      #endif
      ctx.add_program(source, prog_name);
      init_done[ctx.handle().get()] = true;
    } //if
  } //init
Пример #5
0
inline void execute(template_base const & T, statements_container const & statements, viennacl::ocl::context & ctx = viennacl::ocl::current_context(), bool force_compilation = false)
{
  //Generate program name
  std::string program_name = tree_parsing::statements_representation(statements, BIND_TO_HANDLE);
  execution_handler handler(program_name, ctx, ctx.current_device(), force_compilation);
  handler.add(program_name, T, statements);
  handler.execute(program_name, statements);
}
Пример #6
0
          static void init(viennacl::ocl::context & ctx)
          {
            viennacl::ocl::DOUBLE_PRECISION_CHECKER<TYPE>::apply(ctx);
            std::string numeric_string = viennacl::ocl::type_to_string<TYPE>::apply();

            static std::map<cl_context, bool> init_done;
            if (!init_done[ctx.handle().get()])
            {
              std::string source;
              source.reserve(8192);

              viennacl::ocl::append_double_precision_pragma<TYPE>(ctx, source);

              // unary operations
              generate_vector_unary_element_ops(source, numeric_string, "acos");
              generate_vector_unary_element_ops(source, numeric_string, "asin");
              generate_vector_unary_element_ops(source, numeric_string, "atan");
              generate_vector_unary_element_ops(source, numeric_string, "ceil");
              generate_vector_unary_element_ops(source, numeric_string, "cos");
              generate_vector_unary_element_ops(source, numeric_string, "cosh");
              generate_vector_unary_element_ops(source, numeric_string, "exp");
              generate_vector_unary_element_ops(source, numeric_string, "fabs");
              generate_vector_unary_element_ops(source, numeric_string, "floor");
              generate_vector_unary_element_ops(source, numeric_string, "log");
              generate_vector_unary_element_ops(source, numeric_string, "log10");
              generate_vector_unary_element_ops(source, numeric_string, "sin");
              generate_vector_unary_element_ops(source, numeric_string, "sinh");
              generate_vector_unary_element_ops(source, numeric_string, "sqrt");
              generate_vector_unary_element_ops(source, numeric_string, "tan");
              generate_vector_unary_element_ops(source, numeric_string, "tanh");

              // binary operations
              generate_vector_binary_element_ops(source, numeric_string);

              std::string prog_name = program_name();
              #ifdef VIENNACL_BUILD_INFO
              std::cout << "Creating program " << prog_name << std::endl;
              #endif
              ctx.add_program(source, prog_name);
              init_done[ctx.handle().get()] = true;
            } //if
          } //init
Пример #7
0
          static void init(viennacl::ocl::context & ctx)
          {
            viennacl::ocl::DOUBLE_PRECISION_CHECKER<NumericT>::apply(ctx);
            std::string numeric_string = viennacl::ocl::type_to_string<NumericT>::apply();
            bool row_major_A = viennacl::is_row_major<F_A>::value;
            bool row_major_B = viennacl::is_row_major<F_B>::value;
            bool row_major_C = viennacl::is_row_major<F_C>::value;


            static std::map<cl_context, bool> init_done;
            if (!init_done[ctx.handle().get()])
            {
              std::string source;
              source.reserve(8192);

              viennacl::ocl::append_double_precision_pragma<NumericT>(ctx, source);

              // only generate for floating points (forces error for integers)
              if (numeric_string == "float" || numeric_string == "double")
              {
                generate_matrix_prod_blas3(source, numeric_string, row_major_A, row_major_B, row_major_C, false, false);
                generate_matrix_prod_blas3(source, numeric_string, row_major_A, row_major_B, row_major_C, false, true);
                generate_matrix_prod_blas3(source, numeric_string, row_major_A, row_major_B, row_major_C, true, false);
                generate_matrix_prod_blas3(source, numeric_string, row_major_A, row_major_B, row_major_C, true, true);

                generate_matrix_prod16_blas3(source, numeric_string, row_major_A, row_major_B, row_major_C, false, false);
                generate_matrix_prod16_blas3(source, numeric_string, row_major_A, row_major_B, row_major_C, false, true);
                generate_matrix_prod16_blas3(source, numeric_string, row_major_A, row_major_B, row_major_C, true, false);
                generate_matrix_prod16_blas3(source, numeric_string, row_major_A, row_major_B, row_major_C, true, true);

              }

              std::string prog_name = program_name();
              #ifdef VIENNACL_BUILD_INFO
              std::cout << "Creating program " << prog_name << std::endl;
              #endif
              ctx.add_program(source, prog_name);
              init_done[ctx.handle().get()] = true;
            } //if
          } //init
Пример #8
0
  static void init(viennacl::ocl::context & ctx)
  {
    static std::map<cl_context, bool> init_done;
    if (!init_done[ctx.handle().get()])
    {
      viennacl::ocl::DOUBLE_PRECISION_CHECKER<NumericT>::apply(ctx);
      std::string numeric_string = viennacl::ocl::type_to_string<NumericT>::apply();

      std::string source;
      source.reserve(1024);

      viennacl::ocl::append_double_precision_pragma<NumericT>(ctx, source);

      // only generate for floating points (forces error for integers)
      if (numeric_string == "float" || numeric_string == "double")
      {
        generate_ilu_level_scheduling_substitute(source, numeric_string);

        generate_icc_extract_L_1(source);
        generate_icc_extract_L_2(source, numeric_string);
        generate_icc_chow_patel_sweep_kernel(source, numeric_string);

        generate_ilu_extract_LU_1(source);
        generate_ilu_extract_LU_2(source, numeric_string);
        generate_ilu_scale_kernel_1(source, numeric_string);
        generate_ilu_scale_kernel_2(source, numeric_string);
        generate_ilu_chow_patel_sweep_kernel(source, numeric_string);
        generate_ilu_form_neumann_matrix_kernel(source, numeric_string);
      }

      std::string prog_name = program_name();
      #ifdef VIENNACL_BUILD_INFO
      std::cout << "Creating program " << prog_name << std::endl;
      #endif
      ctx.add_program(source, prog_name);
      init_done[ctx.handle().get()] = true;
    } //if
  } //init
Пример #9
0
  static void init(viennacl::ocl::context & ctx)
  {
    static std::map<cl_context, bool> init_done;
    if (!init_done[ctx.handle().get()])
    {
      viennacl::ocl::DOUBLE_PRECISION_CHECKER<NumericT>::apply(ctx);
      std::string numeric_string = viennacl::ocl::type_to_string<NumericT>::apply();

      std::string source;
      source.reserve(8192);

      viennacl::ocl::append_double_precision_pragma<NumericT>(ctx, source);

      // unary operations
      if (numeric_string == "float" || numeric_string == "double")
      {
        generate_fft_bluestein_post(source, numeric_string);
        generate_fft_bluestein_pre(source, numeric_string);
        generate_fft_complex_to_real(source, numeric_string);
        generate_fft_div_vec_scalar(source, numeric_string);
        generate_fft_mult_vec(source, numeric_string);
        generate_fft_real_to_complex(source, numeric_string);
        generate_fft_reverse_inplace(source, numeric_string);
        generate_fft_transpose(source, numeric_string);
        generate_fft_transpose_inplace(source, numeric_string);
        generate_fft_vandermonde_prod(source, numeric_string);
        generate_fft_zero2(source, numeric_string);
      }

      std::string prog_name = program_name();
      #ifdef VIENNACL_BUILD_INFO
      std::cout << "Creating program " << prog_name << std::endl;
      #endif
      ctx.add_program(source, prog_name);
      init_done[ctx.handle().get()] = true;
    } //if
  } //init
Пример #10
0
 inline void append_double_precision_pragma<double>(viennacl::ocl::context const & ctx, std::string & source)
 {
   source.append("#pragma OPENCL EXTENSION " + ctx.current_device().double_support_extension() + " : enable\n\n");
 }
Пример #11
0
 static void apply(viennacl::ocl::context const & ctx)
 {
   if (!ctx.current_device().double_support())
     throw viennacl::ocl::double_precision_not_provided_error();
 }
Пример #12
0
 /** @brief Creates an array of the specified size in the current OpenCL context. If the second argument is provided, the buffer is initialized with data from that pointer.
  *
  * @param size_in_bytes   Number of bytes to allocate
  * @param host_ptr        Pointer to data which will be copied to the new array. Must point to at least 'size_in_bytes' bytes of data.
  * @param ctx             Optional context in which the matrix is created (one out of multiple OpenCL contexts, CUDA, host)
  *
  */
 inline cl_mem memory_create(viennacl::ocl::context const & ctx, vcl_size_t size_in_bytes, const void * host_ptr = NULL)
 {
   //std::cout << "Creating buffer (" << size_in_bytes << " bytes) host buffer " << host_ptr << " in context " << &ctx << std::endl;
   return ctx.create_memory_without_smart_handle(CL_MEM_READ_WRITE, static_cast<unsigned int>(size_in_bytes), const_cast<void *>(host_ptr));
 }