コード例 #1
0
        public void Test_SingleThreadGPUtoGPU()
        {
            if (!_gpu0.CanAccessPeer(_gpu1))
            {
                Console.WriteLine("Device not supporting this, so skip.");
                return;
            }
            Random r = new Random();

            for (int i = 0; i < _uintBufferIn0.Length; i++)
            {
                _uintBufferIn0[i] = (uint)r.Next(Int32.MaxValue);
            }

            _gpu0.SetCurrentContext();
            _gpuuintBufferIn0 = _gpu0.CopyToDevice(_uintBufferIn0);
            _gpu1.SetCurrentContext();
            _gpuuintBufferIn1 = _gpu1.CopyToDevice(_uintBufferIn1);

            _gpu0.SetCurrentContext();
            long      loops = 500;
            Stopwatch sw    = Stopwatch.StartNew();

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

            float mbps = (float)((long)_uintBufferIn0.Length * sizeof(int) * loops) / (float)(sw.ElapsedMilliseconds * 1000);

            Console.WriteLine(mbps);
            _gpu1.SetCurrentContext();
            _gpu1.CopyFromDevice(_gpuuintBufferIn1, _uintBufferOut1);

            Assert.IsTrue(Compare(_uintBufferIn0, _uintBufferOut1));
            ClearOutputsAndGPU(0);
            ClearOutputsAndGPU(1);
        }