… | |
… | |
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 | |
287 | static void |
291 | static void |
288 | CLOBJ_push (SV *self, SV *data) |
292 | CLOBJ_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 */ |
323 | static void CL_CALLBACK |
329 | static void CL_CALLBACK |
… | |
… | |
347 | |
353 | |
348 | static void |
354 | static void |
349 | eq_enq (eq_vtbl *vtbl, SV *cb, void *data1, void *data2, void *data3) |
355 | eq_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; |
… | |
… | |
428 | eq_poll_interrupt (pTHX_ void *c_arg, int value) |
432 | eq_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 | |
435 | static void |
440 | static void |
436 | eq_context_push (void *data1, void *data2, void *data3) |
441 | eq_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 | |
444 | static eq_vtbl eq_context_vtbl = { 0, eq_context_push }; |
452 | static eq_vtbl eq_context_vtbl = { 0, eq_context_push }; |
445 | |
453 | |
|
|
454 | static void CL_CALLBACK |
|
|
455 | eq_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 | |
|
|
472 | static SV * |
|
|
473 | new_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 | |
448 | static void |
488 | static void |
449 | eq_program_push (void *data1, void *data2, void *data3) |
489 | eq_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 | |
504 | static void |
545 | static void |
505 | eq_event_push (void *data1, void *data2, void *data3) |
546 | eq_event_push (void *data1, void *data2, void *data3) |
506 | { |
547 | { |
… | |
… | |
514 | |
555 | |
515 | static void CL_CALLBACK |
556 | static void CL_CALLBACK |
516 | eq_event_notify (cl_event event, cl_int event_command_exec_status, void *user_data) |
557 | eq_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 | |
524 | static size_t |
565 | static 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 | |
639 | void |
680 | void |
640 | context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
681 | context_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 | |
|
|
647 | void |
687 | void |
648 | context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) |
688 | context (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 | |
654 | void |
692 | void |
655 | wait_for_events (...) |
693 | wait_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 | |
712 | void |
750 | void |
713 | context (OpenCL::Platform self, cl_context_properties *properties, SV *devices, SV *notify = 0) |
751 | context (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 | |
732 | void |
768 | void |
733 | context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
769 | context_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 | |
740 | MODULE = OpenCL PACKAGE = OpenCL::Device |
778 | MODULE = OpenCL PACKAGE = OpenCL::Device |
741 | |
779 | |
742 | void |
780 | void |
743 | info (OpenCL::Device self, cl_device_info name) |
781 | info (OpenCL::Device self, cl_device_info name) |