Commits

David Lin committed f7cc667

add

  • Participants
  • Parent commits 7715c0a
  • Branches profiling

Comments (0)

Files changed (4)

www/js/app/fx/grayscale.js

                    channelDataType: WebCL.CL_UNORM_INT8 }
     var imgIn = ctx.createImage2D(WebCL.CL_MEM_READ_ONLY, format, src.width, src.height, 0);
     var imgOut = ctx.createImage2D(WebCL.CL_MEM_WRITE_ONLY, format, src.width, src.height, 0);
-    fx.dispatchWriteImage2D(imgIn, src.data);
+    var evtWrite = fx.dispatchWriteImage2D(imgIn, src.data);
+    WebCL.waitForEvents([evtWrite]);
+    (function(){
+      var d = evtWrite.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_END) - 
+              evtWrite.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_START);
+      console.log("Write Event: " + d + " ns");
+    })();
     var kernel = fx.buildKernel(code);
     kernel.setKernelArg(0, imgIn);
     kernel.setKernelArg(1, imgOut);
-    fx.dispatchExecution2D(kernel, src.width, src.height);
+    var evtCompute = fx.dispatchExecution2D(kernel, src.width, src.height);
+    WebCL.waitForEvents([evtCompute]);
+    (function(){
+      var d = evtCompute.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_END) - 
+              evtCompute.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_START);
+      console.log("Compute Event: " + d + " ns");
+    })();
     var canvas = outputCanvasElement();
     canvas.width = src.width;
     canvas.height = src.height;
     var canvasCtx = canvas.getContext('2d');
     var result = canvasCtx.createImageData(src.width, src.height);
-    fx.dispatchReadImage2D(imgOut, result.data);
+    var evtRead = fx.dispatchReadImage2D(imgOut, result.data);
+    WebCL.waitForEvents([evtRead]);
+    (function(){
+      var d = evtRead.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_END) - 
+              evtRead.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_START);
+      console.log("Read Event: " + d + " ns");
+    })();
     cmd.finish();
     canvasCtx.putImageData(result, 0, 0);
     imgIn.releaseCLResources();

www/js/app/fx/invert.js

                    channelDataType: WebCL.CL_UNORM_INT8 }
     var imgIn = ctx.createImage2D(WebCL.CL_MEM_READ_ONLY, format, src.width, src.height, 0);
     var imgOut = ctx.createImage2D(WebCL.CL_MEM_WRITE_ONLY, format, src.width, src.height, 0);
-    fx.dispatchWriteImage2D(imgIn, src.data);
+    var evtWrite = fx.dispatchWriteImage2D(imgIn, src.data);
+    WebCL.waitForEvents([evtWrite]);
+    (function(){
+      var d = evtWrite.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_END) - 
+              evtWrite.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_START);
+      console.log("Write Event: " + d + " ns");
+    })();
     var kernel = fx.buildKernel(code);
     kernel.setKernelArg(0, imgIn);
     kernel.setKernelArg(1, imgOut);
-    fx.dispatchExecution2D(kernel, src.width, src.height);
+    var evtCompute = fx.dispatchExecution2D(kernel, src.width, src.height);
+    WebCL.waitForEvents([evtCompute]);
+    (function(){
+      var d = evtCompute.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_END) - 
+              evtCompute.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_START);
+      console.log("Compute Event: " + d + " ns");
+    })();
     var canvas = outputCanvasElement();
     canvas.width = src.width;
     canvas.height = src.height;
     var canvasCtx = canvas.getContext('2d');
     var result = canvasCtx.createImageData(src.width, src.height);
-    fx.dispatchReadImage2D(imgOut, result.data);
+    var evtRead = fx.dispatchReadImage2D(imgOut, result.data);
+    WebCL.waitForEvents([evtRead]);
+    (function(){
+      var d = evtRead.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_END) - 
+              evtRead.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_START);
+      console.log("Read Event: " + d + " ns");
+    })();
     cmd.finish();
     canvasCtx.putImageData(result, 0, 0);
     imgIn.releaseCLResources();

www/js/app/fx/pixelize.js

                    channelDataType: WebCL.CL_UNORM_INT8 }
     var imgIn = ctx.createImage2D(WebCL.CL_MEM_READ_ONLY, format, src.width, src.height, 0);
     var imgOut = ctx.createImage2D(WebCL.CL_MEM_WRITE_ONLY, format, src.width, src.height, 0);
-    fx.dispatchWriteImage2D(imgIn, src.data);
+    var evtWrite = fx.dispatchWriteImage2D(imgIn, src.data);
+    WebCL.waitForEvents([evtWrite]);
+    (function(){
+      var d = evtWrite.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_END) - 
+              evtWrite.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_START);
+      console.log("Write Event: " + d + " ns");
+    })();
     var kernel = fx.buildKernel(code);
     kernel.setKernelArg(0, imgIn);
     kernel.setKernelArg(1, imgOut);
     kernel.setKernelArg(2, $("#param-block_size")[0].value, WebCL.types.INT);
-    fx.dispatchExecution2D(kernel, src.width, src.height);
+    var evtCompute = fx.dispatchExecution2D(kernel, src.width, src.height);
+    WebCL.waitForEvents([evtCompute]);
+    (function(){
+      var d = evtCompute.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_END) - 
+              evtCompute.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_START);
+      console.log("Compute Event: " + d + " ns");
+    })();
     var canvas = outputCanvasElement();
     canvas.width = src.width;
     canvas.height = src.height;
     var canvasCtx = canvas.getContext('2d');
     var result = canvasCtx.createImageData(src.width, src.height);
-    fx.dispatchReadImage2D(imgOut, result.data);
+    var evtRead = fx.dispatchReadImage2D(imgOut, result.data);
+    WebCL.waitForEvents([evtRead]);
+    (function(){
+      var d = evtRead.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_END) - 
+              evtRead.getEventProfilingInfo(WebCL.CL_PROFILING_COMMAND_START);
+      console.log("Read Event: " + d + " ns");
+    })();
     cmd.finish();
     canvasCtx.putImageData(result, 0, 0);
     imgIn.releaseCLResources();

www/js/app/fx/shared.js

   //
   var devices = context.getContextInfo(WebCL.CL_CONTEXT_DEVICES);
   var device = devices[0];
-  var commandQueue = context.createCommandQueue(device, 0);
+  var commandQueue = context.createCommandQueue(device, WebCL.CL_QUEUE_PROFILING_ENABLE);
   //
   function buildKernel(code, entryName = 'main')
   {
     var height = image.getImageInfo(WebCL.CL_IMAGE_HEIGHT);
     var o = [0,0,0]; // origin
     var d = [width, height, 1]; // dimensions
-    commandQueue.enqueueReadImage(image, false, o, d, 0, 0, data, []);
+    return commandQueue.enqueueReadImage(image, false, o, d, 0, 0, data, []);
   }
   //
   function dispatchWriteImage2D(image, data)
     var height = image.getImageInfo(WebCL.CL_IMAGE_HEIGHT);
     var o = [0,0,0]; // origin
     var d = [width, height, 1]; // dimensions
-    commandQueue.enqueueWriteImage(image, false, o, d, 0, 0, data, []);
+    return commandQueue.enqueueWriteImage(image, false, o, d, 0, 0, data, []);
   }
   
   //