Hi Namik, > I'm currently implementing the platform and device chooser, and could > use some help. > > So far I've managed to create custom contexts for each device. I iterate > through all available platforms, and setup a new context for every > device in a platform. Here's how that looks: > > //---PLATFORMS--- > platforms_type platforms = viennacl::ocl::get_platforms(); > long platformCounter = 1; > for(platforms_type::iterator platform_iter = platforms.begin(); > platform_iter != platforms.end(); ++platform_iter){ > > //---DEVICES--- > devices_type devices = platform_iter->devices(CL_DEVICE_TYPE_ALL); > for(devices_type::iterator iter = devices.begin(); iter != > devices.end(); iter++){ > > viennacl::ocl::setup_context( platformCounter, *iter ); > > } //END---DEVICES--- > > platformCounter++; > } //END---PLATFORMS---
Most importantly, it is necessary to run the context setup before any of the ViennaCL objects are created. Also, setup_context() takes the context ID as the first argument, not the platform ID. > Then I bind each context/device to a combo box in the UI, and switch > between contexts/devices like this: > viennacl::ocl::switch_context(contextNumber); > viennacl::ocl::current_context().switch_device(deviceNumber); You only have one device per context, so there is no need to switch the device. 'deviceNumber' will always be zero if you only have one device per context. Remove the second line. > There's a couple of problems: > > *(-1-)* It doesn't work. Switching contexts and devices by using the UI > seems to work alright, but it crashes when running a benchmark. When it > crashes, it gives the following feedback: > > -the source code of the program it was currently running; > -ViennaCL: FATAL ERROR: Kernel start failed for 'vec_mul'.; > -ViennaCL: Smaller work sizes could not solve the problem.; > -terminate called after throwing an instance of > 'viennacl::ocl::invalid_program_executable' > what(): ViennaCL: FATAL ERROR: CL_INVALID_PROGRAM_EXECUTABLE.; > -my screen flickers on and off while it is crashing; > -and my antivirus pops up telling me it detected a malicious dll (always > a random openCL-related dll) > -finally, it crashes This error might be due to the ViennaCL-objects created in a different context. Do you recreate the ViennaCL-objects for each benchmark run? If so, there should be no such problem. > Now comes the *very* interesting part. I've got an Intel i5 2500k CPU & > an AMD 7950 Radeon GPU. That means I've got 3 contexts to choose from: > 1. AMD: GPU > 2. AMD: CPU > 3. Intel: CPU > > I get different behavior for each context: > 1. AMD: GPU - no crash. Benchmark completes successfully with screen > flicker between each sub-test in a benchmark. (The screen flicker might > actually be a large console window quickly disappearing, can't say for > sure). ViennCL spits out the program source code to the console. Anti > virus pops a dll threat detected window. After choosing to ignore the > threat, the benchmark can then be properly re-run with no issues whatsoever. > The same procedure applies when running benchmark with different precision. > > 2. AMD: CPU - crash. This is the crash that I initially described, under > *(-1-)* These issues might be due to setting the device incorrectly. Did you compile this in debug mode? There should be some asserts for protection against invalid arguments... > 3. Intel: CPU - no issues whatsoever. Benchmark runs and finishes fine > using both precisions. Here you only have one device, so nothing can go wrong. > So, what did I mess up? From your explanation I think it is the device selection. > It's worth noting that I do the context/device switching as soon as an > appropriate option has been selected with the UI combo box. I hope the user can't change the combo box values while the benchmark is running... > It's also worth noting that I don't know in what way are platforms > selected. Let me describe this in the next section. > > *(-2-)*Sure I iterate through all platforms and create unique contexts > for each platform/device combo, but I'm not so sure the correct platform > has actually been selected. That is, I'm not sure if I am *really* using > a different platform, or all three contexts are bound to the same > platform. Was I supposed to do something special when calling > viennacl::ocl::setup_context( platformCounter, *iter );? Ok, here's how it should work: context_ctr = 0; platforms_type platforms = viennacl::ocl::get_platforms(); for (platform_id = 0; platform_id < platforms.size(); ++platform_id ) { devices_type devices = platform_iter->devices(CL_DEVICE_TYPE_ALL); for(devices_type::iterator iter = devices.begin(); iter != devices.end(); iter++) { viennacl::ocl::set_context_platform_index(context_ctr, platform_id); viennacl::ocl::setup_context(context_ctr, *iter); ++context_ctr; } } For you case of a system with AMD GPU and both Intel and AMD SDKs installed, this gives you: Context 0: AMD GPU using AMD SDK Context 1: CPU using AMD SDK Context 2: CPU using Intel SDK (assuming that the AMD SDK is platform 0) Now you should be able to switch context as needed via viennacl::ocl::switch_context(0); // AMD GPU viennacl::ocl::switch_context(1); // CPU with AMD SDK viennacl::ocl::switch_context(2); // CPU with Intel SDK If you still run into issues, please let us know, then this requires fixing in ViennaCL. > *(-3-)*I couldn't find a way to prevent ViennaCL from creating its own > context. In the manual is says: Unless specified otherwise (see Chap. > 10), ViennaCL silently creates its own context and > adds all available default devices with a single queue per device to it. Have a look at examples/tutorial/custom-context.cpp on how to provide your own contexts. > I looked at Chap. 10, but didn't find a way to disable the auto context > creation. I wish to disable it because it would make interaction with > the UI a lot easier. Since the auto(0) context fails to add all devices, > and I'm creating additional contexts (and one of those is bound to be > the same as the one automatically created) , that complicates things > when interacting with the UI. Can you provide a test case where the code silently creates a context even though it should not? If you really want to manage your own context and stuff, you will add a lot of (imho unnecessary) code to the GUI just for managing the OpenCL layer. Keep in mind that the code with the least maintenance effort is the code which isn't there... > It would be much easier if I could just take care of contexts on my own. > Can this be done? Yes, it can be done, but you really should *not* do this, since you are not running any OpenCL operations outside ViennaCL. Best regards, Karli ------------------------------------------------------------------------------ _______________________________________________ ViennaCL-devel mailing list ViennaCL-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/viennacl-devel