コード例 #1
0
        public void Copy(CudaDeviceVector deviceVector, CudaHostVector hostVector)
        {
            if (hostVector == null)
            {
                throw new ArgumentNullException("hostVector");
            }
            if (deviceVector == null)
            {
                throw new ArgumentNullException("deviceVector");
            }
            if (hostVector.Length != deviceVector.Length)
            {
                throw new ArgumentException("Vector lengths should be equal.");
            }

            CudaMemoryImports.CudaGetVector(hostVector.Length, sizeof(float), deviceVector.DevicePointer, deviceVector.ElementSpacing,
                hostVector.PageLockedPointer, hostVector.ElementSpacing, this.stream.StreamId.Value);
        }
コード例 #2
0
        public void GenerateUniformTest()
        {
            using (CudaSharpStream stream = new CudaSharpStream())
            {
                CudaRandom target = stream.Random;
                using (CudaDeviceVector deviceVector = new CudaDeviceVector(100000))
                {
                    using (CudaHostVector hostVector = new CudaHostVector(100000))
                    {
                        target.GenerateUniform(deviceVector);
                        stream.MemoryManagement.Copy(deviceVector, hostVector);
                        stream.Synchronize();

                        Assert.IsTrue(hostVector[100] > 0);
                    }
                }
            }
        }
コード例 #3
0
 public void CopyVectorTest()
 {
     using (CudaSharpStream str = new CudaSharpStream())
     {
         CudaMemoryManagement target = str.MemoryManagement;
         using (CudaDeviceVector deviceVector = new CudaDeviceVector(5))
         {
             using (CudaHostVector hostVector = new CudaHostVector(5))
             {
                 hostVector[2] = 3;
                 using (CudaHostVector hostVector2 = new CudaHostVector(5))
                 {
                     target.Copy(hostVector, deviceVector);
                     target.Copy(deviceVector, hostVector2);
                     str.Synchronize();
                     Assert.AreEqual(3, hostVector2[2]);
                 }
             }
         }
     }
 }
コード例 #4
0
        public void ScalarMultiplicationTest()
        {
            using (CudaSharpStream stream = new CudaSharpStream())
            {
                CudaAlgebra target = stream.Algebra;
                using (CudaHostVector hostVector = new CudaHostVector(50000))
                {
                    using (CudaDeviceVector deviceVector = new CudaDeviceVector(50000))
                    {
                        using (CudaHostScalar hostScalar = new CudaHostScalar(3))
                        {
                            hostVector[2] = 3;

                            stream.MemoryManagement.Copy(hostVector, deviceVector);
                            target.ScalarMultiplication(deviceVector, hostScalar);
                            stream.MemoryManagement.Copy(deviceVector, hostVector);
                            stream.Synchronize();

                            Assert.AreEqual(9, hostVector[2]);
                        }
                    }
                }
            }
        }
コード例 #5
0
 public ScalarCollection(CudaHostVector that)
 {
     this.that = that;
 }