We'd hoped to keep contexts completely transparent to the user but as more users attempt multi-GPU set-ups with CUDAfy we've needed to expose this a little. Maybe it needs to go further but let's see how this works out for now.

If you build from the latest sources you will see a new method added to GPGPU called SetCurrentContext. This must be called when switching between GPGPUs.

Important to remember is that creating a GPGPU using GetDevice will set the current context to the new context that is generated for every new device. You can check if your context is current to a device via the GPGPU.IsCurrentContext property. If this is false then call SetCurrentContext before doing anything with that GPGPU.

If you look at MultiGPUTests.cs you'll see a new unit test that illustrates the usage (plus the new CopyDeviceToDevice method):
        public void Test_SingleThreadGPUtoGPU()
            Random r = new Random();
            for (int i = 0; i < _uintBufferIn0.Length; i++)
                _uintBufferIn0[i] = (uint)r.Next(Int32.MaxValue);

            _gpuuintBufferIn0 = _gpu0.CopyToDevice(_uintBufferIn0);
            _gpuuintBufferIn1 = _gpu1.CopyToDevice(_uintBufferIn1);
            int loops = 100;
            Stopwatch sw = Stopwatch.StartNew();

            for (int i = 0; i < loops; i++)
                _gpu0.CopyDeviceToDevice(_gpuuintBufferIn0, 0, _gpu1, _gpuuintBufferIn1, 0, _uintBufferIn0.Length);

            float mbps = (float)(_uintBufferIn0.Length * sizeof(int) * loops) / (float)(sw.ElapsedMilliseconds * 1000);
            _gpu1.CopyFromDevice(_gpuuintBufferIn1, _uintBufferOut1);

            Assert.IsTrue(Compare(_uintBufferIn0, _uintBufferOut1));

Last edited Jun 20, 2012 at 2:31 PM by NickKopp, version 1


No comments yet.