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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.51 by root, Tue Apr 24 22:45:38 2012 UTC vs.
Revision 1.52 by root, Tue Apr 24 23:53:12 2012 UTC

273{ 273{
274 if (SvROK (sv) && sv_derived_from (sv, pkg)) 274 if (SvROK (sv) && sv_derived_from (sv, pkg))
275 { 275 {
276 SV *rv = SvRV (sv); 276 SV *rv = SvRV (sv);
277 277
278#if CLOBJ_PUSH
278 if (SvTYPE (rv) == SVt_PVAV) 279 if (SvTYPE (rv) == SVt_PVAV)
279 rv = AvARRAY (rv)[0]; 280 rv = AvARRAY (rv)[0];
281#endif
280 282
281 return (void *)SvIV (SvRV (sv)); 283 return (void *)SvIV (rv);
282 } 284 }
283 285
284 croak ("%s: %s is not of type %s", func, svname, pkg); 286 croak ("%s: %s is not of type %s", func, svname, pkg);
285} 287}
288
289#if CLOBJ_PUSH
286 290
287static void 291static void
288CLOBJ_push (SV *self, SV *data) 292CLOBJ_push (SV *self, SV *data)
289{ 293{
290 SV *rv = SvRV (self); 294 SV *rv = SvRV (self);
314 SV *sv = sv_struct (size); 318 SV *sv = sv_struct (size);
315 CLOBJ_push (self, sv); 319 CLOBJ_push (self, sv);
316 return SvPVX (sv); 320 return SvPVX (sv);
317} 321}
318 322
323#endif
324
319/*****************************************************************************/ 325/*****************************************************************************/
320/* callback stuff */ 326/* callback stuff */
321 327
322/* default context callback, log to stderr */ 328/* default context callback, log to stderr */
323static void CL_CALLBACK 329static void CL_CALLBACK
347 353
348static void 354static void
349eq_enq (eq_vtbl *vtbl, SV *cb, void *data1, void *data2, void *data3) 355eq_enq (eq_vtbl *vtbl, SV *cb, void *data1, void *data2, void *data3)
350{ 356{
351 eq_item *item = malloc (sizeof (eq_item)); 357 eq_item *item = malloc (sizeof (eq_item));
352
353 printf ("enq(%p,%p,%p,%p,%p)\n", vtbl, cb, data1, data2, data3);//D
354 358
355 item->next = 0; 359 item->next = 0;
356 item->vtbl = vtbl; 360 item->vtbl = vtbl;
357 item->cb = cb; 361 item->cb = cb;
358 item->data1 = data1; 362 item->data1 = data1;
428eq_poll_interrupt (pTHX_ void *c_arg, int value) 432eq_poll_interrupt (pTHX_ void *c_arg, int value)
429{ 433{
430 eq_poll (); 434 eq_poll ();
431} 435}
432 436
437/*****************************************************************************/
433/* context notify */ 438/* context notify */
434 439
435static void 440static void
436eq_context_push (void *data1, void *data2, void *data3) 441eq_context_push (void *data1, void *data2, void *data3)
437{ 442{
438 dSP; 443 dSP;
439 PUSHs (sv_2mortal (newSVpv (data1, 0))); 444 PUSHs (sv_2mortal (newSVpv (data1, 0)));
440 PUSHs (sv_2mortal (newSVpvn (data2, (STRLEN)data3))); 445 PUSHs (sv_2mortal (newSVpvn (data2, (STRLEN)data3)));
441 PUTBACK; 446 PUTBACK;
447
448 free (data1);
449 free (data2);
442} 450}
443 451
444static eq_vtbl eq_context_vtbl = { 0, eq_context_push }; 452static eq_vtbl eq_context_vtbl = { 0, eq_context_push };
445 453
454static void CL_CALLBACK
455eq_context_notify (const char *msg, const void *pvt, size_t cb, void *user_data)
456{
457 void *pvt_copy = malloc (cb);
458 memcpy (pvt_copy, pvt, cb);
459 eq_enq (&eq_context_vtbl, user_data, strdup (msg), pvt_copy, (void *)cb);
460}
461
462#define CONTEXT_NOTIFY_CALLBACK \
463 void (CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *) = context_default_notify; \
464 void *user_data = 0; \
465 \
466 if (SvOK (notify)) \
467 { \
468 pfn_notify = eq_context_notify; \
469 user_data = s_get_cv (notify); \
470 }
471
472static SV *
473new_clobj_context (cl_context ctx, void *user_data)
474{
475 SV *sv = NEW_CLOBJ ("OpenCL::Context", ctx);
476
477 if (user_data)
478 sv_magicext (SvRV (sv), user_data, PERL_MAGIC_ext, 0, 0, 0);
479
480 return sv;
481}
482
483#define XPUSH_CLOBJ_CONTEXT XPUSHs (new_clobj_context (ctx, user_data));
484
485/*****************************************************************************/
446/* build/compile/link notify */ 486/* build/compile/link notify */
447 487
448static void 488static void
449eq_program_push (void *data1, void *data2, void *data3) 489eq_program_push (void *data1, void *data2, void *data3)
450{ 490{
497 537
498 xthread_t id; 538 xthread_t id;
499 thread_create (&id, build_program_thread, arg); 539 thread_create (&id, build_program_thread, arg);
500} 540}
501 541
542/*****************************************************************************/
502/* event objects */ 543/* event objects */
503 544
504static void 545static void
505eq_event_push (void *data1, void *data2, void *data3) 546eq_event_push (void *data1, void *data2, void *data3)
506{ 547{
514 555
515static void CL_CALLBACK 556static void CL_CALLBACK
516eq_event_notify (cl_event event, cl_int event_command_exec_status, void *user_data) 557eq_event_notify (cl_event event, cl_int event_command_exec_status, void *user_data)
517{ 558{
518 clRetainEvent (event); 559 clRetainEvent (event);
519 eq_enq (&eq_event_vtbl, user_data, (void *)event, (void *)event_command_exec_status, 0); 560 eq_enq (&eq_event_vtbl, user_data, (void *)event, (void *)(IV)event_command_exec_status, 0);
520} 561}
521 562
522/*****************************************************************************/ 563/*****************************************************************************/
523 564
524static size_t 565static size_t
635 EXTEND (SP, count); 676 EXTEND (SP, count);
636 for (i = 0; i < count; ++i) 677 for (i = 0; i < count; ++i)
637 PUSH_CLOBJ ("OpenCL::Platform", list [i]); 678 PUSH_CLOBJ ("OpenCL::Platform", list [i]);
638 679
639void 680void
640context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) 681context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, SV *notify = &PL_sv_undef)
641 PPCODE: 682 PPCODE:
683 CONTEXT_NOTIFY_CALLBACK;
642 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res)); 684 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res));
643 XPUSH_CLOBJ ("OpenCL::Context", ctx); 685 XPUSH_CLOBJ_CONTEXT;
644 686
645#if 0
646
647void 687void
648context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) 688context (FUTURE properties, FUTURE devices, FUTURE notify)
649 PPCODE: 689 PPCODE:
650 /* der Gipfel der Kunst */ 690 /* der Gipfel der Kunst */
651
652#endif
653 691
654void 692void
655wait_for_events (...) 693wait_for_events (...)
656 CODE: 694 CODE:
657 EVENT_LIST (0, items); 695 EVENT_LIST (0, items);
708 EXTEND (SP, count); 746 EXTEND (SP, count);
709 for (i = 0; i < count; ++i) 747 for (i = 0; i < count; ++i)
710 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); 748 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i]));
711 749
712void 750void
713context (OpenCL::Platform self, cl_context_properties *properties, SV *devices, SV *notify = 0) 751context (OpenCL::Platform self, cl_context_properties *properties, SV *devices, SV *notify = &PL_sv_undef)
714 PPCODE: 752 PPCODE:
715 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) 753 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV)
716 croak ("OpenCL::Platform::context argument 'device' must be an arrayref with device objects, in call"); 754 croak ("OpenCL::Platform::context argument 'device' must be an arrayref with device objects, in call");
717 755
718 AV *av = (AV *)SvRV (devices); 756 AV *av = (AV *)SvRV (devices);
721 759
722 int i; 760 int i;
723 for (i = num_devices; i--; ) 761 for (i = num_devices; i--; )
724 device_list [i] = SvCLOBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device"); 762 device_list [i] = SvCLOBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device");
725 763
726 void (CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *) = context_default_notify; 764 CONTEXT_NOTIFY_CALLBACK;
727 void *user_data = 0;
728
729 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (properties, num_devices, device_list, pfn_notify, user_data, &res)); 765 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (properties, num_devices, device_list, pfn_notify, user_data, &res));
730 XPUSH_CLOBJ ("OpenCL::Context", ctx); 766 XPUSH_CLOBJ_CONTEXT;
731 767
732void 768void
733context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) 769context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, SV *notify = &PL_sv_undef)
734 PPCODE: 770 PPCODE:
735 cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self }; 771 cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self };
736 cl_context_properties *props = SvCONTEXTPROPERTIES ("OpenCL::Platform::context_from_type", "properties", properties, extra, 2); 772 cl_context_properties *props = SvCONTEXTPROPERTIES ("OpenCL::Platform::context_from_type", "properties", properties, extra, 2);
773
774 CONTEXT_NOTIFY_CALLBACK;
737 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res)); 775 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res));
738 XPUSH_CLOBJ ("OpenCL::Context", ctx); 776 XPUSH_CLOBJ_CONTEXT;
739 777
740MODULE = OpenCL PACKAGE = OpenCL::Device 778MODULE = OpenCL PACKAGE = OpenCL::Device
741 779
742void 780void
743info (OpenCL::Device self, cl_device_info name) 781info (OpenCL::Device self, cl_device_info name)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines