@@ -190,7 +190,6 @@ public static Pair<Map<CLDevice, byte[]>, String> readBinaries(List<CLDevice> al
190190
191191 ZipInputStream zin = new ZipInputStream (new GZIPInputStream (new BufferedInputStream (in )));
192192 ZipEntry ze ;
193-
194193 String source = null ;
195194
196195 boolean first = true ;
@@ -269,17 +268,19 @@ public synchronized void allocate() {
269268
270269 #declareReusablePtrsAndPErr ()
271270 long program ;
272- int previousAttempts = 0 ;
273- Pointer <Pointer <Byte >> pSources = pointerToCStrings (sources );
274- do {
275- program = CL .clCreateProgramWithSource (
276- context .getEntity (),
277- sources .length ,
278- getPeer (pSources ),
279- getPeer (pLengths ),
280- getPeer (pErr )
281- );
282- } while (failedForLackOfMemory (pErr .getInt (), previousAttempts ++));
271+ int previousAttempts = 0 ;
272+ Pointer <Pointer <Byte >> pSources = pointerToCStrings (sources );
273+ do {
274+ program = CL .clCreateProgramWithSource (
275+ context .getEntity (),
276+ sources .length ,
277+ getPeer (pSources ),
278+ getPeer (pLengths ),
279+ getPeer (pErr )
280+ );
281+ } while (failedForLackOfMemory (pErr .getInt (), previousAttempts ++));
282+ Pointer .release (pSources );
283+ Pointer .release (pLengths );
283284 setEntity (program );
284285 }
285286
@@ -688,22 +689,27 @@ protected String computeCacheSignature() throws IOException {
688689 "os.version" ,
689690 "os.name"
690691 };
691-
692- protected Set <String > getProgramBuildInfo (long pgm , Pointer <SizeT > deviceIds ) {
693- Pointer <SizeT > len = allocateSizeT ();
694- int bufLen = 2048 * 32 ; //TODO find proper size
695- Pointer <?> buffer = allocateBytes (bufLen );
696-
692+
693+ private String getProgramBuildInfo (long pgm , long deviceId ) {
694+ Pointer <SizeT > pLen = allocateSizeT ();
695+ error (CL .clGetProgramBuildInfo (pgm , deviceId , CL_PROGRAM_BUILD_LOG , 0 , 0 , getPeer (pLen )));
696+ long len = pLen .getSizeT ();
697+ Pointer <?> buffer = allocateBytes (len );
698+ error (CL .clGetProgramBuildInfo (pgm , deviceId , CL_PROGRAM_BUILD_LOG , len , getPeer (buffer ), 0 ));
699+ String s = buffer .getCString ();
700+ Pointer .release (pLen );
701+ Pointer .release (buffer );
702+ return s ;
703+ }
704+ private Set <String > getProgramBuildInfo (long pgm , Pointer <SizeT > deviceIds ) {
697705 Set <String > errs = new HashSet <String >();
698706 if (deviceIds == null ) {
699- error (CL .clGetProgramBuildInfo (pgm , 0 , CL_PROGRAM_BUILD_LOG , bufLen , getPeer (buffer ), getPeer (len )));
700- String s = buffer .getCString ();
707+ String s = getProgramBuildInfo (pgm , 0 );
701708 if (s .length () > 0 )
702709 errs .add (s );
703710 } else {
704711 for (SizeT device : deviceIds ) {
705- error (CL .clGetProgramBuildInfo (pgm , device .longValue (), CL_PROGRAM_BUILD_LOG , bufLen , getPeer (buffer ), getPeer (len )));
706- String s = buffer .getCString ();
712+ String s = getProgramBuildInfo (pgm , device .longValue ());
707713 if (s .length () > 0 )
708714 errs .add (s );
709715 }
@@ -763,20 +769,21 @@ public synchronized CLProgram build() throws CLBuildException {
763769 }
764770 Pointer <Byte > pOptions = pointerToCString (getOptionsString ());
765771 int err = CL .clBuildProgram (
766- getEntity (),
767- nDevices ,
768- getPeer (deviceIds ),
769- getPeer (pOptions ),
770- 0 ,
771- 0
772+ getEntity (),
773+ nDevices ,
774+ getPeer (deviceIds ),
775+ getPeer (pOptions ),
776+ 0 ,
777+ 0
772778 );
779+ Pointer .release (pOptions );
773780 Set <String > errors = getProgramBuildInfo (getEntity (), deviceIds );
774781
775782 if (err != CL_SUCCESS ) {
776783 throw new CLBuildException (this , "Compilation failure : " + errorString (err ) + " (devices: " + Arrays .asList (getDevices ()) + ")" , errors );
777784 } else {
778- if (!errors .isEmpty ())
779- JavaCL .log (Level .INFO , "Build info :\n \t " + StringUtils .implode (errors , "\n \t " ));
785+ if (!errors .isEmpty ())
786+ JavaCL .log (Level .INFO , "Build info :\n \t " + StringUtils .implode (errors , "\n \t " ));
780787 }
781788 built = true ;
782789 if (deleteTempFiles != null )
@@ -785,11 +792,11 @@ public synchronized CLProgram build() throws CLBuildException {
785792 if (isCached () && !readBinaries && !loadedFromBinary ) {
786793 JavaCL .userCacheDir .mkdirs ();
787794 try {
788- Map <CLDevice , byte []> binaries = getBinaries ();
789- if (!binaries .isEmpty ()) {
790- writeBinaries (getBinaries (), getSource (), contentSignature , new FileOutputStream (cacheFile ));
791- assert log (Level .INFO , "Wrote binaries cache to '" + cacheFile + "'" );
792- }
795+ Map <CLDevice , byte []> binaries = getBinaries ();
796+ if (!binaries .isEmpty ()) {
797+ writeBinaries (getBinaries (), getSource (), contentSignature , new FileOutputStream (cacheFile ));
798+ assert log (Level .INFO , "Wrote binaries cache to '" + cacheFile + "'" );
799+ }
793800 } catch (Exception ex ) {
794801 new IOException ("[JavaCL] Failed to cache program" , ex ).printStackTrace ();
795802 }
@@ -844,6 +851,7 @@ public CLKernel createKernel(String name, Object... args) throws CLBuildExceptio
844851 do {
845852 kernel = CL .clCreateKernel (getEntity (), getPeer (pName ), getPeer (pErr ));
846853 } while (failedForLackOfMemory (pErr .getInt (), previousAttempts ++));
854+ Pointer .release (pName );
847855
848856 CLKernel kn = new CLKernel (this , name , kernel );
849857 if (args .length != 0 )
0 commit comments