You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A new high-level interface to OpenCL has been added to FAST in version 4.16.0
This makes it easy to implement GPU processing algorithms directly in Python using very little code. A tutorial on this interface has been added to the documentation page.
The same interface is also available from C++.
Here is a quick example from the documentation which inverts a uint8 image on the GPU:
importfastclassOpenCLInverter(fast.PythonProcessObject):
""" A python process object which simply inverts an uint8 image with OpenCL """def__init__(self):
super().__init__()
self.createInputPort(0)
self.createOutputPort(0)
# Create an image invert OpenCL kernel inline:self.createInlineOpenCLProgram(
''' __const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_NEAREST | CLK_ADDRESS_NONE; __kernel void invert( __read_only image2d_t input, __write_only image2d_t output ) { int2 pos = {get_global_id(0), get_global_id(1)}; int value = read_imageui(input, sampler, pos).x; write_imageui(output, pos, 255 - value); } '''
)
defexecute(self):
# Get input image and create output image:image=self.getInputData()
outputImage=fast.Image.createFromImage(image)
# Get kernel from OpenCL programkernel=self.getKernel('invert')
# Provide arguments to the kernelkernel.setArg('input', image)
kernel.setArg('output', outputImage)
# Add the kernel to the command queueself.getQueue().add(kernel, image.getSize())
# Pass on the output imageself.addOutputData(0, outputImage)
# Set up pipeline as normal# Stream some ultrasound dataimporter=fast.ImageFileStreamer.create(
fast.Config.getTestDataPath() +'US/Heart/ApicalFourChamber/US-2D_#.mhd',
loop=True,
framerate=40,
)
# Set up the Inverter process objectinverter=OpenCLInverter.create().connect(importer)
# Run pipeline and displayfast.display2D(inverter)
This OpenCL interface might change in the future, and any feedback on the interface is appreciated.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
A new high-level interface to OpenCL has been added to FAST in version 4.16.0
This makes it easy to implement GPU processing algorithms directly in Python using very little code.
A tutorial on this interface has been added to the documentation page.
The same interface is also available from C++.
Here is a quick example from the documentation which inverts a uint8 image on the GPU:
This OpenCL interface might change in the future, and any feedback on the interface is appreciated.
Beta Was this translation helpful? Give feedback.
All reactions