当前位置: 首页>>代码示例>>C#>>正文


C# MyMemoryBlock.SafeCopyToHost方法代码示例

本文整理汇总了C#中MyMemoryBlock.SafeCopyToHost方法的典型用法代码示例。如果您正苦于以下问题:C# MyMemoryBlock.SafeCopyToHost方法的具体用法?C# MyMemoryBlock.SafeCopyToHost怎么用?C# MyMemoryBlock.SafeCopyToHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MyMemoryBlock的用法示例。


在下文中一共展示了MyMemoryBlock.SafeCopyToHost方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

 public override void Run(MatOperation operation, MyMemoryBlock<float> A, MyMemoryBlock<float> B, MyMemoryBlock<float> Result)
 {
     Result.Fill(.0f);
     switch (operation)
     {
         case MatOperation.EuclidDist:
             if (B.Count == A.ColumnHint)
             {
                 A.SafeCopyToHost();
                 B.SafeCopyToHost();
                 for (int row = 0; row < A.Count / A.ColumnHint; row++)
                 {
                     Result.Host[row] = 0;
                     for (int Bindex = 0; Bindex < B.Count; Bindex++)
                     {
                         Result.Host[row] += (B.Host[Bindex] - A.Host[A.ColumnHint * row + Bindex]) * (B.Host[Bindex] - A.Host[A.ColumnHint * row + Bindex]);
                     }
                     Result.Host[row] = (float)Math.Sqrt( (double) Result.Host[row] );
                     //System.Console.Write(" " + Result.Host[row]);
                 }
                 Result.SafeCopyToDevice();
             }
             break;
         default:
             MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run cpu mat ops. for undefined MatOperation");
             break;
     }
 }
开发者ID:Jlaird,项目名称:BrainSimulator,代码行数:28,代码来源:MyMatrixCPUOps.cs

示例2: Run

 public override void Run(MatOperation operation, MyMemoryBlock<float> A, MyMemoryBlock<float> B, MyMemoryBlock<float> Result)
 {
     switch (operation)
     {
         case MatOperation.Multiplication:  // vectors/matrices have to be always in the correct dimesions!
             if (A.Count == 1) // valueA * B
             {
                 Result.Fill(.0f);
                 A.SafeCopyToHost();
                 MyCublasFactory.Instance.Axpy(A.Host[0], B.GetDevice(callee), 1, Result.GetDevice(callee), 1);
             }
             else if (B.Count == 1) // A * valueB
             {
                 Result.Fill(.0f);
                 B.SafeCopyToHost();
                 MyCublasFactory.Instance.Axpy(B.Host[0], A.GetDevice(callee), 1, Result.GetDevice(callee), 1);
             }
             else // another executions...
             {
                 Run(operation, A.GetDevice(callee), A.Count, A.ColumnHint, B.GetDevice(callee), B.Count, B.ColumnHint, Result.GetDevice(callee), Result.Count, Result.ColumnHint, 0);
             }
             break;
         case MatOperation.DotProd:
             Run(operation, A.GetDevice(callee), A.Count, A.ColumnHint, B.GetDevice(callee), B.Count, B.ColumnHint, Result.GetDevice(callee), Result.Count, Result.ColumnHint, 0);
             break;
         default:
             MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run cublas for undefined MatOperation");
             break;
     }
 }
开发者ID:Jlaird,项目名称:BrainSimulator,代码行数:30,代码来源:MyMatrixCublasOps.cs

示例3: NormalizeLeadingDim

        /// <summary>
        /// Normalizes vectors along the leading dimension.
        /// </summary>
        public static void NormalizeLeadingDim(
            MyMemoryBlock<float> vectors, MyMemoryBlock<float> temp,
            int leadingDim, int otherDim,
            MyProductKernel<float> dotKernel, MyCudaKernel multKernel, int GPU)
        {
            var count = leadingDim * otherDim;

            Debug.Assert(vectors != null && temp != null, "Missing data!");
            Debug.Assert(dotKernel != null && multKernel != null, "Missing kernels.");
            Debug.Assert(leadingDim > 0 && otherDim > 0, "Negative matrix dimensions!");
            Debug.Assert(vectors.Count >= count, "Too little vectors to orthonormalize!");
            Debug.Assert(temp.Count >= Math.Max(leadingDim, otherDim), "Too little temp space!");

            multKernel.SetupExecution(leadingDim);

            for (int i = 0; i < otherDim; i++)
            {
                var seg = vectors.GetDevicePtr(GPU, i * leadingDim);
                //dotKernel.Run(temp, i, seg, seg, leadingDim, /* distributed: */ 0);
                dotKernel.outOffset = i;
                dotKernel.Run(temp, seg, seg, leadingDim);
            }

            temp.SafeCopyToHost(0, otherDim);

            for (int i = 0; i < otherDim; i++)
            {
                if (temp.Host[i] < 0.0000001f)
                    temp.Host[i] = 0;
                else
                    temp.Host[i] = (float)(1 / Math.Sqrt(temp.Host[i]));
            }

            temp.SafeCopyToDevice(0, otherDim);

            for (int i = 0; i < otherDim; i++)
            {
                var seg = vectors.GetDevicePtr(GPU, i * leadingDim);
                var len = temp.GetDevicePtr(GPU, i);
                multKernel.Run(seg, len, seg, (int)MyJoin.MyJoinOperation.Multiplication, leadingDim, 1);
            }
        }
开发者ID:sschocke,项目名称:BrainSimulator,代码行数:45,代码来源:MyRandomPool.cs

示例4: RunReturn

 public float RunReturn(MatOperation operation, MyMemoryBlock<float> A, MyMemoryBlock<float> Result)
 {
     Run(operation, A, Result);
     Result.SafeCopyToHost();
     return Result.Host[0];
 }
开发者ID:Soucha,项目名称:BrainSimulator,代码行数:6,代码来源:MyMatrixOps.cs

示例5: Run

        public void Run(VectorOperation operation,
            MyMemoryBlock<float> a,
            MyMemoryBlock<float> b,
            MyMemoryBlock<float> result)
        {
            if (!Validate(operation, a.Count, b.Count))
                return;

            switch (operation)
            {
                case VectorOperation.Rotate:
                {
                    b.SafeCopyToHost();
                    float rads = DegreeToRadian(b.Host[0]);
                    float[] transform = { (float)Math.Cos(rads), -(float)Math.Sin(rads), (float)Math.Sin(rads), (float)Math.Cos(rads) };
                    Array.Copy(transform, m_temp.Host, transform.Length);
                    m_temp.SafeCopyToDevice();
                    m_matOperation.Run(MatOperation.Multiplication, m_temp, a, result);
                }
                break;

                case VectorOperation.Angle:
                {
                    m_matOperation.Run(MatOperation.DotProd, a, b, result);
                    result.SafeCopyToHost();
                    float dotProd = result.Host[0];
                    float angle = RadianToDegree((float)Math.Acos(dotProd));
                    result.Fill(0);
                    result.Host[0] = angle;
                    result.SafeCopyToDevice();
                }
                break;

                case VectorOperation.DirectedAngle:
                {
                    result.Host[0] = -90;
                    result.SafeCopyToDevice();
                    Run(VectorOperation.Rotate, a, result, result);
                    result.CopyToMemoryBlock(m_temp, 0, 0, result.Count);

                    m_matOperation.Run(MatOperation.DotProd, a, b, result);
                    result.SafeCopyToHost();
                    float dotProd = result.Host[0];
                    float angle;
                    if (Math.Abs(Math.Abs(dotProd) - 1) < 1E-4)
                        angle = 0;
                    else
                        angle = RadianToDegree((float)Math.Acos(dotProd));

                    m_matOperation.Run(MatOperation.DotProd, m_temp, b, result);
                    result.SafeCopyToHost();
                    float perpDotProd = result.Host[0];

                    if (perpDotProd > 0)
                        angle *= -1;
                    result.Fill(0);
                    result.Host[0] = angle;
                    result.SafeCopyToDevice();
                }
                break;
            }
        }
开发者ID:sschocke,项目名称:BrainSimulator,代码行数:62,代码来源:VectorOps.cs

示例6: PrintMemBlock2Console

 public void PrintMemBlock2Console(MyMemoryBlock<float> m, string s = "")
 {
     System.Console.Write("  + " + s + ": ");
     m.SafeCopyToHost();
     for (int i = 0; i < Math.Min(30,m.Count); i++)
     {
         System.Console.Write(m.Host[i]+" ");
     }
     System.Console.WriteLine("");
 }
开发者ID:J-F-B-M,项目名称:BrainSimulator,代码行数:10,代码来源:MyLSTMLayer.cs

示例7: Run

 public override void Run(MatOperation operation, MyMemoryBlock<float> A, MyMemoryBlock<float> B, MyMemoryBlock<float> Result)
 {
     if (OpersKerlsDictionary.ContainsKey(operation))
     {
         if (operation == MatOperation.GetRow)
         {
             B.SafeCopyToHost();
             OpersKerlsDictionary[operation].SetupExecution(A.ColumnHint);
             OpersKerlsDictionary[operation].Run(A, A.Count, A.ColumnHint, Result, Result.Count, Result.ColumnHint, B.Host[0]);
         }
         else if (operation == MatOperation.GetCol)
         {
             B.SafeCopyToHost();
             OpersKerlsDictionary[operation].SetupExecution(A.Count / A.ColumnHint);
             OpersKerlsDictionary[operation].Run(A, A.Count, A.ColumnHint, Result, Result.Count, Result.ColumnHint, B.Host[0]);
         }
         else if (operation == MatOperation.MultiplElemntWise | operation == MatOperation.Addition | operation == MatOperation.Substraction | operation == MatOperation.Pow)
         {
             if (A.Count >= B.Count)
             {
                 OpersKerlsDictionary[operation].SetupExecution(A.Count);
                 OpersKerlsDictionary[operation].Run(A, A.Count, A.ColumnHint, B, B.Count, B.ColumnHint, Result, Result.Count, Result.ColumnHint, float.NaN);
             }
             else
             {
                 OpersKerlsDictionary[operation].SetupExecution(B.Count);
                 OpersKerlsDictionary[operation].Run(B, B.Count, B.ColumnHint, A, A.Count, A.ColumnHint, Result, Result.Count, Result.ColumnHint, float.NaN);
             }
         }
         else
         { // other executions are performed by ,,standartezied'' kernel-call
             OpersKerlsDictionary[operation].SetupExecution(A.Count);
             OpersKerlsDictionary[operation].Run(A, A.Count, A.ColumnHint, B, B.Count, B.ColumnHint, Result, Result.Count, Result.ColumnHint);
         }
     }
     else
     {
         MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run kernel MatrixOps for uninitialized kernel");
     }
 }
开发者ID:sschocke,项目名称:BrainSimulator,代码行数:40,代码来源:MyMatrixKernelOps.cs


注:本文中的MyMemoryBlock.SafeCopyToHost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。