uygn / aparapi

Automatically exported from code.google.com/p/aparapi
Other
0 stars 0 forks source link

Wiki about using multiple devices seems out of sync with code #109

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. visit 
http://code.google.com/p/aparapi/wiki/ChoosingSpecificDevicesForExecution

2. The example code shown in the page does not exist in the repo

3.

What is the expected output? What do you see instead?

Please use labels and text to provide additional information.

Original issue reported on code.google.com by ecasp...@gmail.com on 24 Apr 2013 at 3:23

GoogleCodeExporter commented 9 years ago
Correct ;) The Wiki is indeed out of date. 

Rather than having folks loop through all devices, I created API's for 
selecting/comparing device capabilities. 

For example you can create a device selector (uses the first device instance 
returned as non null from select(device)).

   OpenCLDevice firstAMD = OpenCLDevice.select(new OpenCLDevice.DeviceSelector() {
             public OpenCLDevice select(OpenCLDevice d) {
                 return((d.getPlatform().getVendor().contains("AMD"))?d : null);
             }
         });

or of course if you are using Java 8 ;) DeviceSelector is a SAM type, so we can 
use a lambda ;) 

 OpenCLDevice amdDevice =  OpenCLDevice.select(
    d->{return((d.getPlatform().getVendor().contains("AMD"))?d : null);});

We also have a device comparitor, where the comparitor returns the preferable 
of two given devices. 

So to select the device with the largest local memory we can use

OpenCLDevice maxLocalMemory = OpenCLDevice.select(
   (lhs, rhs)->{return(lhs.getLocalMemSize()>rhs.getLocalMemSize()?lhs:rhs);});

Or

OpenCLDevice maxLocalMemory = OpenCLDevice.select(new 
OpenCLDevice.DeviceComparitor(){
   public OpenCLDevice select(OpenCLDevice lhs, OpenCLDevice rhs){
       return(lhs.getLocalMemSize()>rhs.getLocalMemSize()?lhs:rhs);
   }
});

I will update the Wiki.

Original comment by frost.g...@gmail.com on 24 Apr 2013 at 3:40

GoogleCodeExporter commented 9 years ago

Original comment by ecasp...@gmail.com on 24 Apr 2013 at 4:00