ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/OpenCL/OpenCL.xs
(Generate patch)

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.68 by root, Fri May 4 14:56:50 2012 UTC vs.
Revision 1.70 by root, Sat May 5 02:33:55 2012 UTC

153 } 153 }
154 154
155 return buf [idx]; 155 return buf [idx];
156} 156}
157 157
158static const char * ecb_noinline
159cv_get_name (CV *cv)
160{
161 static char fullname [256];
162
163 GV *gv = CvGV (cv); // gv better be nonzero
164
165 HV *stash = GvSTASH (gv);
166 const char *hvname = HvNAME_get (stash); // stash also better be nonzero
167 const char *gvname = GvNAME (gv);
168
169 snprintf (fullname, sizeof (fullname), "%s::%s", hvname, gvname);
170 return fullname;
171}
172
158/*****************************************************************************/ 173/*****************************************************************************/
159 174
160typedef struct 175typedef struct
161{ 176{
162 IV iv; 177 IV iv;
320 335
321 return p; 336 return p;
322 } 337 }
323 338
324 croak ("%s: %s is not a property list (either undef or [type => value, ...])", func, svname); 339 croak ("%s: %s is not a property list (either undef or [type => value, ...])", func, svname);
340}
341
342static void * ecb_noinline
343object_list (CV *cv, int or_undef, const char *argname, SV *arg, const char *klass, cl_uint *rcount)
344{
345 const char *funcname = cv_get_name (cv);
346
347 if (!SvROK (arg) || SvTYPE (SvRV (arg)) != SVt_PVAV)
348 croak ("%s: '%s' parameter must be %sa reference to an array of %s objects",
349 funcname, argname, or_undef ? "undef or " : "", klass);
350
351 AV *av = (AV *)SvRV (arg);
352 void **list = 0;
353 cl_uint count = av_len (av) + 1;
354
355 if (count)
356 {
357 list = tmpbuf (sizeof (*list) * count);
358 int i;
359 for (i = 0; i < count; ++i)
360 list [i] = SvCLOBJ (funcname, argname, *av_fetch (av, i, 1), klass);
361 }
362
363 if (!count && !or_undef)
364 croak ("%s: '%s' must contain at least one %s object",
365 funcname, argname, klass);
366
367 *rcount = count;
368 return (void *)list;
325} 369}
326 370
327/*****************************************************************************/ 371/*****************************************************************************/
328/* callback stuff */ 372/* callback stuff */
329 373
489static eq_vtbl eq_program_vtbl = { 1, eq_program_push }; 533static eq_vtbl eq_program_vtbl = { 1, eq_program_push };
490 534
491static void CL_CALLBACK 535static void CL_CALLBACK
492eq_program_notify (cl_program program, void *user_data) 536eq_program_notify (cl_program program, void *user_data)
493{ 537{
538 clRetainProgram (program);
539
494 eq_enq (&eq_program_vtbl, user_data, (void *)program, 0, 0); 540 eq_enq (&eq_program_vtbl, user_data, (void *)program, 0, 0);
541}
542
543typedef void (CL_CALLBACK *program_callback)(cl_program program, void *user_data);
544
545static program_callback ecb_noinline
546make_program_callback (SV *notify, void **ruser_data)
547{
548 if (SvOK (notify))
549 {
550 *ruser_data = SvREFCNT_inc (s_get_cv (notify));
551 return eq_program_notify;
552 }
553 else
554 {
555 *ruser_data = 0;
556 return 0;
557 }
495} 558}
496 559
497struct build_args 560struct build_args
498{ 561{
499 cl_program program; 562 cl_program program;
863 PUSH_CLOBJ (stash_device, list [i]); 926 PUSH_CLOBJ (stash_device, list [i]);
864 927
865void 928void
866context (OpenCL::Platform self, SV *properties = 0, SV *devices, SV *notify = &PL_sv_undef) 929context (OpenCL::Platform self, SV *properties = 0, SV *devices, SV *notify = &PL_sv_undef)
867 PPCODE: 930 PPCODE:
868 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV)
869 croak ("OpenCL::Platform::context argument 'device' must be an arrayref with device objects, in call");
870
871 cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self }; 931 cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self };
872 cl_context_properties *props = SvCONTEXTPROPERTIES ("OpenCL::Platform::context", "properties", properties, extra, 2); 932 cl_context_properties *props = SvCONTEXTPROPERTIES ("OpenCL::Platform::context", "properties", properties, extra, 2);
873 933
874 AV *av = (AV *)SvRV (devices); 934 cl_uint device_count = 0;
875 cl_uint num_devices = av_len (av) + 1; 935 cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count);
876 cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices);
877
878 int i;
879 for (i = num_devices; i--; )
880 device_list [i] = SvCLOBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device");
881 936
882 CONTEXT_NOTIFY_CALLBACK; 937 CONTEXT_NOTIFY_CALLBACK;
883 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (props, num_devices, device_list, pfn_notify, user_data, &res)); 938 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (props, device_count, device_list, pfn_notify, user_data, &res));
884 XPUSH_CLOBJ_CONTEXT; 939 XPUSH_CLOBJ_CONTEXT;
885 940
886void 941void
887context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, SV *notify = &PL_sv_undef) 942context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, SV *notify = &PL_sv_undef)
888 PPCODE: 943 PPCODE:
1365 XPUSH_CLOBJ (stash_program, prog); 1420 XPUSH_CLOBJ (stash_program, prog);
1366 1421
1367void 1422void
1368program_with_binary (OpenCL::Context self, SV *devices, SV *binaries) 1423program_with_binary (OpenCL::Context self, SV *devices, SV *binaries)
1369 PPCODE: 1424 PPCODE:
1370 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) 1425 cl_uint device_count;
1371 croak ("OpenCL::Context::program_with_binary: devices must be specified as reference to an array of device objects"); 1426 cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count);
1372
1373 devices = SvRV (devices);
1374 1427
1375 if (!SvROK (binaries) || SvTYPE (SvRV (binaries)) != SVt_PVAV) 1428 if (!SvROK (binaries) || SvTYPE (SvRV (binaries)) != SVt_PVAV)
1376 croak ("OpenCL::Context::program_with_binary: binaries must be specified as reference to an array of strings"); 1429 croak ("OpenCL::Context::program_with_binary: binaries must be specified as reference to an array of strings");
1377 1430
1378 binaries = SvRV (binaries); 1431 binaries = SvRV (binaries);
1379 1432
1380 if (av_len ((AV *)devices) != av_len ((AV *)binaries)) 1433 if (device_count != av_len ((AV *)binaries) + 1)
1381 croak ("OpenCL::Context::program_with_binary: differing numbers of devices and binaries are not allowed"); 1434 croak ("OpenCL::Context::program_with_binary: differing numbers of devices and binaries are not allowed");
1382 1435
1383 int count = av_len ((AV *)devices) + 1;
1384 cl_device_id *device_list = tmpbuf (sizeof (*device_list) * count);
1385 size_t *length_list = tmpbuf (sizeof (*length_list) * count); 1436 size_t *length_list = tmpbuf (sizeof (*length_list) * device_count);
1386 const unsigned char **binary_list = tmpbuf (sizeof (*binary_list) * count); 1437 const unsigned char **binary_list = tmpbuf (sizeof (*binary_list) * device_count);
1387 cl_int *status_list = tmpbuf (sizeof (*status_list) * count); 1438 cl_int *status_list = tmpbuf (sizeof (*status_list) * device_count);
1388 1439
1389 int i; 1440 int i;
1390 for (i = 0; i < count; ++i) 1441 for (i = 0; i < device_count; ++i)
1391 { 1442 {
1392 device_list [i] = SvCLOBJ ("OpenCL::Context::program_with_binary", "devices", *av_fetch ((AV *)devices, i, 0), "OpenCL::Device");
1393 STRLEN len; 1443 STRLEN len;
1394 binary_list [i] = (const unsigned char *)SvPVbyte (*av_fetch ((AV *)binaries, i, 0), len); 1444 binary_list [i] = (const unsigned char *)SvPVbyte (*av_fetch ((AV *)binaries, i, 0), len);
1395 length_list [i] = len; 1445 length_list [i] = len;
1396 } 1446 }
1397 1447
1398 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithBinary, (self, count, device_list, length_list, binary_list, GIMME_V == G_ARRAY ? status_list : 0, &res)); 1448 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithBinary, (self, device_count, device_list,
1449 length_list, binary_list,
1450 GIMME_V == G_ARRAY ? status_list : 0, &res));
1399 1451
1400 EXTEND (SP, 2); 1452 EXTEND (SP, 2);
1401 PUSH_CLOBJ (stash_program, prog); 1453 PUSH_CLOBJ (stash_program, prog);
1402 1454
1403 if (GIMME_V == G_ARRAY) 1455 if (GIMME_V == G_ARRAY)
1404 { 1456 {
1405 AV *av = newAV (); 1457 AV *av = newAV ();
1406 PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); 1458 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
1407 1459
1408 for (i = count; i--; ) 1460 for (i = device_count; i--; )
1409 av_store (av, i, newSViv (status_list [i])); 1461 av_store (av, i, newSViv (status_list [i]));
1410 } 1462 }
1411 1463
1412#if CL_VERSION_1_2 1464#if CL_VERSION_1_2
1413 1465
1414void 1466void
1415program_with_built_in_kernels (OpenCL::Context self, SV *devices, SV *kernel_names) 1467program_with_built_in_kernels (OpenCL::Context self, SV *devices, SV *kernel_names)
1416 PPCODE: 1468 PPCODE:
1417 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) 1469 cl_uint device_count = 0;
1418 croak ("OpenCL::Context::program_with_built_in_kernels: devices must be specified as reference to an array of device objects"); 1470 cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count);
1419 1471
1420 devices = SvRV (devices);
1421
1422 int count = av_len ((AV *)devices) + 1;
1423 cl_device_id *device_list = tmpbuf (sizeof (*device_list) * count);
1424
1425 int i;
1426 for (i = 0; i < count; ++i)
1427 device_list [i] = SvCLOBJ ("OpenCL::Context::program_with_built_in_kernels", "devices", *av_fetch ((AV *)devices, i, 0), "OpenCL::Device");
1428
1429 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithBuiltInKernels, (self, count, device_list, SvPVbyte_nolen (kernel_names), &res)); 1472 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithBuiltInKernels, (self, device_count, device_list, SvPVbyte_nolen (kernel_names), &res));
1473
1474 XPUSH_CLOBJ (stash_program, prog);
1475
1476void
1477link_program (OpenCL::Context self, SV *devices, SV *options, SV *programs, SV *notify = &PL_sv_undef)
1478 CODE:
1479 cl_uint device_count = 0;
1480 cl_device_id *device_list = 0;
1481
1482 if (SvOK (devices))
1483 device_list = object_list (cv, 1, "devices", devices, "OpenCL::Device", &device_count);
1484
1485 cl_uint program_count;
1486 cl_program *program_list = object_list (cv, 0, "programs", programs, "OpenCL::Program", &program_count);
1487
1488 void *user_data;
1489 program_callback pfn_notify = make_program_callback (notify, &user_data);
1490
1491 NEED_SUCCESS_ARG (cl_program prog, LinkProgram, (self, device_count, device_list, SvPVbyte_nolen (options),
1492 program_count, program_list, pfn_notify, user_data, &res));
1430 1493
1431 XPUSH_CLOBJ (stash_program, prog); 1494 XPUSH_CLOBJ (stash_program, prog);
1432 1495
1433#endif 1496#endif
1434 1497
1484void 1547void
1485read_buffer (OpenCL::Queue self, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...) 1548read_buffer (OpenCL::Queue self, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...)
1486 ALIAS: 1549 ALIAS:
1487 enqueue_read_buffer = 0 1550 enqueue_read_buffer = 0
1488 PPCODE: 1551 PPCODE:
1489 cl_event ev = 0;
1490 EVENT_LIST (6); 1552 EVENT_LIST (6);
1491 1553
1492 SvUPGRADE (data, SVt_PV); 1554 SvUPGRADE (data, SVt_PV);
1493 SvGROW (data, len); 1555 SvGROW (data, len);
1494 SvPOK_only (data); 1556 SvPOK_only (data);
1495 SvCUR_set (data, len); 1557 SvCUR_set (data, len);
1558
1559 cl_event ev = 0;
1496 NEED_SUCCESS (EnqueueReadBuffer, (self, mem, blocking, offset, len, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1560 NEED_SUCCESS (EnqueueReadBuffer, (self, mem, blocking, offset, len, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1497 1561
1498 if (ev) 1562 if (ev)
1499 XPUSH_CLOBJ (stash_event, ev); 1563 XPUSH_CLOBJ (stash_event, ev);
1500 1564
1501void 1565void
1502write_buffer (OpenCL::Queue self, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...) 1566write_buffer (OpenCL::Queue self, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...)
1503 ALIAS: 1567 ALIAS:
1504 enqueue_write_buffer = 0 1568 enqueue_write_buffer = 0
1505 PPCODE: 1569 PPCODE:
1506 cl_event ev = 0; 1570 EVENT_LIST (5);
1571
1507 STRLEN len; 1572 STRLEN len;
1508 char *ptr = SvPVbyte (data, len); 1573 char *ptr = SvPVbyte (data, len);
1509 EVENT_LIST (5);
1510 1574
1575 cl_event ev = 0;
1511 NEED_SUCCESS (EnqueueWriteBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1576 NEED_SUCCESS (EnqueueWriteBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1512 1577
1513 if (ev) 1578 if (ev)
1514 XPUSH_CLOBJ (stash_event, ev); 1579 XPUSH_CLOBJ (stash_event, ev);
1515 1580
1518void 1583void
1519fill_buffer (OpenCL::Queue self, OpenCL::Buffer mem, SV *data, size_t offset, size_t size, ...) 1584fill_buffer (OpenCL::Queue self, OpenCL::Buffer mem, SV *data, size_t offset, size_t size, ...)
1520 ALIAS: 1585 ALIAS:
1521 enqueue_fill_buffer = 0 1586 enqueue_fill_buffer = 0
1522 PPCODE: 1587 PPCODE:
1523 cl_event ev = 0; 1588 EVENT_LIST (5);
1589
1524 STRLEN len; 1590 STRLEN len;
1525 char *ptr = SvPVbyte (data, len); 1591 char *ptr = SvPVbyte (data, len);
1526 EVENT_LIST (5);
1527 1592
1593 cl_event ev = 0;
1528 NEED_SUCCESS (EnqueueFillBuffer, (self, mem, ptr, len, offset, size, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1594 NEED_SUCCESS (EnqueueFillBuffer, (self, mem, ptr, len, offset, size, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1529 1595
1530 if (ev) 1596 if (ev)
1531 XPUSH_CLOBJ (stash_event, ev); 1597 XPUSH_CLOBJ (stash_event, ev);
1532 1598
1533void 1599void
1534fill_image (OpenCL::Queue self, OpenCL::Image img, NV r, NV g, NV b, NV a, size_t x, size_t y, size_t z, size_t width, size_t height, size_t depth, ...) 1600fill_image (OpenCL::Queue self, OpenCL::Image img, NV r, NV g, NV b, NV a, size_t x, size_t y, size_t z, size_t width, size_t height, size_t depth, ...)
1535 ALIAS: 1601 ALIAS:
1536 enqueue_fill_image = 0 1602 enqueue_fill_image = 0
1537 PPCODE: 1603 PPCODE:
1538 cl_event ev = 0; 1604 EVENT_LIST (12);
1605
1539 const size_t origin [3] = { x, y, z }; 1606 const size_t origin [3] = { x, y, z };
1540 const size_t region [3] = { width, height, depth }; 1607 const size_t region [3] = { width, height, depth };
1541 EVENT_LIST (12);
1542 1608
1543 const cl_float c_f [4] = { r, g, b, a }; 1609 const cl_float c_f [4] = { r, g, b, a };
1544 const cl_uint c_u [4] = { r, g, b, a }; 1610 const cl_uint c_u [4] = { r, g, b, a };
1545 const cl_int c_s [4] = { r, g, b, a }; 1611 const cl_int c_s [4] = { r, g, b, a };
1546 const void *c_fus [3] = { &c_f, &c_u, &c_s }; 1612 const void *c_fus [3] = { &c_f, &c_u, &c_s };
1549 NEED_SUCCESS (GetImageInfo, (img, CL_IMAGE_FORMAT, sizeof (format), &format, 0)); 1615 NEED_SUCCESS (GetImageInfo, (img, CL_IMAGE_FORMAT, sizeof (format), &format, 0));
1550 assert (sizeof (fus) == CL_FLOAT + 1 - CL_SNORM_INT8); 1616 assert (sizeof (fus) == CL_FLOAT + 1 - CL_SNORM_INT8);
1551 if (format.image_channel_data_type < CL_SNORM_INT8 || CL_FLOAT < format.image_channel_data_type) 1617 if (format.image_channel_data_type < CL_SNORM_INT8 || CL_FLOAT < format.image_channel_data_type)
1552 croak ("enqueue_fill_image: image has unsupported channel type, only opencl 1.2 channel types supported."); 1618 croak ("enqueue_fill_image: image has unsupported channel type, only opencl 1.2 channel types supported.");
1553 1619
1620 cl_event ev = 0;
1554 NEED_SUCCESS (EnqueueFillImage, (self, img, c_fus [fus [format.image_channel_data_type - CL_SNORM_INT8]], 1621 NEED_SUCCESS (EnqueueFillImage, (self, img, c_fus [fus [format.image_channel_data_type - CL_SNORM_INT8]],
1555 origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1622 origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1556 1623
1557 if (ev) 1624 if (ev)
1558 XPUSH_CLOBJ (stash_event, ev); 1625 XPUSH_CLOBJ (stash_event, ev);
1562void 1629void
1563copy_buffer (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...) 1630copy_buffer (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...)
1564 ALIAS: 1631 ALIAS:
1565 enqueue_copy_buffer = 0 1632 enqueue_copy_buffer = 0
1566 PPCODE: 1633 PPCODE:
1634 EVENT_LIST (6);
1635
1567 cl_event ev = 0; 1636 cl_event ev = 0;
1568 EVENT_LIST (6);
1569
1570 NEED_SUCCESS (EnqueueCopyBuffer, (self, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1637 NEED_SUCCESS (EnqueueCopyBuffer, (self, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1571 1638
1572 if (ev) 1639 if (ev)
1573 XPUSH_CLOBJ (stash_event, ev); 1640 XPUSH_CLOBJ (stash_event, ev);
1574 1641
1575void 1642void
1576read_buffer_rect (OpenCL::Queue self, OpenCL::Memory buf, cl_bool blocking, size_t buf_x, size_t buf_y, size_t buf_z, size_t host_x, size_t host_y, size_t host_z, size_t width, size_t height, size_t depth, size_t buf_row_pitch, size_t buf_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, SV *data, ...) 1643read_buffer_rect (OpenCL::Queue self, OpenCL::Memory buf, cl_bool blocking, size_t buf_x, size_t buf_y, size_t buf_z, size_t host_x, size_t host_y, size_t host_z, size_t width, size_t height, size_t depth, size_t buf_row_pitch, size_t buf_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, SV *data, ...)
1577 ALIAS: 1644 ALIAS:
1578 enqueue_read_buffer_rect = 0 1645 enqueue_read_buffer_rect = 0
1579 PPCODE: 1646 PPCODE:
1580 cl_event ev = 0; 1647 EVENT_LIST (17);
1648
1581 const size_t buf_origin [3] = { buf_x , buf_y , buf_z }; 1649 const size_t buf_origin [3] = { buf_x , buf_y , buf_z };
1582 const size_t host_origin[3] = { host_x, host_y, host_z }; 1650 const size_t host_origin[3] = { host_x, host_y, host_z };
1583 const size_t region[3] = { width, height, depth }; 1651 const size_t region[3] = { width, height, depth };
1584 EVENT_LIST (17);
1585 1652
1586 if (!buf_row_pitch) 1653 if (!buf_row_pitch)
1587 buf_row_pitch = region [0]; 1654 buf_row_pitch = region [0];
1588 1655
1589 if (!buf_slice_pitch) 1656 if (!buf_slice_pitch)
1599 1666
1600 SvUPGRADE (data, SVt_PV); 1667 SvUPGRADE (data, SVt_PV);
1601 SvGROW (data, len); 1668 SvGROW (data, len);
1602 SvPOK_only (data); 1669 SvPOK_only (data);
1603 SvCUR_set (data, len); 1670 SvCUR_set (data, len);
1671
1672 cl_event ev = 0;
1604 NEED_SUCCESS (EnqueueReadBufferRect, (self, buf, blocking, buf_origin, host_origin, region, buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1673 NEED_SUCCESS (EnqueueReadBufferRect, (self, buf, blocking, buf_origin, host_origin, region, buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1605 1674
1606 if (ev) 1675 if (ev)
1607 XPUSH_CLOBJ (stash_event, ev); 1676 XPUSH_CLOBJ (stash_event, ev);
1608 1677
1609void 1678void
1610write_buffer_rect (OpenCL::Queue self, OpenCL::Memory buf, cl_bool blocking, size_t buf_x, size_t buf_y, size_t buf_z, size_t host_x, size_t host_y, size_t host_z, size_t width, size_t height, size_t depth, size_t buf_row_pitch, size_t buf_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, SV *data, ...) 1679write_buffer_rect (OpenCL::Queue self, OpenCL::Memory buf, cl_bool blocking, size_t buf_x, size_t buf_y, size_t buf_z, size_t host_x, size_t host_y, size_t host_z, size_t width, size_t height, size_t depth, size_t buf_row_pitch, size_t buf_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, SV *data, ...)
1611 ALIAS: 1680 ALIAS:
1612 enqueue_write_buffer_rect = 0 1681 enqueue_write_buffer_rect = 0
1613 PPCODE: 1682 PPCODE:
1614 cl_event ev = 0; 1683 EVENT_LIST (17);
1684
1615 const size_t buf_origin [3] = { buf_x , buf_y , buf_z }; 1685 const size_t buf_origin [3] = { buf_x , buf_y , buf_z };
1616 const size_t host_origin[3] = { host_x, host_y, host_z }; 1686 const size_t host_origin[3] = { host_x, host_y, host_z };
1617 const size_t region[3] = { width, height, depth }; 1687 const size_t region[3] = { width, height, depth };
1618 STRLEN len; 1688 STRLEN len;
1619 char *ptr = SvPVbyte (data, len); 1689 char *ptr = SvPVbyte (data, len);
1620 EVENT_LIST (17);
1621 1690
1622 if (!buf_row_pitch) 1691 if (!buf_row_pitch)
1623 buf_row_pitch = region [0]; 1692 buf_row_pitch = region [0];
1624 1693
1625 if (!buf_slice_pitch) 1694 if (!buf_slice_pitch)
1634 size_t min_len = host_row_pitch * host_slice_pitch * region [2]; 1703 size_t min_len = host_row_pitch * host_slice_pitch * region [2];
1635 1704
1636 if (len < min_len) 1705 if (len < min_len)
1637 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 1706 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
1638 1707
1708 cl_event ev = 0;
1639 NEED_SUCCESS (EnqueueWriteBufferRect, (self, buf, blocking, buf_origin, host_origin, region, buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1709 NEED_SUCCESS (EnqueueWriteBufferRect, (self, buf, blocking, buf_origin, host_origin, region, buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1640 1710
1641 if (ev) 1711 if (ev)
1642 XPUSH_CLOBJ (stash_event, ev); 1712 XPUSH_CLOBJ (stash_event, ev);
1643 1713
1644void 1714void
1645copy_buffer_rect (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch, size_t dst_slice_pitch, ...) 1715copy_buffer_rect (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch, size_t dst_slice_pitch, ...)
1646 ALIAS: 1716 ALIAS:
1647 enqueue_copy_buffer_rect = 0 1717 enqueue_copy_buffer_rect = 0
1648 PPCODE: 1718 PPCODE:
1649 cl_event ev = 0; 1719 EVENT_LIST (16);
1720
1650 const size_t src_origin[3] = { src_x, src_y, src_z }; 1721 const size_t src_origin[3] = { src_x, src_y, src_z };
1651 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 1722 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
1652 const size_t region[3] = { width, height, depth }; 1723 const size_t region[3] = { width, height, depth };
1653 EVENT_LIST (16);
1654 1724
1725 cl_event ev = 0;
1655 NEED_SUCCESS (EnqueueCopyBufferRect, (self, src, dst, src_origin, dst_origin, region, src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1726 NEED_SUCCESS (EnqueueCopyBufferRect, (self, src, dst, src_origin, dst_origin, region, src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1656 1727
1657 if (ev) 1728 if (ev)
1658 XPUSH_CLOBJ (stash_event, ev); 1729 XPUSH_CLOBJ (stash_event, ev);
1659 1730
1660void 1731void
1661read_image (OpenCL::Queue self, OpenCL::Image src, cl_bool blocking, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...) 1732read_image (OpenCL::Queue self, OpenCL::Image src, cl_bool blocking, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...)
1662 ALIAS: 1733 ALIAS:
1663 enqueue_read_image = 0 1734 enqueue_read_image = 0
1664 PPCODE: 1735 PPCODE:
1665 cl_event ev = 0; 1736 EVENT_LIST (12);
1737
1666 const size_t src_origin[3] = { src_x, src_y, src_z }; 1738 const size_t src_origin[3] = { src_x, src_y, src_z };
1667 const size_t region[3] = { width, height, depth }; 1739 const size_t region[3] = { width, height, depth };
1668 EVENT_LIST (12);
1669 1740
1670 if (!row_pitch) 1741 if (!row_pitch)
1671 row_pitch = img_row_pitch (src); 1742 row_pitch = img_row_pitch (src);
1672 1743
1673 if (depth > 1 && !slice_pitch) 1744 if (depth > 1 && !slice_pitch)
1677 1748
1678 SvUPGRADE (data, SVt_PV); 1749 SvUPGRADE (data, SVt_PV);
1679 SvGROW (data, len); 1750 SvGROW (data, len);
1680 SvPOK_only (data); 1751 SvPOK_only (data);
1681 SvCUR_set (data, len); 1752 SvCUR_set (data, len);
1753
1754 cl_event ev = 0;
1682 NEED_SUCCESS (EnqueueReadImage, (self, src, blocking, src_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1755 NEED_SUCCESS (EnqueueReadImage, (self, src, blocking, src_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1683 1756
1684 if (ev) 1757 if (ev)
1685 XPUSH_CLOBJ (stash_event, ev); 1758 XPUSH_CLOBJ (stash_event, ev);
1686 1759
1687void 1760void
1688write_image (OpenCL::Queue self, OpenCL::Image dst, cl_bool blocking, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...) 1761write_image (OpenCL::Queue self, OpenCL::Image dst, cl_bool blocking, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...)
1689 ALIAS: 1762 ALIAS:
1690 enqueue_write_image = 0 1763 enqueue_write_image = 0
1691 PPCODE: 1764 PPCODE:
1692 cl_event ev = 0; 1765 EVENT_LIST (12);
1766
1693 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 1767 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
1694 const size_t region[3] = { width, height, depth }; 1768 const size_t region[3] = { width, height, depth };
1695 STRLEN len; 1769 STRLEN len;
1696 char *ptr = SvPVbyte (data, len); 1770 char *ptr = SvPVbyte (data, len);
1697 EVENT_LIST (12);
1698 1771
1699 if (!row_pitch) 1772 if (!row_pitch)
1700 row_pitch = img_row_pitch (dst); 1773 row_pitch = img_row_pitch (dst);
1701 1774
1702 if (depth > 1 && !slice_pitch) 1775 if (depth > 1 && !slice_pitch)
1705 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height; 1778 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height;
1706 1779
1707 if (len < min_len) 1780 if (len < min_len)
1708 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 1781 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
1709 1782
1783 cl_event ev = 0;
1710 NEED_SUCCESS (EnqueueWriteImage, (self, dst, blocking, dst_origin, region, row_pitch, slice_pitch, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1784 NEED_SUCCESS (EnqueueWriteImage, (self, dst, blocking, dst_origin, region, row_pitch, slice_pitch, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1711 1785
1712 if (ev) 1786 if (ev)
1713 XPUSH_CLOBJ (stash_event, ev); 1787 XPUSH_CLOBJ (stash_event, ev);
1714 1788
1715void 1789void
1716copy_image (OpenCL::Queue self, OpenCL::Image src, OpenCL::Image dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...) 1790copy_image (OpenCL::Queue self, OpenCL::Image src, OpenCL::Image dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...)
1717 ALIAS: 1791 ALIAS:
1718 enqueue_copy_image = 0 1792 enqueue_copy_image = 0
1719 PPCODE: 1793 PPCODE:
1720 cl_event ev = 0; 1794 EVENT_LIST (12);
1795
1721 const size_t src_origin[3] = { src_x, src_y, src_z }; 1796 const size_t src_origin[3] = { src_x, src_y, src_z };
1722 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 1797 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
1723 const size_t region[3] = { width, height, depth }; 1798 const size_t region[3] = { width, height, depth };
1724 EVENT_LIST (12);
1725 1799
1800 cl_event ev = 0;
1726 NEED_SUCCESS (EnqueueCopyImage, (self, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1801 NEED_SUCCESS (EnqueueCopyImage, (self, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1727 1802
1728 if (ev) 1803 if (ev)
1729 XPUSH_CLOBJ (stash_event, ev); 1804 XPUSH_CLOBJ (stash_event, ev);
1730 1805
1731void 1806void
1732copy_image_to_buffer (OpenCL::Queue self, OpenCL::Image src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t dst_offset, ...) 1807copy_image_to_buffer (OpenCL::Queue self, OpenCL::Image src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t dst_offset, ...)
1733 ALIAS: 1808 ALIAS:
1734 enqueue_copy_image_to_buffer = 0 1809 enqueue_copy_image_to_buffer = 0
1735 PPCODE: 1810 PPCODE:
1736 cl_event ev = 0; 1811 EVENT_LIST (10);
1812
1737 const size_t src_origin[3] = { src_x, src_y, src_z }; 1813 const size_t src_origin[3] = { src_x, src_y, src_z };
1738 const size_t region [3] = { width, height, depth }; 1814 const size_t region [3] = { width, height, depth };
1739 EVENT_LIST (10);
1740 1815
1816 cl_event ev = 0;
1741 NEED_SUCCESS (EnqueueCopyImageToBuffer, (self, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1817 NEED_SUCCESS (EnqueueCopyImageToBuffer, (self, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1742 1818
1743 if (ev) 1819 if (ev)
1744 XPUSH_CLOBJ (stash_event, ev); 1820 XPUSH_CLOBJ (stash_event, ev);
1745 1821
1746void 1822void
1747copy_buffer_to_image (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Image dst, size_t src_offset, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...) 1823copy_buffer_to_image (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Image dst, size_t src_offset, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...)
1748 ALIAS: 1824 ALIAS:
1749 enqueue_copy_buffer_to_image = 0 1825 enqueue_copy_buffer_to_image = 0
1750 PPCODE: 1826 PPCODE:
1751 cl_event ev = 0; 1827 EVENT_LIST (10);
1828
1752 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 1829 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
1753 const size_t region [3] = { width, height, depth }; 1830 const size_t region [3] = { width, height, depth };
1754 EVENT_LIST (10);
1755 1831
1832 cl_event ev = 0;
1756 NEED_SUCCESS (EnqueueCopyBufferToImage, (self, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1833 NEED_SUCCESS (EnqueueCopyBufferToImage, (self, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1757 1834
1758 if (ev) 1835 if (ev)
1759 XPUSH_CLOBJ (stash_event, ev); 1836 XPUSH_CLOBJ (stash_event, ev);
1760 1837
1761void 1838void
1762map_buffer (OpenCL::Queue self, OpenCL::Buffer buf, cl_bool blocking = 1, cl_map_flags map_flags = CL_MAP_READ | CL_MAP_WRITE, size_t offset = 0, SV *cb_ = &PL_sv_undef, ...) 1839map_buffer (OpenCL::Queue self, OpenCL::Buffer buf, cl_bool blocking = 1, cl_map_flags map_flags = CL_MAP_READ | CL_MAP_WRITE, size_t offset = 0, SV *cb_ = &PL_sv_undef, ...)
1763 ALIAS: 1840 ALIAS:
1764 enqueue_map_buffer = 0 1841 enqueue_map_buffer = 0
1765 PPCODE: 1842 PPCODE:
1766 cl_event ev;
1767 EVENT_LIST (6); 1843 EVENT_LIST (6);
1844
1768 size_t cb = SvIV (cb_); 1845 size_t cb = SvIV (cb_);
1769 1846
1770 if (!SvOK (cb_)) 1847 if (!SvOK (cb_))
1771 { 1848 {
1772 NEED_SUCCESS (GetMemObjectInfo, (buf, CL_MEM_SIZE, sizeof (cb), &cb, 0)); 1849 NEED_SUCCESS (GetMemObjectInfo, (buf, CL_MEM_SIZE, sizeof (cb), &cb, 0));
1773 cb -= offset; 1850 cb -= offset;
1774 } 1851 }
1775 1852
1853 cl_event ev;
1776 NEED_SUCCESS_ARG (void *ptr, EnqueueMapBuffer, (self, buf, blocking, map_flags, offset, cb, event_list_count, event_list_ptr, &ev, &res)); 1854 NEED_SUCCESS_ARG (void *ptr, EnqueueMapBuffer, (self, buf, blocking, map_flags, offset, cb, event_list_count, event_list_ptr, &ev, &res));
1777 XPUSHs (mapped_new (stash_mappedbuffer, self, buf, map_flags, ptr, cb, ev, 0, 0)); 1855 XPUSHs (mapped_new (stash_mappedbuffer, self, buf, map_flags, ptr, cb, ev, 0, 0));
1778 1856
1779void 1857void
1780map_image (OpenCL::Queue self, OpenCL::Image img, cl_bool blocking = 1, cl_map_flags map_flags = CL_MAP_READ | CL_MAP_WRITE, size_t x = 0, size_t y = 0, size_t z = 0, SV *width_ = &PL_sv_undef, SV *height_ = &PL_sv_undef, SV *depth_ = &PL_sv_undef, ...) 1858map_image (OpenCL::Queue self, OpenCL::Image img, cl_bool blocking = 1, cl_map_flags map_flags = CL_MAP_READ | CL_MAP_WRITE, size_t x = 0, size_t y = 0, size_t z = 0, SV *width_ = &PL_sv_undef, SV *height_ = &PL_sv_undef, SV *depth_ = &PL_sv_undef, ...)
1833void 1911void
1834task (OpenCL::Queue self, OpenCL::Kernel kernel, ...) 1912task (OpenCL::Queue self, OpenCL::Kernel kernel, ...)
1835 ALIAS: 1913 ALIAS:
1836 enqueue_task = 0 1914 enqueue_task = 0
1837 PPCODE: 1915 PPCODE:
1916 EVENT_LIST (2);
1917
1838 cl_event ev = 0; 1918 cl_event ev = 0;
1839 EVENT_LIST (2);
1840
1841 NEED_SUCCESS (EnqueueTask, (self, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1919 NEED_SUCCESS (EnqueueTask, (self, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1842 1920
1843 if (ev) 1921 if (ev)
1844 XPUSH_CLOBJ (stash_event, ev); 1922 XPUSH_CLOBJ (stash_event, ev);
1845 1923
1846void 1924void
1847nd_range_kernel (OpenCL::Queue self, OpenCL::Kernel kernel, SV *global_work_offset, SV *global_work_size, SV *local_work_size = &PL_sv_undef, ...) 1925nd_range_kernel (OpenCL::Queue self, OpenCL::Kernel kernel, SV *global_work_offset, SV *global_work_size, SV *local_work_size = &PL_sv_undef, ...)
1848 ALIAS: 1926 ALIAS:
1849 enqueue_nd_range_kernel = 0 1927 enqueue_nd_range_kernel = 0
1850 PPCODE: 1928 PPCODE:
1851 cl_event ev = 0; 1929 EVENT_LIST (5);
1930
1852 size_t *gwo = 0, *gws, *lws = 0; 1931 size_t *gwo = 0, *gws, *lws = 0;
1853 int gws_len; 1932 int gws_len;
1854 size_t *lists; 1933 size_t *lists;
1855 int i; 1934 int i;
1856 EVENT_LIST (5);
1857 1935
1858 if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV) 1936 if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV)
1859 croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference"); 1937 croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference");
1860 1938
1861 gws_len = AvFILLp (SvRV (global_work_size)) + 1; 1939 gws_len = AvFILLp (SvRV (global_work_size)) + 1;
1900 if (!lws [i]) 1978 if (!lws [i])
1901 croak ("clEnqueueNDRangeKernel: local_work_size[%d] is zero, must be non-zero", i); 1979 croak ("clEnqueueNDRangeKernel: local_work_size[%d] is zero, must be non-zero", i);
1902 } 1980 }
1903 } 1981 }
1904 1982
1983 cl_event ev = 0;
1905 NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1984 NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1906 1985
1907 if (ev) 1986 if (ev)
1908 XPUSH_CLOBJ (stash_event, ev); 1987 XPUSH_CLOBJ (stash_event, ev);
1909 1988
1914 ALIAS: 1993 ALIAS:
1915 enqueue_migrate_mem_objects = 0 1994 enqueue_migrate_mem_objects = 0
1916 PPCODE: 1995 PPCODE:
1917 EVENT_LIST (3); 1996 EVENT_LIST (3);
1918 1997
1919 if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV) 1998 cl_uint obj_count;
1920 croak ("OpenCL::Queue::migrate_mem_objects: objects must be an array reference with OpenCL::Memory objects"); 1999 cl_mem *obj_list = object_list (cv, 0, "objects", objects, "OpenCL::Memory", &obj_count);
1921
1922 objects = SvRV (objects);
1923
1924 cl_uint object_count = av_len ((AV *)objects) + 1;
1925 cl_mem *object_list = tmpbuf (sizeof (*object_list) * object_count);
1926
1927 int i;
1928 for (i = object_count; i--; )
1929 object_list [i] = SvCLOBJ ("OpenCL::Queue::migrate_mem_objects", "objects", *av_fetch ((AV *)objects, i, 0), "OpenCL::Memory");
1930 2000
1931 cl_event ev = 0; 2001 cl_event ev = 0;
1932 NEED_SUCCESS (EnqueueMigrateMemObjects, (self, object_count, object_list, flags, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 2002 NEED_SUCCESS (EnqueueMigrateMemObjects, (self, obj_count, obj_list, flags, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1933 2003
1934 if (ev) 2004 if (ev)
1935 XPUSH_CLOBJ (stash_event, ev); 2005 XPUSH_CLOBJ (stash_event, ev);
1936 2006
1937#endif 2007#endif
1943 ALIAS: 2013 ALIAS:
1944 release_gl_objects = 1 2014 release_gl_objects = 1
1945 enqueue_acquire_gl_objects = 0 2015 enqueue_acquire_gl_objects = 0
1946 enqueue_release_gl_objects = 1 2016 enqueue_release_gl_objects = 1
1947 PPCODE: 2017 PPCODE:
1948 if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV) 2018 EVENT_LIST (2);
1949 croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call"); 2019
2020 cl_uint obj_count;
2021 cl_mem *obj_list = object_list (cv, 0, "objects", objects, "OpenCL::Memory", &obj_count);
1950 2022
1951 cl_event ev = 0; 2023 cl_event ev = 0;
1952 EVENT_LIST (2);
1953 AV *av = (AV *)SvRV (objects);
1954 cl_uint num_objects = av_len (av) + 1;
1955 cl_mem *object_list = tmpbuf (sizeof (cl_mem) * num_objects);
1956
1957 int i;
1958 for (i = num_objects; i--; )
1959 object_list [i] = SvCLOBJ ("OpenCL::Queue::acquire/release_gl_objects", "objects", *av_fetch (av, i, 0), "OpenCL::Memory");
1960 2024
1961 if (ix) 2025 if (ix)
1962 NEED_SUCCESS (EnqueueReleaseGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 2026 NEED_SUCCESS (EnqueueReleaseGLObjects, (self, obj_count, obj_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1963 else 2027 else
1964 NEED_SUCCESS (EnqueueAcquireGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 2028 NEED_SUCCESS (EnqueueAcquireGLObjects, (self, obj_count, obj_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1965 2029
1966 if (ev) 2030 if (ev)
1967 XPUSH_CLOBJ (stash_event, ev); 2031 XPUSH_CLOBJ (stash_event, ev);
1968 2032
1969#endif 2033#endif
1983void 2047void
1984marker (OpenCL::Queue self, ...) 2048marker (OpenCL::Queue self, ...)
1985 ALIAS: 2049 ALIAS:
1986 enqueue_marker = 0 2050 enqueue_marker = 0
1987 PPCODE: 2051 PPCODE:
2052 EVENT_LIST (1);
1988 cl_event ev = 0; 2053 cl_event ev = 0;
1989 EVENT_LIST (1);
1990#if PREFER_1_1 2054#if PREFER_1_1
1991 if (!event_list_count) 2055 if (!event_list_count)
1992 NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0)); 2056 NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0));
1993 else 2057 else
1994#if CL_VERSION_1_2 2058#if CL_VERSION_1_2
2008void 2072void
2009barrier (OpenCL::Queue self, ...) 2073barrier (OpenCL::Queue self, ...)
2010 ALIAS: 2074 ALIAS:
2011 enqueue_barrier = 0 2075 enqueue_barrier = 0
2012 PPCODE: 2076 PPCODE:
2077 EVENT_LIST (1);
2013 cl_event ev = 0; 2078 cl_event ev = 0;
2014 EVENT_LIST (1);
2015#if PREFER_1_1 2079#if PREFER_1_1
2016 if (!event_list_count && GIMME_V == G_VOID) 2080 if (!event_list_count && GIMME_V == G_VOID)
2017 NEED_SUCCESS (EnqueueBarrier, (self)); 2081 NEED_SUCCESS (EnqueueBarrier, (self));
2018 else 2082 else
2019#if CL_VERSION_1_2 2083#if CL_VERSION_1_2
2347void 2411void
2348build (OpenCL::Program self, SV *devices = &PL_sv_undef, SV *options = &PL_sv_undef, SV *notify = &PL_sv_undef) 2412build (OpenCL::Program self, SV *devices = &PL_sv_undef, SV *options = &PL_sv_undef, SV *notify = &PL_sv_undef)
2349 ALIAS: 2413 ALIAS:
2350 build_async = 1 2414 build_async = 1
2351 CODE: 2415 CODE:
2352 void (CL_CALLBACK *pfn_notify)(cl_program program, void *user_data) = 0;
2353 void *user_data = 0;
2354 cl_uint num_devices = 0; 2416 cl_uint device_count = 0;
2355 cl_device_id *device_list = 0; 2417 cl_device_id *device_list = 0;
2356 2418
2357 if (SvOK (devices)) 2419 if (SvOK (devices))
2358 { 2420 device_list = object_list (cv, 1, "devices", devices, "OpenCL::Device", &device_count);
2421
2422 void *user_data;
2423 program_callback pfn_notify = make_program_callback (notify, &user_data);
2424
2425 if (ix)
2426 build_program_async (self, device_count, device_list, SvPVbyte_nolen (options), user_data);
2427 else
2428 NEED_SUCCESS (BuildProgram, (self, device_count, device_list, SvPVbyte_nolen (options), pfn_notify, user_data));
2429
2430#if CL_VERSION_1_2
2431
2432void
2433compile (OpenCL::Program self, SV *devices, SV *options = &PL_sv_undef, SV *headers = &PL_sv_undef, SV *notify = &PL_sv_undef)
2434 CODE:
2435 cl_uint device_count = 0;
2436 cl_device_id *device_list = 0;
2437
2438 if (SvOK (devices))
2439 device_list = object_list (cv, 1, "devices", devices, "OpenCL::Device", &device_count);
2440
2441 cl_uint header_count = 0;
2442 cl_program *header_list = 0;
2443 const char **header_name = 0;
2444
2445 if (SvOK (headers))
2446 {
2359 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) 2447 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVHV)
2360 croak ("clProgramBuild: devices must be undef or an array of OpenCL::Device objects."); 2448 croak ("clCompileProgram: headers must be undef or a hashref of name => OpenCL::Program pairs");
2361 2449
2362 AV *av = (AV *)SvRV (devices); 2450 HV *hv = (HV *)SvRV (devices);
2363 num_devices = av_len (av) + 1;
2364 2451
2365 if (num_devices) 2452 header_count = hv_iterinit (hv);
2453 header_list = tmpbuf (sizeof (*header_list) * header_count);
2454 header_name = tmpbuf (sizeof (*header_name) * header_count);
2455
2456 HE *he;
2457 int i = 0;
2458 while (he = hv_iternext (hv))
2366 { 2459 {
2367 device_list = tmpbuf (sizeof (*device_list) * num_devices); 2460 header_name [i] = SvPVbyte_nolen (HeSVKEY_force (he));
2461 header_list [i] = SvCLOBJ ("clCompileProgram", "headers", HeVAL (he), "OpenCL::Program");
2368 int count; 2462 ++i;
2369 for (count = 0; count < num_devices; ++count)
2370 device_list [count] = SvCLOBJ ("clBuildProgram", "devices", *av_fetch (av, count, 1), "OpenCL::Device");
2371 } 2463 }
2372 } 2464 }
2373 2465
2374 if (SvOK (notify)) 2466 void *user_data;
2375 { 2467 program_callback pfn_notify = make_program_callback (notify, &user_data);
2376 NEED_SUCCESS (RetainProgram, (self));
2377 pfn_notify = eq_program_notify;
2378 user_data = SvREFCNT_inc (s_get_cv (notify));
2379 }
2380 2468
2381 if (ix)
2382 build_program_async (self, num_devices, device_list, SvPVbyte_nolen (options), user_data);
2383 else
2384 NEED_SUCCESS (BuildProgram, (self, num_devices, device_list, SvPVbyte_nolen (options), pfn_notify, user_data)); 2469 NEED_SUCCESS (CompileProgram, (self, device_count, device_list, SvPVbyte_nolen (options),
2470 header_count, header_list, header_name, pfn_notify, user_data));
2471
2472#endif
2385 2473
2386void 2474void
2387build_info (OpenCL::Program self, OpenCL::Device device, cl_program_build_info name) 2475build_info (OpenCL::Program self, OpenCL::Device device, cl_program_build_info name)
2388 PPCODE: 2476 PPCODE:
2389 size_t size; 2477 size_t size;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines