~ubuntu-branches/ubuntu/wily/pyopencl/wily

« back to all changes in this revision

Viewing changes to src/wrapper/wrap_cl.hpp

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-10-22 18:08:41 UTC
  • mfrom: (2.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20131022180841-1lcaecrns774y1ys
Tags: 2013.1+git20130916-1build1
No change rebuild for Boost 1.54 transition.

Show diffs side-by-side

added added

removed removed

Lines of Context:
432
432
        return m_platform;
433
433
      }
434
434
 
435
 
      npy_intp obj_ptr() const
436
 
      {
437
 
        return (npy_intp) data();
438
 
      }
439
 
 
440
435
      PYOPENCL_EQUALITY_TESTS(platform);
441
436
 
442
437
      py::object get_info(cl_platform_info param_name) const
570
565
        return m_device;
571
566
      }
572
567
 
573
 
      npy_intp obj_ptr() const
574
 
      {
575
 
        return (npy_intp) data();
576
 
      }
577
 
 
578
568
      PYOPENCL_EQUALITY_TESTS(device);
579
569
 
580
570
      py::object get_info(cl_device_info param_name) const
720
710
          case CL_DEVICE_PREFERRED_INTEROP_USER_SYNC: DEV_GET_INT_INF(cl_bool);
721
711
          case CL_DEVICE_PRINTF_BUFFER_SIZE: DEV_GET_INT_INF(cl_bool);
722
712
#endif
 
713
// {{{ AMD dev attrs
 
714
//
 
715
// types of AMD dev attrs divined from
 
716
// https://www.khronos.org/registry/cl/api/1.2/cl.hpp
 
717
#ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
 
718
          case CL_DEVICE_PROFILING_TIMER_OFFSET_AMD: DEV_GET_INT_INF(cl_ulong);
 
719
#endif
 
720
/* FIXME
 
721
#ifdef CL_DEVICE_TOPOLOGY_AMD
 
722
          case CL_DEVICE_TOPOLOGY_AMD:
 
723
#endif
 
724
*/
 
725
#ifdef CL_DEVICE_BOARD_NAME_AMD
 
726
          case CL_DEVICE_BOARD_NAME_AMD: ;
 
727
            PYOPENCL_GET_STR_INFO(Device, m_device, param_name);
 
728
#endif
 
729
#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
 
730
          case CL_DEVICE_GLOBAL_FREE_MEMORY_AMD:
 
731
            {
 
732
              std::vector<size_t> result;
 
733
              PYOPENCL_GET_VEC_INFO(Device, m_device, param_name, result);
 
734
              PYOPENCL_RETURN_VECTOR(size_t, result);
 
735
            }
 
736
#endif
 
737
#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
 
738
          case CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD: DEV_GET_INT_INF(cl_uint);
 
739
#endif
 
740
#ifdef CL_DEVICE_SIMD_WIDTH_AMD
 
741
          case CL_DEVICE_SIMD_WIDTH_AMD: DEV_GET_INT_INF(cl_uint);
 
742
#endif
 
743
#ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
 
744
          case CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD: DEV_GET_INT_INF(cl_uint);
 
745
#endif
 
746
#ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
 
747
          case CL_DEVICE_WAVEFRONT_WIDTH_AMD: DEV_GET_INT_INF(cl_uint);
 
748
#endif
 
749
#ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
 
750
          case CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD: DEV_GET_INT_INF(cl_uint);
 
751
#endif
 
752
#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
 
753
          case CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD: DEV_GET_INT_INF(cl_uint);
 
754
#endif
 
755
#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
 
756
          case CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD: DEV_GET_INT_INF(cl_uint);
 
757
#endif
 
758
#ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
 
759
          case CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD: DEV_GET_INT_INF(cl_uint);
 
760
#endif
 
761
#ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
 
762
          case CL_DEVICE_LOCAL_MEM_BANKS_AMD: DEV_GET_INT_INF(cl_uint);
 
763
#endif
 
764
// }}}
 
765
 
 
766
#ifdef CL_DEVICE_MAX_ATOMIC_COUNTERS_EXT
 
767
          case CL_DEVICE_MAX_ATOMIC_COUNTERS_EXT: DEV_GET_INT_INF(cl_uint);
 
768
#endif
723
769
 
724
770
          default:
725
771
            throw error("Device.get_info", CL_INVALID_VALUE);
846
892
        return m_context;
847
893
      }
848
894
 
849
 
      npy_intp obj_ptr() const
850
 
      {
851
 
        return (npy_intp) data();
852
 
      }
853
 
 
854
895
      PYOPENCL_EQUALITY_TESTS(context);
855
896
 
856
897
      py::object get_info(cl_context_info param_name) const
1130
1171
      const cl_command_queue data() const
1131
1172
      { return m_queue; }
1132
1173
 
1133
 
      npy_intp obj_ptr() const
1134
 
      {
1135
 
        return (npy_intp) data();
1136
 
      }
1137
 
 
1138
1174
      PYOPENCL_EQUALITY_TESTS(command_queue);
1139
1175
 
1140
1176
      py::object get_info(cl_command_queue_info param_name) const
1215
1251
      const cl_event data() const
1216
1252
      { return m_event; }
1217
1253
 
1218
 
      npy_intp obj_ptr() const
1219
 
      {
1220
 
        return (npy_intp) data();
1221
 
      }
1222
 
 
1223
1254
      PYOPENCL_EQUALITY_TESTS(event);
1224
1255
 
1225
1256
      py::object get_info(cl_event_info param_name) const
1321
1352
 
1322
1353
 
1323
1354
 
 
1355
#if PYOPENCL_CL_VERSION >= 0x1020
1324
1356
  inline
1325
 
  event *enqueue_marker(command_queue &cq,
 
1357
  event *enqueue_marker_with_wait_list(command_queue &cq,
1326
1358
      py::object py_wait_for)
1327
1359
  {
1328
1360
    PYOPENCL_PARSE_WAIT_FOR;
1329
1361
    cl_event evt;
1330
1362
 
1331
 
#if PYOPENCL_CL_VERSION >= 0x1020
1332
1363
    PYOPENCL_CALL_GUARDED(clEnqueueMarkerWithWaitList, (
1333
1364
          cq.data(), PYOPENCL_WAITLIST_ARGS, &evt));
1334
 
#else
1335
 
    if (num_events_in_wait_list)
1336
 
    {
1337
 
      PYOPENCL_CALL_GUARDED(clEnqueueWaitForEvents, (
1338
 
            cq.data(), PYOPENCL_WAITLIST_ARGS));
1339
 
    }
1340
 
    PYOPENCL_CALL_GUARDED(clEnqueueMarker, (
1341
 
          cq.data(), &evt));
1342
 
#endif
1343
1365
 
1344
1366
    PYOPENCL_RETURN_NEW_EVENT(evt);
1345
1367
  }
1346
1368
 
1347
 
 
1348
 
 
1349
 
 
1350
 
 
1351
1369
  inline
1352
 
  event *enqueue_barrier(command_queue &cq,
 
1370
  event *enqueue_barrier_with_wait_list(command_queue &cq,
1353
1371
      py::object py_wait_for)
1354
1372
  {
1355
1373
    PYOPENCL_PARSE_WAIT_FOR;
1356
1374
    cl_event evt;
1357
1375
 
1358
 
#if PYOPENCL_CL_VERSION >= 0x1020
1359
1376
    PYOPENCL_CALL_GUARDED(clEnqueueBarrierWithWaitList,
1360
1377
        (cq.data(), PYOPENCL_WAITLIST_ARGS, &evt));
1361
1378
 
1362
 
#else
1363
 
    if (num_events_in_wait_list)
1364
 
    {
1365
 
      PYOPENCL_CALL_GUARDED(clEnqueueWaitForEvents, (
1366
 
            cq.data(), PYOPENCL_WAITLIST_ARGS));
1367
 
    }
1368
 
 
1369
 
    PYOPENCL_CALL_GUARDED(clEnqueueBarrier, (cq.data()));
 
1379
    PYOPENCL_RETURN_NEW_EVENT(evt);
 
1380
  }
 
1381
#endif
 
1382
 
 
1383
 
 
1384
  // {{{ used internally for pre-OpenCL-1.2 contexts
 
1385
 
 
1386
  inline
 
1387
  event *enqueue_marker(command_queue &cq)
 
1388
  {
 
1389
    cl_event evt;
1370
1390
 
1371
1391
    PYOPENCL_CALL_GUARDED(clEnqueueMarker, (
1372
1392
          cq.data(), &evt));
1373
 
#endif
1374
1393
 
1375
1394
    PYOPENCL_RETURN_NEW_EVENT(evt);
1376
1395
  }
1377
1396
 
1378
 
 
1379
 
 
1380
 
 
1381
1397
  inline
1382
1398
  void enqueue_wait_for_events(command_queue &cq, py::object py_events)
1383
1399
  {
1384
 
    PYOPENCL_DEPRECATED("enqueue_wait_for_events", "2013.1", );
1385
 
 
1386
1400
    cl_uint num_events = 0;
1387
1401
    std::vector<cl_event> event_list(len(py_events));
1388
1402
 
1394
1408
          cq.data(), num_events, event_list.empty( ) ? NULL : &event_list.front()));
1395
1409
  }
1396
1410
 
 
1411
  inline
 
1412
  void enqueue_barrier(command_queue &cq)
 
1413
  {
 
1414
    PYOPENCL_CALL_GUARDED(clEnqueueBarrier, (cq.data()));
 
1415
  }
1397
1416
 
 
1417
  // }}}
1398
1418
 
1399
1419
 
1400
1420
#if PYOPENCL_CL_VERSION >= 0x1010
1515
1535
      const cl_mem data() const
1516
1536
      { return m_mem; }
1517
1537
 
1518
 
      npy_intp obj_ptr() const
1519
 
      {
1520
 
        return (npy_intp) data();
1521
 
      }
1522
 
 
1523
1538
  };
1524
1539
 
1525
1540
#if PYOPENCL_CL_VERSION >= 0x1020
1793
1808
 
1794
1809
    cl_event evt;
1795
1810
    PYOPENCL_RETRY_IF_MEM_ERROR(
1796
 
      PYOPENCL_CALL_GUARDED(clEnqueueReadBuffer, (
 
1811
      PYOPENCL_CALL_GUARDED_THREADED(clEnqueueReadBuffer, (
1797
1812
            cq.data(),
1798
1813
            mem.data(),
1799
1814
            PYOPENCL_CAST_BOOL(is_blocking),
1826
1841
 
1827
1842
    cl_event evt;
1828
1843
    PYOPENCL_RETRY_IF_MEM_ERROR(
1829
 
      PYOPENCL_CALL_GUARDED(clEnqueueWriteBuffer, (
 
1844
      PYOPENCL_CALL_GUARDED_THREADED(clEnqueueWriteBuffer, (
1830
1845
            cq.data(),
1831
1846
            mem.data(),
1832
1847
            PYOPENCL_CAST_BOOL(is_blocking),
1911
1926
 
1912
1927
    cl_event evt;
1913
1928
    PYOPENCL_RETRY_IF_MEM_ERROR(
1914
 
      PYOPENCL_CALL_GUARDED(clEnqueueReadBufferRect, (
 
1929
      PYOPENCL_CALL_GUARDED_THREADED(clEnqueueReadBufferRect, (
1915
1930
            cq.data(),
1916
1931
            mem.data(),
1917
1932
            PYOPENCL_CAST_BOOL(is_blocking),
1957
1972
 
1958
1973
    cl_event evt;
1959
1974
    PYOPENCL_RETRY_IF_MEM_ERROR(
1960
 
      PYOPENCL_CALL_GUARDED(clEnqueueWriteBufferRect, (
 
1975
      PYOPENCL_CALL_GUARDED_THREADED(clEnqueueWriteBufferRect, (
1961
1976
            cq.data(),
1962
1977
            mem.data(),
1963
1978
            PYOPENCL_CAST_BOOL(is_blocking),
2618
2633
      memory_object_holder &buf,
2619
2634
      cl_map_flags flags,
2620
2635
      size_t offset,
2621
 
      py::object py_shape, py::object dtype, py::object order_py,
 
2636
      py::object py_shape, py::object dtype,
 
2637
      py::object py_order, py::object py_strides,
2622
2638
      py::object py_wait_for,
2623
2639
      bool is_blocking
2624
2640
      )
2639
2655
 
2640
2656
    PYOPENCL_RETRY_IF_MEM_ERROR(
2641
2657
        {
 
2658
          Py_BEGIN_ALLOW_THREADS
2642
2659
          mapped = clEnqueueMapBuffer(
2643
2660
                cq.data(), buf.data(),
2644
2661
                PYOPENCL_CAST_BOOL(is_blocking), flags,
2645
2662
                offset, size_in_bytes,
2646
2663
                PYOPENCL_WAITLIST_ARGS, &evt,
2647
2664
                &status_code);
 
2665
          Py_END_ALLOW_THREADS
2648
2666
          if (status_code != CL_SUCCESS)
2649
2667
            throw pyopencl::error("clEnqueueMapBuffer", status_code);
2650
2668
        } );
2656
2674
    {
2657
2675
      result = py::handle<>(PyArray_NewFromDescr(
2658
2676
          &PyArray_Type, tp_descr,
2659
 
          shape.size(), shape.empty( ) ? NULL : &shape.front(), /*strides*/ NULL,
 
2677
          shape.size(),
 
2678
          shape.empty() ? NULL : &shape.front(),
 
2679
          strides.empty() ? NULL : &strides.front(),
2660
2680
          mapped, ary_flags, /*obj*/NULL));
2661
2681
 
2662
2682
      if (size_in_bytes != (npy_uintp) PyArray_NBYTES(result.get()))
2663
2683
        throw pyopencl::error("enqueue_map_buffer", CL_INVALID_VALUE,
2664
 
            "miscalculated numpy array size");
 
2684
            "miscalculated numpy array size (not contiguous?)");
2665
2685
 
2666
2686
       map = std::auto_ptr<memory_map>(new memory_map(cq, buf, mapped));
2667
2687
    }
2691
2711
      cl_map_flags flags,
2692
2712
      py::object py_origin,
2693
2713
      py::object py_region,
2694
 
      py::object py_shape, py::object dtype, py::object order_py,
 
2714
      py::object py_shape, py::object dtype,
 
2715
      py::object py_order, py::object py_strides,
2695
2716
      py::object py_wait_for,
2696
2717
      bool is_blocking
2697
2718
      )
2708
2729
    void *mapped;
2709
2730
    PYOPENCL_RETRY_IF_MEM_ERROR(
2710
2731
      {
 
2732
        Py_BEGIN_ALLOW_THREADS
2711
2733
        mapped = clEnqueueMapImage(
2712
2734
              cq.data(), img.data(),
2713
2735
              PYOPENCL_CAST_BOOL(is_blocking), flags,
2714
2736
              origin, region, &row_pitch, &slice_pitch,
2715
2737
              PYOPENCL_WAITLIST_ARGS, &evt,
2716
2738
              &status_code);
 
2739
        Py_END_ALLOW_THREADS
2717
2740
        if (status_code != CL_SUCCESS)
2718
2741
          throw pyopencl::error("clEnqueueMapImage", status_code);
2719
2742
      } );
2734
2757
 
2735
2758
    py::handle<> result = py::handle<>(PyArray_NewFromDescr(
2736
2759
        &PyArray_Type, tp_descr,
2737
 
        shape.size(), shape.empty( ) ? NULL : &shape.front(), /*strides*/ NULL,
 
2760
        shape.size(),
 
2761
        shape.empty() ? NULL : &shape.front(),
 
2762
        strides.empty() ? NULL : &strides.front(),
2738
2763
        mapped, ary_flags, /*obj*/NULL));
2739
2764
 
2740
2765
    py::handle<> map_py(handle_from_new_ptr(map.release()));
2770
2795
          throw pyopencl::error("Sampler", status_code);
2771
2796
      }
2772
2797
 
 
2798
      sampler(cl_sampler samp, bool retain)
 
2799
        : m_sampler(samp)
 
2800
      {
 
2801
        if (retain)
 
2802
          PYOPENCL_CALL_GUARDED(clRetainSampler, (samp));
 
2803
      }
 
2804
 
2773
2805
      ~sampler()
2774
2806
      {
2775
2807
        PYOPENCL_CALL_GUARDED_CLEANUP(clReleaseSampler, (m_sampler));
2780
2812
        return m_sampler;
2781
2813
      }
2782
2814
 
2783
 
      npy_intp obj_ptr() const
2784
 
      {
2785
 
        return (npy_intp) data();
2786
 
      }
2787
 
 
2788
2815
      PYOPENCL_EQUALITY_TESTS(sampler);
2789
2816
 
2790
2817
      py::object get_info(cl_sampler_info param_name) const
2849
2876
        return m_program_kind;
2850
2877
      }
2851
2878
 
2852
 
      npy_intp obj_ptr() const
2853
 
      {
2854
 
        return (npy_intp) data();
2855
 
      }
2856
 
 
2857
2879
      PYOPENCL_EQUALITY_TESTS(program);
2858
2880
 
2859
2881
      py::object get_info(cl_program_info param_name) const
3254
3276
        return m_kernel;
3255
3277
      }
3256
3278
 
3257
 
      npy_intp obj_ptr() const
3258
 
      {
3259
 
        return (npy_intp) data();
3260
 
      }
3261
 
 
3262
3279
      PYOPENCL_EQUALITY_TESTS(kernel);
3263
3280
 
3264
3281
      void set_arg_null(cl_uint arg_index)
3828
3845
 
3829
3846
  // {{{ deferred implementation bits
3830
3847
 
3831
 
  inline py::object create_event_wrapper_from_int(intptr_t cl_event_as_int)
3832
 
  {
3833
 
    return py::object(handle_from_new_ptr(new event((cl_event)cl_event_as_int, true)));
3834
 
  }
3835
 
 
3836
3848
  inline py::object create_mem_object_wrapper(cl_mem mem)
3837
3849
  {
3838
3850
    cl_mem_object_type mem_obj_type;