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.53 by root, Wed Apr 25 00:02:25 2012 UTC

270/* they can be upgraded at runtime to the array form */ 270/* they can be upgraded at runtime to the array form */
271static void * 271static void *
272SvCLOBJ (const char *func, const char *svname, SV *sv, const char *pkg) 272SvCLOBJ (const char *func, const char *svname, SV *sv, const char *pkg)
273{ 273{
274 if (SvROK (sv) && sv_derived_from (sv, pkg)) 274 if (SvROK (sv) && sv_derived_from (sv, pkg))
275 {
276 SV *rv = SvRV (sv);
277
278 if (SvTYPE (rv) == SVt_PVAV)
279 rv = AvARRAY (rv)[0];
280
281 return (void *)SvIV (SvRV (sv)); 275 return (void *)SvIV (SvRV (sv));
282 }
283 276
284 croak ("%s: %s is not of type %s", func, svname, pkg); 277 croak ("%s: %s is not of type %s", func, svname, pkg);
285}
286
287static void
288CLOBJ_push (SV *self, SV *data)
289{
290 SV *rv = SvRV (self);
291
292 if (SvTYPE (rv) != SVt_PVAV)
293 {
294 AV *av = newAV ();
295 av_push (av, rv);
296 rv = (SV *)av;
297 SvRV_set (self, rv);
298 }
299
300 av_push ((AV *)rv, data);
301}
302
303static SV *
304sv_struct (STRLEN size)
305{
306 SV *sv = newSV (size);
307 SvPOK_only (sv);
308 return sv;
309}
310
311static void *
312CLOBJ_push_struct (SV *self, STRLEN size)
313{
314 SV *sv = sv_struct (size);
315 CLOBJ_push (self, sv);
316 return SvPVX (sv);
317} 278}
318 279
319/*****************************************************************************/ 280/*****************************************************************************/
320/* callback stuff */ 281/* callback stuff */
321 282
347 308
348static void 309static void
349eq_enq (eq_vtbl *vtbl, SV *cb, void *data1, void *data2, void *data3) 310eq_enq (eq_vtbl *vtbl, SV *cb, void *data1, void *data2, void *data3)
350{ 311{
351 eq_item *item = malloc (sizeof (eq_item)); 312 eq_item *item = malloc (sizeof (eq_item));
352
353 printf ("enq(%p,%p,%p,%p,%p)\n", vtbl, cb, data1, data2, data3);//D
354 313
355 item->next = 0; 314 item->next = 0;
356 item->vtbl = vtbl; 315 item->vtbl = vtbl;
357 item->cb = cb; 316 item->cb = cb;
358 item->data1 = data1; 317 item->data1 = data1;
383 X_UNLOCK (eq_lock); 342 X_UNLOCK (eq_lock);
384 343
385 return res; 344 return res;
386} 345}
387 346
388#if 0
389static void
390mem_free (pTHX_ void *p)
391{
392 free (p);
393}
394//SAVEDESTRUCTOR_X (mem_free, item);
395#endif
396
397static void 347static void
398eq_poll (void) 348eq_poll (void)
399{ 349{
400 eq_item *item; 350 eq_item *item;
401 351
428eq_poll_interrupt (pTHX_ void *c_arg, int value) 378eq_poll_interrupt (pTHX_ void *c_arg, int value)
429{ 379{
430 eq_poll (); 380 eq_poll ();
431} 381}
432 382
383/*****************************************************************************/
433/* context notify */ 384/* context notify */
434 385
435static void 386static void
436eq_context_push (void *data1, void *data2, void *data3) 387eq_context_push (void *data1, void *data2, void *data3)
437{ 388{
438 dSP; 389 dSP;
439 PUSHs (sv_2mortal (newSVpv (data1, 0))); 390 PUSHs (sv_2mortal (newSVpv (data1, 0)));
440 PUSHs (sv_2mortal (newSVpvn (data2, (STRLEN)data3))); 391 PUSHs (sv_2mortal (newSVpvn (data2, (STRLEN)data3)));
441 PUTBACK; 392 PUTBACK;
393
394 free (data1);
395 free (data2);
442} 396}
443 397
444static eq_vtbl eq_context_vtbl = { 0, eq_context_push }; 398static eq_vtbl eq_context_vtbl = { 0, eq_context_push };
445 399
400static void CL_CALLBACK
401eq_context_notify (const char *msg, const void *pvt, size_t cb, void *user_data)
402{
403 void *pvt_copy = malloc (cb);
404 memcpy (pvt_copy, pvt, cb);
405 eq_enq (&eq_context_vtbl, user_data, strdup (msg), pvt_copy, (void *)cb);
406}
407
408#define CONTEXT_NOTIFY_CALLBACK \
409 void (CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *) = context_default_notify; \
410 void *user_data = 0; \
411 \
412 if (SvOK (notify)) \
413 { \
414 pfn_notify = eq_context_notify; \
415 user_data = s_get_cv (notify); \
416 }
417
418static SV *
419new_clobj_context (cl_context ctx, void *user_data)
420{
421 SV *sv = NEW_CLOBJ ("OpenCL::Context", ctx);
422
423 if (user_data)
424 sv_magicext (SvRV (sv), user_data, PERL_MAGIC_ext, 0, 0, 0);
425
426 return sv;
427}
428
429#define XPUSH_CLOBJ_CONTEXT XPUSHs (new_clobj_context (ctx, user_data));
430
431/*****************************************************************************/
446/* build/compile/link notify */ 432/* build/compile/link notify */
447 433
448static void 434static void
449eq_program_push (void *data1, void *data2, void *data3) 435eq_program_push (void *data1, void *data2, void *data3)
450{ 436{
497 483
498 xthread_t id; 484 xthread_t id;
499 thread_create (&id, build_program_thread, arg); 485 thread_create (&id, build_program_thread, arg);
500} 486}
501 487
488/*****************************************************************************/
502/* event objects */ 489/* event objects */
503 490
504static void 491static void
505eq_event_push (void *data1, void *data2, void *data3) 492eq_event_push (void *data1, void *data2, void *data3)
506{ 493{
514 501
515static void CL_CALLBACK 502static void CL_CALLBACK
516eq_event_notify (cl_event event, cl_int event_command_exec_status, void *user_data) 503eq_event_notify (cl_event event, cl_int event_command_exec_status, void *user_data)
517{ 504{
518 clRetainEvent (event); 505 clRetainEvent (event);
519 eq_enq (&eq_event_vtbl, user_data, (void *)event, (void *)event_command_exec_status, 0); 506 eq_enq (&eq_event_vtbl, user_data, (void *)event, (void *)(IV)event_command_exec_status, 0);
520} 507}
521 508
522/*****************************************************************************/ 509/*****************************************************************************/
523 510
524static size_t 511static size_t
635 EXTEND (SP, count); 622 EXTEND (SP, count);
636 for (i = 0; i < count; ++i) 623 for (i = 0; i < count; ++i)
637 PUSH_CLOBJ ("OpenCL::Platform", list [i]); 624 PUSH_CLOBJ ("OpenCL::Platform", list [i]);
638 625
639void 626void
640context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) 627context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, SV *notify = &PL_sv_undef)
641 PPCODE: 628 PPCODE:
629 CONTEXT_NOTIFY_CALLBACK;
642 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res)); 630 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res));
643 XPUSH_CLOBJ ("OpenCL::Context", ctx); 631 XPUSH_CLOBJ_CONTEXT;
644 632
645#if 0
646
647void 633void
648context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) 634context (FUTURE properties, FUTURE devices, FUTURE notify)
649 PPCODE: 635 PPCODE:
650 /* der Gipfel der Kunst */ 636 /* der Gipfel der Kunst */
651
652#endif
653 637
654void 638void
655wait_for_events (...) 639wait_for_events (...)
656 CODE: 640 CODE:
657 EVENT_LIST (0, items); 641 EVENT_LIST (0, items);
708 EXTEND (SP, count); 692 EXTEND (SP, count);
709 for (i = 0; i < count; ++i) 693 for (i = 0; i < count; ++i)
710 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); 694 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i]));
711 695
712void 696void
713context (OpenCL::Platform self, cl_context_properties *properties, SV *devices, SV *notify = 0) 697context (OpenCL::Platform self, cl_context_properties *properties, SV *devices, SV *notify = &PL_sv_undef)
714 PPCODE: 698 PPCODE:
715 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) 699 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV)
716 croak ("OpenCL::Platform::context argument 'device' must be an arrayref with device objects, in call"); 700 croak ("OpenCL::Platform::context argument 'device' must be an arrayref with device objects, in call");
717 701
718 AV *av = (AV *)SvRV (devices); 702 AV *av = (AV *)SvRV (devices);
721 705
722 int i; 706 int i;
723 for (i = num_devices; i--; ) 707 for (i = num_devices; i--; )
724 device_list [i] = SvCLOBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device"); 708 device_list [i] = SvCLOBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device");
725 709
726 void (CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *) = context_default_notify; 710 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)); 711 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (properties, num_devices, device_list, pfn_notify, user_data, &res));
730 XPUSH_CLOBJ ("OpenCL::Context", ctx); 712 XPUSH_CLOBJ_CONTEXT;
731 713
732void 714void
733context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) 715context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, SV *notify = &PL_sv_undef)
734 PPCODE: 716 PPCODE:
735 cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self }; 717 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); 718 cl_context_properties *props = SvCONTEXTPROPERTIES ("OpenCL::Platform::context_from_type", "properties", properties, extra, 2);
719
720 CONTEXT_NOTIFY_CALLBACK;
737 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res)); 721 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res));
738 XPUSH_CLOBJ ("OpenCL::Context", ctx); 722 XPUSH_CLOBJ_CONTEXT;
739 723
740MODULE = OpenCL PACKAGE = OpenCL::Device 724MODULE = OpenCL PACKAGE = OpenCL::Device
741 725
742void 726void
743info (OpenCL::Device self, cl_device_info name) 727info (OpenCL::Device self, cl_device_info name)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines