-
Notifications
You must be signed in to change notification settings - Fork 35
Add TornadoVM GPU convolution backend support #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Pakhi-7831
wants to merge
1
commit into
sumit3203:master
Choose a base branch
from
Pakhi-7831:pr-1-backend
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,127 @@ | ||
| //package dsp; | ||
| // | ||
| //import dsp.gpu.ConvGpu; | ||
| //import dsp.cpu.Conv; | ||
| //import dsp.tornado.*; | ||
| //import ij.IJ; | ||
| // | ||
| //public class ConvFactory { | ||
| // private static boolean useGPU = false; | ||
| // private static ConvGpu gpuInstance = null; | ||
| // | ||
| // public static IConv createConv() { | ||
| // if (useGPU) { | ||
| // try { | ||
| // if (gpuInstance == null) { | ||
| // gpuInstance = new ConvGpu(); | ||
| // } | ||
| // return gpuInstance; | ||
| // } catch (Exception e) { | ||
| // IJ.log("GPU initialization failed, falling back to CPU: " + e.getMessage()); | ||
| // return new Conv(); | ||
| // } | ||
| // } else { | ||
| // return new Conv(); | ||
| // } | ||
| // } | ||
| // | ||
| // public static void cleanup() { | ||
| // if (gpuInstance != null) { | ||
| // gpuInstance.cleanup(); | ||
| // gpuInstance = null; | ||
| // } | ||
| // } | ||
| // | ||
| // public static void setUseGPU(boolean useGPU) { | ||
| // ConvFactory.useGPU = useGPU; | ||
| // } | ||
| // | ||
| // public static boolean isUsingGPU() { | ||
| // return useGPU; | ||
| // } | ||
| //} | ||
|
|
||
| package dsp; | ||
|
|
||
| import dsp.gpu.ConvGpu; | ||
| import dsp.cpu.Conv; | ||
| import dsp.tornado.ConvTornado; | ||
| import ij.IJ; | ||
|
|
||
| public class ConvFactory { | ||
| private static boolean useGPU = false; | ||
|
|
||
| //CH - instead of having two possibilities, added an enum to store three possibilities for now | ||
| // The three possible engines | ||
| public enum Backend { CPU, GPU, TORNADO } | ||
|
|
||
| // Which engine is currently selected (default CPU) | ||
| private static Backend backend = Backend.CPU; | ||
|
|
||
| // Reusable instances (so we don't recreate every time) | ||
| private static ConvGpu gpuInstance = null; | ||
| private static ConvTornado tornadoInstance = null; | ||
|
|
||
| public static IConv createConv() { | ||
| if (useGPU) { | ||
| try { | ||
| if (gpuInstance == null) { | ||
| gpuInstance = new ConvGpu(); | ||
| System.out.println("@@@@@ createConv CALLED, backend=" + backend); | ||
| switch (backend) { | ||
|
|
||
| case GPU: | ||
| try { | ||
| if (gpuInstance == null) { | ||
| gpuInstance = new ConvGpu(); | ||
| //CH - added logs for understanding purposes | ||
| System.out.println(">>> GPU: ConvGPU Instance created successfully"); | ||
| } | ||
| return gpuInstance; | ||
| } catch (Exception e) { | ||
| System.out.println("GPU failed, using CPU: " + e.getMessage()); | ||
| return new Conv(); | ||
| } | ||
|
|
||
| case TORNADO: | ||
| System.out.println("checker_1"); | ||
| try { | ||
| if (tornadoInstance == null) { | ||
| tornadoInstance = new ConvTornado(); | ||
| System.out.println(">>> Using ConvTornado"); | ||
| } | ||
| return tornadoInstance; | ||
| } catch (Exception e) { | ||
| System.out.println("Tornado failed, using CPU: " + e.getMessage()); | ||
| return new Conv(); | ||
| } | ||
| return gpuInstance; | ||
| } catch (Exception e) { | ||
| IJ.log("GPU initialization failed, falling back to CPU: " + e.getMessage()); | ||
|
|
||
| case CPU: | ||
| default: | ||
| return new Conv(); | ||
| } | ||
| } else { | ||
| return new Conv(); | ||
| } | ||
| } | ||
|
|
||
| public static void setBackend(Backend b) { | ||
| backend = b; | ||
| } | ||
|
|
||
| public static Backend getBackend() { | ||
| return backend; | ||
| } | ||
|
|
||
| public static void cleanup() { | ||
| if (gpuInstance != null) { | ||
| gpuInstance.cleanup(); | ||
| gpuInstance = null; | ||
| } | ||
| if (tornadoInstance != null) { | ||
| tornadoInstance.cleanup(); | ||
| tornadoInstance = null; | ||
| } | ||
| } | ||
|
|
||
| // CH - rewritten the following functions to reroute to tornado insteead of jcuda, and to read the value of backend to answer | ||
| public static void setUseGPU(boolean useGPU) { | ||
| ConvFactory.useGPU = useGPU; | ||
| backend=useGPU? Backend.TORNADO : Backend.CPU; | ||
| } | ||
|
|
||
| public static boolean isUsingGPU() { | ||
| return useGPU; | ||
| return backend != Backend.CPU; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My suggestion is to define a separate application Interface wehre you define the methods and then to inherit both interfaces. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a good idea to include void convolveStructGrad(FloatProcessor src, float[] kernx, float[] kern_diff1,
FloatProcessor gradx, FloatProcessor grady);
void convolveStructSmooth(float[] kernx, float[] kern_diff1,
FloatProcessor gx2, FloatProcessor gy2, FloatProcessor gxy) at the interface level. These are concrete applications.