/
sjgopencl.c
3101 lines (2169 loc) · 82.4 KB
/
sjgopencl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Gimp plugin for OpenCL support
*
* (c) Stephen Geary, Dec 2013
*
* $Id: sjgopencl.c,v 1.46 2015/11/26 05:07:50 sjg Exp $
*
* A major rewrite from generiffilter.c v 1.221 to add support
* for more scripted control of multiple kernel processes.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <gtk-2.0/gtk/gtk.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
#include "sjg_messages.h"
#include "simpleCL.h"
#include "sjgutils.h"
#include "debugme.h"
#include "parser.h"
#include "expr.h"
/***********************************************************************************
*/
#define PLUG_IN_NAME "sjg-opencl"
#define PLUG_IN_AUTHOR "Stephen Geary"
// Union used in passing parameters to kernel
union uf_u {
int i ;
float f ;
} ;
typedef union uf_u uf_t ;
/***********************************************************************************
*/
#define CHECKPTR(ptr) if( (ptr) == NULL ){ SJGDEBUG() ; goto err_exit ; }
/***********************************************************************************
*/
// convenience macro for filling file paths in gimp_directory subdirs
#define make_gimp_filename( buffer, subdir, fname ) \
if( (buffer) != NULL ) \
{ \
snprintf( (char *)((buffer)), MAXPATHLEN, "%s%c%s%c%s%c", \
gimp_directory(), \
G_DIR_SEPARATOR, \
(subdir), \
G_DIR_SEPARATOR, \
(fname), \
0 \
) ; \
}
/***********************************************************************************
*/
int width = 0 ;
int height = 0 ;
int channels = 0 ;
/***********************************************************************************
*/
/* return rest of line with matching key in buffer
*
* return FALSE if not found
*/
#define check_for_firstentry(h,p,b,l) check_for_firstentry_real((h),(guchar *)(p),(b),(l))
static int check_for_firstentry_real( void *handlep, guchar *prefix, guchar *buffer, int buflen )
{
// check for FIRST entry in the parser file matching "<prefix> <something>EOL"
int retv = FALSE ;
if( ( handlep == NULL ) && ( prefix != NULL ) )
{
SJGDEBUG() ;
return FALSE ;
}
if( ( buffer != NULL ) && ( buflen > 0 ) )
{
buffer[0] = 0 ;
}
int *idxp = NULL ;
int idxcount = 0 ;
idxp = parser_get_indexarray( handlep ) ;
if( idxp == NULL )
{
SJGDEBUG() ;
return FALSE ;
}
idxcount = parser_get_indexlen( handlep ) ;
if( idxcount == 0 )
{
SJGDEBUG() ;
return FALSE ;
}
// have a useful index array
guchar *filecopy ;
filecopy = parser_get_filecopy( handlep ) ;
guchar *p ;
int j = 0 ;
int i = 0 ;
while( j < idxcount )
{
p = filecopy + idxp[j] ;
i = parser_starts_with( p, prefix ) ;
if( i > 0 )
{
// found a match to the prefix
retv = TRUE ;
p += i ;
i = 0 ;
while( ( i < buflen-1 ) && isnoteol(p[i]) )
{
buffer[i] = p[i] ;
i++ ;
};
// terminating nul
buffer[i] = 0 ;
// as we have a first match we can stop looking
break ;
}
j++ ;
};
return retv ;
}
/***********************************************************************************
*/
// #define PARAMCOUNTMAX 64
/* scans a file for parameters names
*
* The file was loaded via parser_loadfile() and the
* handlep we receive is used for referencing it.
*
* Also the indexarray was built previously.
*
* returns a count and set the array pointer to an
* allocated memory array of strings ( or NULL if count was zero )
*/
static int check_for_parameters( void *handlep, guchar ***paramnames, int *maxlenp )
{
int count = 0 ;
*paramnames = NULL ;
if( handlep == NULL )
{
return 0 ;
}
// have the file in memory. Now scan it for parameters.
int *idxp = NULL ;
int idxcount = 0 ;
idxp = parser_get_indexarray( handlep ) ;
if( idxp == NULL )
{
SJGDEBUG() ;
return 0 ;
}
idxcount = parser_get_indexlen( handlep ) ;
if( idxcount == 0 )
{
// cannot be any PARAM entries as their are no entries
return 0 ;
}
SJGDEBUGF( "idxcount = [%d]", idxcount ) ;
// have a list of candidate lines in the file
//
// now find the ones that match our needs
/* Alloca() temporary char pointer arrays
*
* Cannot need more than idxcount entries
*/
/*
guchar *found[PARAMCOUNTMAX] ;
guchar *values[PARAMCOUNTMAX] ;
*/
/* The following replaces the above and assumes that
* alloca() allocates an area aligned for pointers
*/
guchar **found = (guchar **)aligned_alloca( idxcount*sizeof(guchar *), sizeof(guchar *) ) ;
guchar **values = (guchar **)aligned_alloca( idxcount*sizeof(guchar *), sizeof(guchar *) ) ;
guchar *filecopy = NULL ;
filecopy = parser_get_filecopy( handlep ) ;
int i = 0 ;
int j = 0 ;
guchar *p = NULL ;
count = 0 ;
int maxlen = 0 ;
int len = 0 ;
while( i < idxcount )
{
p = filecopy + idxp[i] ;
j = parser_starts_with( p, (guchar *)"// param " ) ;
if( j >= 0 )
{
p += j ;
if( isnoteol(*p) && isliteral(*p) )
{
found[count] = p ;
len = 1 ;
while( isnoteol(*p) && ! isblank(*p) )
{
p++ ;
len++ ;
};
if( isblank(*p) )
{
// the expected space is here
if( len > maxlen )
{
maxlen = len ;
}
p++ ;
while( isblank(*p) )
{
p++ ;
};
len = parser_readfp( p ) ;
if( len > 0 )
{
// did find a decimal floating point number
if( len > maxlen )
{
maxlen = len ;
}
values[count] = p ;
// SJGDEBUGF( "found[%d] = [%p]", count, found[count] ) ;
// SJGDEBUGF( "values[%d] = [%p]", count, values[count] ) ;
p += j ;
count++ ;
}
}
}
}
i++ ;
};
// leave room for a terminating nul
maxlen++ ;
// store maxlen
*maxlenp = maxlen ;
// now allocate an array ( if needed ) for the
// parameters names array
// note that we return BOTH the array of pointers
// AND the names in a single allocated memory block
//
// The pointers are arranged as an array at the start
// of the block and the names follow ( as another array )
// with the default values they relate to paired.
if( count == 0 )
{
*paramnames = NULL ;
return 0 ;
}
int w = maxlen + 1 ;
*paramnames = (guchar **)g_malloc_dbg( count*( ( 2*w ) + sizeof(gchar *) ) ) ;
if( *paramnames == NULL )
{
// cannot build parameter list
return 0 ;
}
// copy the param names into the file
guchar *nameblock = ( (guchar *)(*paramnames) ) + ( count * sizeof(gchar *) ) ;
guchar **pnames = *paramnames ;
guchar *s = NULL ;
guchar *d = NULL ;
i = 0 ;
while( i < count )
{
// SJGDEBUGF( "found[i] = [%p]", found[i] ) ;
// store the pointer to the name
pnames[i] = nameblock + ( 2 * i * w ) ;
// SJGDEBUGF( "*paramnames[i] = [%p]", pnames[i] ) ;
s = found[i] ;
d = pnames[i] ;
while( isnoteol(*s) && ! isblank(*s) )
{
*d = *s ;
d++ ;
s++ ;
}
*d = 0 ;
// store the default value it relates to.
s = values[i] ;
d = pnames[i] + w ;
while( isnoteol(*s) )
{
*d = *s ;
d++ ;
s++ ;
}
*d = 0 ;
SJGDEBUGF( "copied to *paramnames[i] = [%s]", pnames[i] ) ;
i++ ;
// SJGDEBUG() ;
};
// SJGDEBUG() ;
return count ;
}
/***********************************************************************************
*/
#define MENUENTRY_MAXLEN 64
static void init()
{
// SJGDEBUGF( "%s :: init called", PLUG_IN_NAME ) ;
// scan the opencl directory in gimp_directory()
// to see if we have matching "auto_opencl_*.py"
// file for them.
GDir *dirh = NULL ;
guchar *oclpath = NULL ;
guchar fname[MAXPATHLEN+1] ;
fname[MAXPATHLEN] = 0 ;
make_gimp_filename( fname, "opencl.log", "sjgopencl_init.log" ) ;
debug_init_log( fname ) ;
oclpath = (guchar *)g_build_filename( gimp_directory(), "opencl", NULL ) ;
if( oclpath == NULL )
{
goto errexit ;
}
dirh = g_dir_open( (gchar *)oclpath, 0, NULL ) ;
if( dirh != NULL )
{
guchar *dname = NULL ;
guchar dnamefull[MAXPATHLEN+1] ;
int len = -1 ;
int scriptdirlen = - 1 ;
make_gimp_filename( fname, "scripts", "sjgopencl_" ) ;
scriptdirlen = strlen( (char *)fname ) ;
guchar menuentry[MENUENTRY_MAXLEN] ;
menuentry[0] = 0 ;
guchar **paramnames = NULL ;
int paramcount = 0 ;
int maxlen = 0 ;
int k = 0 ;
while( ( dname = (guchar *)g_dir_read_name( dirh ) ) != NULL )
{
// SJGDEBUGF( "ocl dir list :: %s", dname ) ;
/* last three chars must be ".cl" so check this
* and if not ignore the entry
*/
len = strlen( (char *)dname ) ;
if( ( len < 4 )
|| ( dname[len-3] != '.' )
|| ( (char)toupper((int)dname[len-2]) != 'C' )
|| ( (char)toupper((int)dname[len-1]) != 'L' )
)
{
SJGDEBUGF( SJG_MESSAGE_001, dname ) ;
continue ;
}
// check to see if there is a corresponding script
// file for it.
// construct fname using omitting the "cl" at the end
// Now done when fname root is constructed as it doesn't change
// memcpy( fname+scriptdirlen, "sjgopencl_", 10 ) ;
memcpy( fname+scriptdirlen, dname, len-2 ) ;
fname[scriptdirlen+len-2] = 's' ;
fname[scriptdirlen+len-1] = 'c' ;
fname[scriptdirlen+len ] = 'm' ;
fname[scriptdirlen+len+1] = 0 ;
/*
* check if a file exists and is more recent than the
* opencl source file ( so we can force an update of
* script if need be ).
*/
make_gimp_filename( dnamefull, "opencl", dname ) ;
// if( g_access( (gchar *)fname, F_OK ) == 0 )
if( g_file_exists( fname ) == TRUE )
{
// check existing file modification times
if( compare_file_write_times( dnamefull , fname ) == FCWT_NEWER )
{
// OpenCL file time is newer so we need
// to delete the old script file and
// generate a new one.
SJGDEBUGF( SJG_MESSAGE_002, dname ) ;
g_remove( (gchar *)fname ) ;
}
}
// if no script file exists then create one
// if( g_access( (gchar *)fname, F_OK ) != 0 )
if( g_file_exists( fname ) == FALSE )
{
SJGDEBUGF( SJG_MESSAGE_003, fname ) ;
// create the script file
FILE *newscript = NULL ;
newscript = fopen( (char *)fname, "w" ) ;
if( newscript != NULL )
{
/* check for Script-Fu parameters in the OpenCL file
*
* These are denote using commented lines ( "// " )
*/
void *handlep = NULL ;
handlep = parser_loadfile( dnamefull ) ;
if( handlep == NULL )
{
// could not load in parser - skip to next file
SJGDEBUG() ;
continue ;
}
// build the arrayindex of all lines with
// the require comment signature at the start
k = parser_build_indexarray( handlep, (guchar *)"// " ) ;
if( k <= 0 )
{
SJGDEBUG() ;
paramcount = 0 ;
menuentry[0] = 0 ;
}
else
{
check_for_firstentry( handlep, "// menuentry ", menuentry, MENUENTRY_MAXLEN ) ;
paramcount = check_for_parameters( handlep, ¶mnames, &maxlen ) ;
}
parser_closefile( handlep ) ;
// write to the file
fprintf( newscript, SJG_MESSAGE_004, PLUG_IN_NAME ) ;
fprintf( newscript, "(define (sjgopencl-%.*s image drawable", len-3, dname ) ;
for( k = 0 ; k < paramcount ; k++ )
{
fprintf( newscript, " p%d", k ) ;
}
fprintf( newscript, ")\n\n (let* (\n" ) ;
fprintf( newscript, " (parray (cons-array %d 'double))\n", paramcount ) ;
fprintf( newscript, " )\n\n" ) ;
for( k = 0 ; k < paramcount ; k++ )
{
fprintf( newscript, " (aset parray %d p%d)\n", k, k ) ;
}
fprintf( newscript, "\n (%s 1 image drawable \"%.*s.cl\" %d parray)\n", PLUG_IN_NAME, len-3, dname, paramcount ) ;
fprintf( newscript, " )\n\n" ) ;
fprintf( newscript, ")\n\n" ) ;
// if we found a menu entry in the source file then
// it will leave a non empty string in 'menuentry'
if( menuentry[0] == 0 )
{
// without a menuentry in the source file we try
// building one from the name of the file.
// The menu entry is a modified version of dname.
// We remove the extension and replace underscores
// wirh spaces.
// Lastly we make the entiure string lower case except
// for the first character which is made upper case.
int j = 0 ;
while( j < len-3 )
{
if( dname[j] == '_' )
{
menuentry[j] = ' ' ;
}
else
{
menuentry[j] = dname[j] ;
}
j++ ;
};
menuentry[len-3] = 0 ;
// check for the "_w" "_W" and "_h" "_H" at the end of
// filename before the extension.
// if found omit them from the menu entry
if( dname[len-5] == '_' )
{
if( ( dname[len-4] == 'w' )
|| ( dname[len-4] == 'W' )
|| ( dname[len-4] == 'h' )
|| ( dname[len-4] == 'H' )
)
{
menuentry[len-5] = 0 ;
}
}
menuentry[0] = (char)toupper( (int)menuentry[0] ) ;
// SJGDEBUGF( "menuentry = [%s]", menuentry ) ;
}
fprintf( newscript, "(script-fu-register \"sjgopencl-%.*s\"\n", len-3, dname ) ;
fprintf( newscript, " \"<Image>/Filters/Open CL/%s\"\n", menuentry ) ;
fprintf( newscript, SJG_MESSAGE_005, dname ) ;
fprintf( newscript, " \"\"\n" ) ;
fprintf( newscript, SJG_MESSAGE_006 ) ;
fprintf( newscript, SJG_MESSAGE_007 ) ;
fprintf( newscript, " \"\"\n" ) ;
fprintf( newscript, " SF-IMAGE \"Image\" 0\n" ) ;
fprintf( newscript, " SF-DRAWABLE \"Drawable\" 0\n" ) ;
// SJGDEBUG() ;
// SJGDEBUGF( "paramnames = %p", paramnames ) ;
guchar *pp = NULL ;
for( k = 0 ; k < paramcount ; k++ )
{
// SJGDEBUGF( "paramnames[k] = %p", paramnames[k] ) ;
pp = paramnames[k] ;
fprintf( newscript, " SF-VALUE \"%s\" \"%s\"\n", pp, (pp+maxlen+1) ) ;
}
fprintf( newscript, ")\n\n" ) ;
// tidy up
fflush( newscript ) ;
fclose( newscript ) ;
if( paramnames != NULL )
{
g_free_safe( paramnames ) ;
paramnames = NULL ;
}
}
}
else
{
SJGDEBUGF( SJG_MESSAGE_008, fname ) ;
}
};
// close the directory
g_dir_close( dirh ) ;
}
errexit:
g_free_safe( oclpath ) ;
// SJGDEBUGMSG( "Finished Init." ) ;
debug_finish_log() ;
}
/***********************************************************************************
*/
static void quit()
{
SJGDEBUGF( SJG_MESSAGE_009, PLUG_IN_NAME ) ;
}
/***********************************************************************************
*/
static void query()
{
static GimpParamDef args[] = {
{
GIMP_PDB_INT32,
"run-mode",
SJG_MESSAGE_010
},
{
GIMP_PDB_IMAGE,
"image",
SJG_MESSAGE_011
},
{
GIMP_PDB_DRAWABLE,
"drawable",
SJG_MESSAGE_012
},
{
GIMP_PDB_STRING,
"filename",
SJG_MESSAGE_013
},
{
GIMP_PDB_INT32,
"arraycount",
SJG_MESSAGE_014
},
{
GIMP_PDB_FLOATARRAY,
"array",
SJG_MESSAGE_015
}
};
gimp_install_procedure(
PLUG_IN_NAME,
SJG_MESSAGE_016,
SJG_MESSAGE_017,
PLUG_IN_AUTHOR,
SJG_MESSAGE_018 PLUG_IN_AUTHOR,
SJG_MESSAGE_019,
SJG_MESSAGE_020,
"RGB*",
GIMP_PLUGIN,
G_N_ELEMENTS (args), 0,
args, NULL
) ;
gimp_plugin_menu_register(PLUG_IN_NAME, SJG_MESSAGE_021 ) ;
}
/***********************************************************************************
*/
static gint32 drawableid = -1 ;
static GimpDrawable *drawable = NULL ;
static char *prepend_buffer = "\n" \
"union uf_u {\n" \
" int \t" \
"i ;\n" \
" float f ;\n" \
"\t} ;\n" \
"\n" \
"typedef union uf_u uf_t ;\n\n" \
"#define PARAMF(idx) ( cons[(idx)+4].f )\n" \
"#define PARAMI(idx) ( cons[(idx)+4].i )\n\n" \
"#define WIDTH (cons[0].i)\n" \
"#define HEIGHT (cons[1].i)\n\n" ;
#ifdef DEBUGME
# define DEFAULT_COMPILER_OPTIONS "-g -cl-opt-disable"
#else
# define DEFAULT_COMPILER_OPTIONS "-cl-single-precision-constant " \
"-cl-mad-enable " \
"-cl-no-signed-zeros " \
"-cl-fast-relaxed-math"
#endif
struct oclbuffer_s ;
struct oclbuffer_s {
struct oclbuffer_s *next ;
guint flags ;
char *hostptr ;
cl_mem clmemref ;
size_t buffersize ;
guchar name[128] ;
} ;
typedef struct oclbuffer_s oclbuffer_t ;
#define OCL_FLAG_NONE 1
#define OCL_FLAG_R 2
#define OCL_FLAG_W 4
#define OCL_FLAG_GLOBAL 8
#define OCL_FLAG_LOCAL 16
#define OCL_FLAG_CONST 32
#define OCL_FLAG_LAYER 64
#define OCL_FLAG_MASK 128
#define OCL_FLAG_READ OCL_FLAG_R
#define OCL_FLAG_WRITE OCL_FLAG_W
#define OCL_FLAG_RW ( OCL_FLAG_READ | OCL_FLAG_WRITE )
static inline void init_oclbuffer( oclbuffer_t *ocp )
{
ocp->next = NULL ;
ocp->flags = OCL_FLAG_NONE ;
ocp->hostptr = NULL ;
ocp->clmemref = NULL ;
ocp->buffersize = 0 ;
ocp->name[0] = 0 ;
}
#define add_new_oclbuffer( newflags, ptr, size, newname ) \
{ \
ocp = (oclbuffer_t *)alloca( sizeof(oclbuffer_t) ) ; \
CHECKPTR(ocp) ; \
\
ocp->clmemref = NULL ; \
ocp->flags = (newflags) ; \
ocp->hostptr = (char *)((ptr)) ; \
ocp->buffersize = (size) ; \
strncpy( (char *)(ocp->name), (char *)(newname), sizeof(ocp->name) ) ; \
\
slist_add( buffer_list, ocp ) ; \
}
static inline void dump_oclbuffer_list( oclbuffer_t *root )
{
oclbuffer_t *this ;
int i = 0 ;
this = root ;
while( this != NULL )
{
SJGDEBUGF( "Buffer %d :: name = [ %s ] :: size = %zd :: ptr = %p", i, this->name, this->buffersize, this->hostptr ) ;
this = this->next ;
i++ ;
};
}
/* maintain a list of kernels
*/
struct oclkernel_s ;
struct oclkernel_s {
struct oclkernel_s *next ;
cl_kernel kernel ;
char name[sizeof(sclSoft)] ;
} ;
typedef struct oclkernel_s oclkernel_t ;
/* A list of arguments to the current kernel
*/
struct oclarg_s ;
struct oclarg_s {
struct oclarg_s *next ;
oclbuffer_t *buffer ;
} ;
typedef struct oclarg_s oclarg_t ;
#define get_firstentry(_tag) check_for_firstentry( handlep, (_tag), tmpbuf, MAXPATHLEN )
/* Some OpenCL shorthand macros and functions
*/
#define clgetinfo( item, infoid, fn, type, msgfmt ) \
{ \
type tmpthing ; \
\
cl_int tmperr ; \
\
tmperr = clGet ## fn ## Info( (item), (infoid), sizeof(tmpthing), (void *)&tmpthing, NULL ) ; \
\
if( tmperr == CL_SUCCESS ) \
{ \
SJGDEBUGF( (msgfmt), (item), (tmpthing) ) ; \
} \
else \
{ \
SJGDEBUGF( SJG_MESSAGE_022 #type " %p", (item) ) ; \
\
CLDEBUG(tmperr) ; \
} \
}
static inline void check_clmemref( cl_mem clm )
{