public override void Run(MatOperation operation, MyMemoryBlock <float> A, MyMemoryBlock <float> Result) { if (OpersKerlsDictionary.ContainsKey(operation)) { OpersKerlsDictionary[operation].Run(A, A.Count, A.ColumnHint, Result, Result.Count, Result.ColumnHint); } }
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; } }
public VectorOps(MyWorkingNode caller, VectorOperation operations, MyMemoryBlock <float> tempBlock) { m_caller = caller; m_operations = operations; m_temp = tempBlock; MatOperation mat_ops = MatOperation.None; if (m_operations.HasFlag(VectorOperation.Rotate)) { Debug.Assert(tempBlock.Count >= 4, "Temporary memory block has to be large at least 4 items when using Rotate operation"); mat_ops |= MatOperation.Multiplication; } if (m_operations.HasFlag(VectorOperation.Angle)) { mat_ops |= MatOperation.DotProd; } if (m_operations.HasFlag(VectorOperation.DirectedAngle)) { mat_ops |= MatOperation.Multiplication | MatOperation.DotProd; m_operations |= VectorOperation.Angle | VectorOperation.Rotate; } m_matOperation = new MyMatrixAutoOps(caller, mat_ops); }
public override void Run(MatOperation operation, MyMemoryBlock <float> A, float value, MyMemoryBlock <float> Result) { if (OpersKerlsDictionary.ContainsKey(operation)) { if (operation == MatOperation.GetRow) { OpersKerlsDictionary[operation].SetupExecution(A.ColumnHint); OpersKerlsDictionary[operation].Run(A, A.Count, A.ColumnHint, Result, Result.Count, Result.ColumnHint, value); } if (operation == MatOperation.GetCol) { OpersKerlsDictionary[operation].SetupExecution(A.Count / A.ColumnHint); OpersKerlsDictionary[operation].Run(A, A.Count, A.ColumnHint, Result, Result.Count, Result.ColumnHint, value); } else if (operation == MatOperation.MultiplElemntWise | operation == MatOperation.Addition | operation == MatOperation.Pow) { OpersKerlsDictionary[operation].SetupExecution(A.Count); OpersKerlsDictionary[operation].Run(A, A.Count, A.ColumnHint, A, 0, 0, Result, Result.Count, Result.ColumnHint, value); } else { OpersKerlsDictionary[operation].SetupExecution(A.Count); OpersKerlsDictionary[operation].Run(A, A.Count, A.ColumnHint, Result, Result.Count, Result.ColumnHint, value); } } else { MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run kernel MatrixOps for uninitialized kernel"); } }
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; } }
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; } }
public static MyMemoryBlock<float> SetupResultSize(MatOperation operation, MyMemoryBlock<float> A, MyMemoryBlock<float> B, MyMemoryBlock<float> Result) { Result.Count = A != null ? A.Count : 1; Result.ColumnHint = A != null ? A.ColumnHint : 1; if (A != null) { if (operation == MatOperation.DotProd) { Result.Count = Result.ColumnHint = 1; } else if (operation == MatOperation.AbsMinIndex || operation == MatOperation.AbsMaxIndex) { Result.ColumnHint = 1; Result.Count = 1; } else if (operation == MatOperation.Multiplication) { if (A != null && B != null && A.ColumnHint != 0 && B.Count > 1) { Result.ColumnHint = B.ColumnHint; Result.Count = B.ColumnHint * A.Count / A.ColumnHint; } } else if (operation == MatOperation.GetCol) { Result.Count = A.Count / A.ColumnHint; Result.ColumnHint = Result.Count; } else if (operation == MatOperation.GetRow) { Result.Count = A.ColumnHint; Result.ColumnHint = Result.Count; } else if (B != null && (operation == MatOperation.MultiplElemntWise || operation == MatOperation.Addition)) { Result.ColumnHint = Math.Max(A.ColumnHint, B.ColumnHint); Result.Count = Math.Max(A.Count, B.Count); } else if (operation == MatOperation.Transpose) { if ((A.ColumnHint != 0) && (A.Count > 0)) // prevent dimension of size 0 { Result.Dims.Set(new[] { -1, A.Count / A.ColumnHint }); } } else if (operation == MatOperation.EuclidDist) { if (B != null) { Result.Count = A.Count / A.ColumnHint; Result.ColumnHint = 1; } } } return Result; }
public MyMatrixKernelOps(MyWorkingNode callee, MatOperation operations, MyMemoryBlock <float> A, MyMemoryBlock <float> B = null) { OpersKerlsDictionary = new Dictionary <MatOperation, MyCudaKernel>(); this.callee = callee; if ((operations & MatOperation.Log) > 0) { OpersKerlsDictionary.Add(MatOperation.Log, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "LogKernel_naive")); } if ((operations & MatOperation.Exp) > 0) { OpersKerlsDictionary.Add(MatOperation.Exp, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "ExpKernel_naive")); } if ((operations & MatOperation.Round) > 0) { OpersKerlsDictionary.Add(MatOperation.Round, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "RoundKernel_naive")); } if ((operations & MatOperation.Floor) > 0) { OpersKerlsDictionary.Add(MatOperation.Floor, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "FloorKernel_naive")); } if ((operations & MatOperation.Ceil) > 0) { OpersKerlsDictionary.Add(MatOperation.Ceil, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "CeilKernel_naive")); } if ((operations & MatOperation.Abs) > 0) { OpersKerlsDictionary.Add(MatOperation.Abs, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "AbsKernel_naive")); } if ((operations & MatOperation.GetCol) > 0) { OpersKerlsDictionary.Add(MatOperation.GetCol, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "Matrix_getCol_FloatId_naive")); } if ((operations & MatOperation.GetRow) > 0) { OpersKerlsDictionary.Add(MatOperation.GetRow, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "Matrix_getRow_FloatId_naive")); } if ((operations & MatOperation.MultiplElemntWise) > 0) { OpersKerlsDictionary.Add(MatOperation.MultiplElemntWise, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "Matrix_MultiplElementWise_naive")); } if ((operations & MatOperation.Addition) > 0) { OpersKerlsDictionary.Add(MatOperation.Addition, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "Matrix_Addition_naive")); } if ((operations & MatOperation.Substraction) > 0) { OpersKerlsDictionary.Add(MatOperation.Substraction, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "Matrix_Substraction_naive")); } if (operations > 0 && OpersKerlsDictionary.Count == 0) { MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to init kernel MatrixOps for undefined MatOperation"); } }
public static MyMemoryBlock <float> SetupResultSize(MatOperation operation, MyMemoryBlock <float> A, MyMemoryBlock <float> B, MyMemoryBlock <float> Result) { Result.Count = A != null ? A.Count : 1; Result.ColumnHint = A != null ? A.ColumnHint : 1; if (A != null) { if (operation == MatOperation.DotProd) { Result.Count = Result.ColumnHint = 1; } else if (operation == MatOperation.AbsMinIndex || operation == MatOperation.AbsMaxIndex) { Result.ColumnHint = 1; Result.Count = 1; } else if (operation == MatOperation.Multiplication) { if (A != null && B != null && A.ColumnHint != 0 && B.Count > 1) { Result.ColumnHint = B.ColumnHint; Result.Count = B.ColumnHint * A.Count / A.ColumnHint; } } else if (operation == MatOperation.GetCol) { Result.Count = A.Count / A.ColumnHint; Result.ColumnHint = Result.Count; } else if (operation == MatOperation.GetRow) { Result.Count = A.ColumnHint; Result.ColumnHint = Result.Count; } else if (B != null && (operation == MatOperation.MultiplElemntWise || operation == MatOperation.Addition)) { Result.ColumnHint = Math.Max(A.ColumnHint, B.ColumnHint); Result.Count = Math.Max(A.Count, B.Count); } else if (operation == MatOperation.Transpose) { Result.Dims = A.Dims.Transpose(); } else if (operation == MatOperation.EuclidDist) { if (B != null) { Result.Count = A.Count / A.ColumnHint; Result.ColumnHint = 1; } } } return(Result); }
public MyMatrixKernelOps(MyWorkingNode callee, MatOperation operations, MyMemoryBlock<float> A, MyMemoryBlock<float> B = null) { OpersKerlsDictionary = new Dictionary<MatOperation, MyCudaKernel>(); this.callee = callee; if ((operations & MatOperation.Log) > 0) { OpersKerlsDictionary.Add(MatOperation.Log, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "LogKernel_naive")); } if ((operations & MatOperation.Exp) > 0) { OpersKerlsDictionary.Add(MatOperation.Exp, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "ExpKernel_naive")); } if ((operations & MatOperation.Round) > 0) { OpersKerlsDictionary.Add(MatOperation.Round, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "RoundKernel_naive")); } if ((operations & MatOperation.Floor) > 0) { OpersKerlsDictionary.Add(MatOperation.Floor, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "FloorKernel_naive")); } if ((operations & MatOperation.Ceil) > 0) { OpersKerlsDictionary.Add(MatOperation.Ceil, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "CeilKernel_naive")); } if ((operations & MatOperation.Abs) > 0) { OpersKerlsDictionary.Add(MatOperation.Abs, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "AbsKernel_naive")); } if ((operations & MatOperation.GetCol) > 0) { OpersKerlsDictionary.Add(MatOperation.GetCol, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "Matrix_getCol_FloatId_naive")); } if ((operations & MatOperation.GetRow) > 0) { OpersKerlsDictionary.Add(MatOperation.GetRow, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "Matrix_getRow_FloatId_naive")); } if ((operations & MatOperation.MultiplElemntWise) > 0) { OpersKerlsDictionary.Add(MatOperation.MultiplElemntWise, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "Matrix_MultiplElementWise_naive")); } if ((operations & MatOperation.Addition) > 0) { OpersKerlsDictionary.Add(MatOperation.Addition, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "Matrix_Addition_naive")); } if ((operations & MatOperation.Substraction) > 0) { OpersKerlsDictionary.Add(MatOperation.Substraction, MyKernelFactory.Instance.Kernel(callee.GPU, @"Vision\Matrix", "Matrix_Substraction_naive")); } if (operations > 0 && OpersKerlsDictionary.Count == 0) { MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to init kernel MatrixOps for undefined MatOperation"); } }
/// <summary> /// Enables overriding the dimensions to be applicable on tensors /// </summary> /// <param name="operation"></param> /// <param name="A"></param> /// <param name="Result"></param> public override void Run(MatOperation operation, MyMemoryBlock <float> A, MyMemoryBlock <float> Result, int AColumnHint) { if (A.Count % AColumnHint != 0) { throw new ArgumentException(string.Format("MyMatrixKernelOps: number of matrix elements ({0}) is not divisible by the desired column hint ({1})", A.Count, AColumnHint)); } if (OpersKerlsDictionary.ContainsKey(operation)) { OpersKerlsDictionary[operation].SetupExecution(A.Count); OpersKerlsDictionary[operation].Run(A, A.Count, AColumnHint, Result, Result.Count, Result.ColumnHint); } }
public void Run(MatOperation operation, CudaDeviceVariable <float> A, int ACount, int AColumnHint, CudaDeviceVariable <float> B, int BCount, int BColumnHint, CudaDeviceVariable <float> Result, int ResultCount, int ResultColumnHint, float beta = 1.0f) { Result.Memset(BitConverter.ToUInt32(BitConverter.GetBytes(0.0f), 0)); switch (operation) { case MatOperation.Multiplication: // vectors/matrices have to be always in the correct dimesions! if (BCount > 1 && ACount > 1 && BColumnHint == 1 && ACount / AColumnHint > 1 && BCount / BColumnHint == AColumnHint) //. A*vecB { MyCublasFactory.Instance.Gemv(Operation.Transpose, // transpose beacuase it does Ax row wise if x is a row vector :D AColumnHint, ACount / AColumnHint, 1.0f, A, AColumnHint, B, 1, beta, Result, 1); } else if (ACount > 1 && BCount > 1 && ACount / AColumnHint == 1 && BColumnHint > 1 && BCount / BColumnHint == AColumnHint) // vecA*B { MyCublasFactory.Instance.Gemv(Operation.NonTranspose, // transpose beacuase it does Ax row wise if x is a row vector :D BColumnHint, BCount / BColumnHint, 1.0f, B, BColumnHint, A, 1, beta, Result, 1); } else if (ACount / AColumnHint == 1 && BColumnHint == 1 && ACount > 1 && BCount > 1) //. trans(vecA) * vecB { Run(MatOperation.DotProd, A, ACount, AColumnHint, B, BCount, BColumnHint, Result, ResultCount, ResultColumnHint, beta); } else if (ACount != 1 || BCount != 1) // A*B matrix multiplication { MyCublasFactory.Instance.Gemm(Operation.NonTranspose, Operation.NonTranspose, ACount / AColumnHint, BColumnHint, AColumnHint, 1.0f, A, ACount / AColumnHint, B, BCount / BColumnHint, beta, Result, ResultColumnHint); } break; case MatOperation.DotProd: MyCublasFactory.Instance.Gemv(Operation.Transpose, // transpose beacuase it does Ax row wise if x is a row vector :D ACount, 1, 1.0f, A, ACount, B, 1, beta, Result, 1); break; default: MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run cublas for undefined MatOperation"); break; } }
public override void Run(MatOperation operation, MyMemoryBlock <float> A, float value, MyMemoryBlock <float> Result) { Result.Fill(.0f); switch (operation) { case MatOperation.Multiplication: MyCublasFactory.Instance.Axpy(value, A.GetDevice(callee), 1, Result.GetDevice(callee), 1); break; default: MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run cublas for undefined MatOperation"); break; } }
public override void Run(MatOperation operation, MyMemoryBlock <float> A, MyMemoryBlock <float> Result) { if ((MyMatrixCublasOps.AvailableOperations() & operation) > 0) { MatCublOps.Run(operation, A, Result); } else if ((MyMatrixKernelOps.AvailableOperations() & operation) > 0) { MatKerlOps.Run(operation, A, Result); } else { MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run undefined MatOps"); } }
public MyMatrixAutoOps(MyWorkingNode callee, MatOperation operations, MyMemoryBlock<float> A = null) { if ((MyMatrixKernelOps.AvailableOperations() & operations) > 0) { MatKerlOps = new MyMatrixKernelOps(callee, operations); } if ((MyMatrixCublasOps.AvailableOperations() & operations) > 0) { MatCublOps = new MyMatrixCublasOps(callee); } if ((MyMatrixCPUOps.AvailableOperations() & operations) > 0) { MatCPUOps = new MyMatrixCPUOps(callee); } }
public override void Run(MatOperation operation, MyMemoryBlock<float> A, float value, MyMemoryBlock<float> Result) { if ((MyMatrixCublasOps.AvailableOperations() & operation) > 0) { MatCublOps.Run(operation, A, value, Result); } else if ((MyMatrixKernelOps.AvailableOperations() & operation) > 0) { MatKerlOps.Run(operation, A, value, Result); } else { MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run undefined MatOps"); } }
public MyMatrixAutoOps(MyWorkingNode callee, MatOperation operations, MyMemoryBlock <float> A = null) { if ((MyMatrixKernelOps.AvailableOperations() & operations) > 0) { MatKerlOps = new MyMatrixKernelOps(callee, operations); } if ((MyMatrixCublasOps.AvailableOperations() & operations) > 0) { MatCublOps = new MyMatrixCublasOps(callee); } if ((MyMatrixCPUOps.AvailableOperations() & operations) > 0) { MatCPUOps = new MyMatrixCPUOps(callee); } }
public void Run(MatOperation operation, CudaDeviceVariable<float> A, int ACount, int AColumnHint, CudaDeviceVariable<float> B, int BCount, int BColumnHint, CudaDeviceVariable<float> Result, int ResultCount, int ResultColumnHint, float beta = 1.0f) { Result.Memset(BitConverter.ToUInt32(BitConverter.GetBytes(0.0f), 0)); switch (operation) { case MatOperation.Multiplication: // vectors/matrices have to be always in the correct dimesions! if (BCount > 1 && ACount > 1 && BColumnHint == 1 && ACount / AColumnHint > 1 && BCount / BColumnHint == AColumnHint) //. A*vecB { MyCublasFactory.Instance.Gemv(Operation.Transpose, // transpose beacuase it does Ax row wise if x is a row vector :D AColumnHint, ACount / AColumnHint, 1.0f, A, AColumnHint, B, 1, beta, Result, 1); } else if (ACount > 1 && BCount > 1 && ACount / AColumnHint == 1 && BColumnHint > 1 && BCount / BColumnHint == AColumnHint) // vecA*B { MyCublasFactory.Instance.Gemv(Operation.NonTranspose, // transpose beacuase it does Ax row wise if x is a row vector :D BColumnHint, BCount / BColumnHint, 1.0f, B, BColumnHint, A, 1, beta, Result, 1); } else if (ACount / AColumnHint == 1 && BColumnHint == 1 && ACount > 1 && BCount > 1) //. trans(vecA) * vecB { Run(MatOperation.DotProd, A, ACount, AColumnHint, B, BCount, BColumnHint, Result, ResultCount, ResultColumnHint, beta); } else if (ACount != 1 || BCount != 1)// A*B matrix multiplication { MyCublasFactory.Instance.Gemm(Operation.NonTranspose, Operation.NonTranspose, ACount / AColumnHint, BColumnHint, AColumnHint, 1.0f, A, ACount / AColumnHint, B, BCount / BColumnHint, beta, Result, ResultColumnHint); } break; case MatOperation.DotProd: MyCublasFactory.Instance.Gemv(Operation.Transpose, // transpose beacuase it does Ax row wise if x is a row vector :D ACount, 1, 1.0f, A, ACount, B, 1, beta, Result, 1); break; default: MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run cublas for undefined MatOperation"); break; } }
public override void Run(MatOperation operation, MyMemoryBlock <float> A) { switch (operation) { case MatOperation.Minus: MyCublasFactory.Instance.Scale(-1.0f, A.GetDevice(callee), 1); break; case MatOperation.Normalize: float nrm = MyCublasFactory.Instance.Norm2(A.GetDevice(callee), 1); MyCublasFactory.Instance.Scale(1 / nrm, A.GetDevice(callee), 1); break; default: MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run cublas for undefined MatOperation"); break; } }
public static bool Validate(MatOperation operation, MyMemoryBlock <float> A, MyMemoryBlock <float> B, MyMemoryBlock <float> Result) { if (A == null || Result == null) { return(false); } bool is_it_correct = true; if (operation == MatOperation.DotProd) { is_it_correct = (A.Count == B.Count) && (Result.Count == 1); } else if (operation == MatOperation.Multiplication) { // it should allow MAT*MAT, vec*MAT and MAT*vec , in correct sizes of course if (B == null) { is_it_correct = A.Count == Result.Count && A.ColumnHint == Result.ColumnHint; } else { is_it_correct = (A.ColumnHint == B.Count / B.ColumnHint) && (B.ColumnHint == Result.ColumnHint) && (A.Count / A.ColumnHint == Result.Count / Result.ColumnHint); is_it_correct = is_it_correct || (B.Count == 1) || (A.Count == 1); // it still allows A*5 :-) } } else if (operation == MatOperation.Addition || operation == MatOperation.MultiplElemntWise) { if (B == null) { is_it_correct = A.Count == Result.Count && A.ColumnHint == Result.ColumnHint; } else { is_it_correct = (A.Count == B.Count) && (A.ColumnHint == B.ColumnHint); // same size is_it_correct |= A.ColumnHint == B.ColumnHint || A.Count / A.ColumnHint == B.Count / B.ColumnHint; // same # of colums, rows is_it_correct |= A.Count == 1 || B.Count == 1; is_it_correct |= (Math.Max(A.Count, B.Count) == Result.Count) && (Math.Max(A.ColumnHint, B.ColumnHint) == Result.ColumnHint); } } else if (operation == MatOperation.EuclidDist) { is_it_correct = (A.ColumnHint == B.Count); } return(is_it_correct); }
public static MyMemoryBlock<float> SetupResultSize(MatOperation operation, MyMemoryBlock<float> A, MyMemoryBlock<float> B, MyMemoryBlock<float> Result) { Result.Count = A != null ? A.Count : 1; Result.ColumnHint = A != null ? A.ColumnHint : 1; if (A != null) { if (operation == MatOperation.DotProd) { Result.Count = Result.ColumnHint = 1; } else if (operation == MatOperation.Multiplication) { if (A != null && B != null && A.ColumnHint != 0 && B.Count > 1) { Result.ColumnHint = B.ColumnHint; Result.Count = B.ColumnHint * A.Count / A.ColumnHint; } } else if (operation == MatOperation.GetCol) { Result.Count = A.Count / A.ColumnHint; Result.ColumnHint = Result.Count; } else if (operation == MatOperation.GetRow) { Result.Count = A.ColumnHint; Result.ColumnHint = Result.Count; } else if (B != null && (operation == MatOperation.MultiplElemntWise || operation == MatOperation.Addition)) { Result.ColumnHint = Math.Max(A.ColumnHint, B.ColumnHint); Result.Count = Math.Max(A.Count, B.Count); } else if (operation == MatOperation.Transpose) { if (A.ColumnHint != 0) { Result.ColumnHint = A.Count / A.ColumnHint; } } } return Result; }
public static Number Calculate(MatOperation operation, Number a, Number b) { Number result = null; switch (operation.Operation) { case Operation.Add: return((Number)Round((a + b))); case Operation.Subtract: return((Number)Round((a - b))); case Operation.Multiply: return((Number)Round((a * b))); case Operation.Divide: return((Number)Round((a / b))); case Operation.Power: if (b.Imaginary == 0 && a.Imaginary == 0) { return((Number)Round(a.Power(b.Real))); } else { return((Number)Round(a.Power(b))); } case Operation.Root: if (b.Imaginary == 0) { return((Number)Round(a.Root((int)b.Real))); } else { return((Number)Round(a.Root(b))); } } return(result); }
/// <summary> /// Enables overriding the dimensions to be applicable on tensors. Result columnHint seems not to be used for any operation so there is no need to override it. /// </summary> /// <param name="operation"></param> /// <param name="A"></param> /// <param name="Result"></param> /// <param name="AColumnHint">sees A as a matrix with this number of columns</param> public override void Run(MatOperation operation, MyMemoryBlock <float> A, MyMemoryBlock <float> Result, int AColumnHint) { if (A.Count % AColumnHint != 0) { throw new ArgumentException(string.Format("MyMatrixAutoOps: number of matrix elements ({0}) is not divisible by the desired column hint ({1})", A.Count, AColumnHint)); } if ((MyMatrixCublasOps.AvailableOperations() & operation) > 0) { MatCublOps.Run(operation, A, Result, AColumnHint); } else if ((MyMatrixKernelOps.AvailableOperations() & operation) > 0) { MatKerlOps.Run(operation, A, Result, AColumnHint); } else { MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run undefined MatOps"); } }
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"); } }
public override void Run(MatOperation operation, MyMemoryBlock <float> A, MyMemoryBlock <float> Result) { int itmp; Result.Fill(.0f); switch (operation) { case MatOperation.AbsMinIndex: itmp = MyCublasFactory.Instance.Min(A.GetDevice(callee), 1); Result.Fill((float)(itmp - 1)); break; case MatOperation.AbsMaxIndex: itmp = MyCublasFactory.Instance.Max(A.GetDevice(callee), 1); Result.Fill((float)(itmp - 1)); break; case MatOperation.Norm2: MyCublasFactory.Instance.Norm2(A.GetDevice(callee), 1, Result.GetDevice(callee)); break; case MatOperation.Normalize: float nrm = MyCublasFactory.Instance.Norm2(A.GetDevice(callee), 1); MyCublasFactory.Instance.Axpy(1 / nrm, A.GetDevice(callee), 1, Result.GetDevice(callee), 1); break; case MatOperation.Minus: MyCublasFactory.Instance.Axpy(-1.0f, A.GetDevice(callee), 1, Result.GetDevice(callee), 1); break; case MatOperation.Copy: MyCublasFactory.Instance.Copy(A.GetDevice(callee), 1, Result.GetDevice(callee), 1); break; default: MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run cublas for undefined MatOperation"); break; } }
public float RunReturn(MatOperation operation, MyMemoryBlock<float> A, MyMemoryBlock<float> Result) { Run(operation, A, Result); Result.SafeCopyToHost(); return Result.Host[0]; }
public abstract void Run(MatOperation operation, MyMemoryBlock<float> A);
public abstract void Run(MatOperation operation, MyMemoryBlock<float> A, float value, MyMemoryBlock<float> Result);
public abstract void Run(MatOperation operation, MyMemoryBlock <float> A); // change A
public MyMatrixCPUOps(MyWorkingNode callee=null, MatOperation operation = 0, MyMemoryBlock<float> A = null, MyMemoryBlock<float> tmp = null) { }
public override void Run(MatOperation operation, MyMemoryBlock<float> A) { }
public override void Run(MatOperation operation, MyMemoryBlock<float> A, float value, MyMemoryBlock<float> Result) { MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run cpu mat ops. for undefined MatOperation"); }
public void Run(MatOperation operation, CudaDeviceVariable<float> A, int ACount, int AColumnHint, CudaDeviceVariable<float> B, int BCount, int BColumnHint, CudaDeviceVariable<float> Result, int ResultCount, int ResultColumnHint, float beta = 1.0f) { Result.Memset(BitConverter.ToUInt32(BitConverter.GetBytes(0.0f), 0)); switch (operation) { case MatOperation.Multiplication: // vectors/matrices have to be always in the correct dimesions! if (BCount > 1 && ACount >= 1 && BColumnHint == 1 && ACount / AColumnHint > 1 && BCount / BColumnHint == AColumnHint) //. A*vecB { MyCublasFactory.Instance.Gemv(Operation.Transpose, // transpose beacuase it does Ax row wise if x is a row vector :D AColumnHint, ACount / AColumnHint, 1.0f, A, AColumnHint, B, 1, beta, Result, 1); } else if (ACount >= 1 && BCount > 1 && ACount / AColumnHint == 1 && BColumnHint > 1 && BCount / BColumnHint == AColumnHint) // vecA*B { MyCublasFactory.Instance.Gemv(Operation.NonTranspose, // transpose beacuase it does Ax row wise if x is a row vector :D BColumnHint, BCount / BColumnHint, 1.0f, B, BColumnHint, A, 1, beta, Result, 1); } else if (ACount / AColumnHint == 1 && BColumnHint == 1 && ACount > 1 && BCount > 1) //. trans(vecA) * vecB { Run(MatOperation.DotProd, A, ACount, AColumnHint, B, BCount, BColumnHint, Result, ResultCount, ResultColumnHint, beta); } else if (ACount != 1 || BCount != 1)// A*B matrix multiplication { // Cublas is using fortran matrices.. thus tey have to be swapped such as described in: http://peterwittek.com/cublas-matrix-c-style.html int m = BColumnHint; int n = ACount / AColumnHint; int k = AColumnHint; int lda = BColumnHint; int ldb = AColumnHint; int ldc = ResultColumnHint; MyCublasFactory.Instance.Gemm(Operation.NonTranspose, Operation.NonTranspose, m, n, k, 1.0f, B, lda, A, ldb, beta, Result, ldc); } break; case MatOperation.DotProd: if (ACount != BCount || ResultCount != 1) { MyLog.Writer.WriteLine(MyLogLevel.ERROR, callee.Name + ": Inconsistent vector dimensions for MyMatrixCublasOps."); break; } MyCublasFactory.Instance.Gemv(Operation.Transpose, // transpose beacuase it does Ax row wise if x is a row vector :D ACount, 1, 1.0f, A, ACount, B, 1, beta, Result, 1); break; default: MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run cublas for undefined MatOperation"); break; } }
public override void Run(MatOperation operation, MyMemoryBlock<float> A, float value, MyMemoryBlock<float> Result) { if (OpersKerlsDictionary.ContainsKey(operation)) { if (operation == MatOperation.GetRow) { OpersKerlsDictionary[operation].SetupExecution(A.ColumnHint); OpersKerlsDictionary[operation].Run(A, A.Count, A.ColumnHint, Result, Result.Count, Result.ColumnHint, value); } if (operation == MatOperation.GetCol) { OpersKerlsDictionary[operation].SetupExecution(A.Count / A.ColumnHint); OpersKerlsDictionary[operation].Run(A, A.Count, A.ColumnHint, Result, Result.Count, Result.ColumnHint, value); } else if (operation == MatOperation.MultiplElemntWise | operation == MatOperation.Addition | operation == MatOperation.Pow) { OpersKerlsDictionary[operation].SetupExecution(A.Count); OpersKerlsDictionary[operation].Run(A, A.Count, A.ColumnHint, A, 0, 0, Result, Result.Count, Result.ColumnHint, value); } else { OpersKerlsDictionary[operation].SetupExecution(A.Count); OpersKerlsDictionary[operation].Run(A, A.Count, A.ColumnHint, Result, Result.Count, Result.ColumnHint, value); } } else { MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run kernel MatrixOps for uninitialized kernel"); } }
/// <summary> /// Enables overriding the dimensions to be applicable on tensors /// </summary> /// <param name="operation"></param> /// <param name="A"></param> /// <param name="Result"></param> public override void Run(MatOperation operation, MyMemoryBlock<float> A, MyMemoryBlock<float> Result, int AColumnHint) { if (A.Count % AColumnHint != 0) { throw new ArgumentException(string.Format("MyMatrixKernelOps: number of matrix elements ({0}) is not divisible by the desired column hint ({1})", A.Count, AColumnHint)); } if (OpersKerlsDictionary.ContainsKey(operation)) { OpersKerlsDictionary[operation].SetupExecution(A.Count); OpersKerlsDictionary[operation].Run(A, A.Count, AColumnHint, Result, Result.Count, Result.ColumnHint); } }
public override void Run(MatOperation operation, MyMemoryBlock <float> A, MyMemoryBlock <float> Result, int AColumnHint) { MyLog.WARNING.WriteLine("MyMatrixCublasOps: Forcing a different columnhint does not have any effect on the perfomed operation - " + operation); Run(operation, A, Result); //the columnhint of A does not have any effect in the operations }
public float RunReturn(MatOperation operation, MyMemoryBlock <float> A, MyMemoryBlock <float> Result) { Run(operation, A, Result); Result.SafeCopyToHost(); return(Result.Host[0]); }
public override void Run(MatOperation operation, MyMemoryBlock<float> A, MyMemoryBlock<float> Result) { if (OpersKerlsDictionary.ContainsKey(operation)) { OpersKerlsDictionary[operation].SetupExecution(A.Count); OpersKerlsDictionary[operation].Run(A, A.Count, A.ColumnHint, Result, Result.Count, Result.ColumnHint); } }
public abstract void Run(MatOperation operation, MyMemoryBlock <float> A, MyMemoryBlock <float> Result, int AcolumnHint);
public override void Run(MatOperation operation, MyMemoryBlock <float> A) { }
public override void Run(MatOperation operation, MyMemoryBlock<float> A, MyMemoryBlock<float> Result) { int itmp; Result.Fill(.0f); switch (operation) { case MatOperation.MinIndex: itmp = MyCublasFactory.Instance.Min(A.GetDevice(callee), 1); Result.Fill((float)(itmp - 1)); break; case MatOperation.MaxIndex: itmp = MyCublasFactory.Instance.Max(A.GetDevice(callee), 1); Result.Fill((float)(itmp - 1)); break; case MatOperation.Norm2: MyCublasFactory.Instance.Norm2(A.GetDevice(callee), 1, Result.GetDevice(callee)); break; case MatOperation.Normalize: float nrm = MyCublasFactory.Instance.Norm2(A.GetDevice(callee), 1); MyCublasFactory.Instance.Axpy(1 / nrm, A.GetDevice(callee), 1, Result.GetDevice(callee), 1); break; case MatOperation.Minus: MyCublasFactory.Instance.Axpy(-1.0f, A.GetDevice(callee), 1, Result.GetDevice(callee), 1); break; case MatOperation.Copy: MyCublasFactory.Instance.Copy(A.GetDevice(callee), 1, Result.GetDevice(callee), 1); break; default: MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run cublas for undefined MatOperation"); break; } }
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"); } }
public override void Run(MatOperation operation, MyMemoryBlock<float> A, float value, MyMemoryBlock<float> Result) { Result.Fill(.0f); switch (operation) { case MatOperation.Multiplication: MyCublasFactory.Instance.Axpy(value, A.GetDevice(callee), 1, Result.GetDevice(callee), 1); break; default: MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run cublas for undefined MatOperation"); break; } }
public override void Run(MatOperation operation, MyMemoryBlock<float> A, MyMemoryBlock<float> Result, int AColumnHint) { MyLog.WARNING.WriteLine("MyMatrixCublasOps: Forcing a different columnhint does not have any effect on the perfomed operation - " + operation); Run(operation, A, Result); //the columnhint of A does not have any effect in the operations }
/// <summary> /// Enables overriding the dimensions to be applicable on tensors. Result columnHint seems not to be used for any operation so there is no need to override it. /// </summary> /// <param name="operation"></param> /// <param name="A"></param> /// <param name="Result"></param> /// <param name="AColumnHint">sees A as a matrix with this number of columns</param> public override void Run(MatOperation operation, MyMemoryBlock<float> A, MyMemoryBlock<float> Result, int AColumnHint) { if (A.Count % AColumnHint != 0) { throw new ArgumentException(string.Format("MyMatrixAutoOps: number of matrix elements ({0}) is not divisible by the desired column hint ({1})", A.Count, AColumnHint)); } if ((MyMatrixCublasOps.AvailableOperations() & operation) > 0) { MatCublOps.Run(operation, A, Result, AColumnHint); } else if ((MyMatrixKernelOps.AvailableOperations() & operation) > 0) { MatKerlOps.Run(operation, A, Result, AColumnHint); } else { MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run undefined MatOps"); } }
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; } }
public abstract void Run(MatOperation operation, MyMemoryBlock <float> A, float value, MyMemoryBlock <float> Result);
public override void Run(MatOperation operation, MyMemoryBlock<float> A) { switch (operation) { case MatOperation.Minus: MyCublasFactory.Instance.Scale(-1.0f, A.GetDevice(callee), 1); break; case MatOperation.Normalize: float nrm = MyCublasFactory.Instance.Norm2(A.GetDevice(callee), 1); MyCublasFactory.Instance.Scale(1 / nrm, A.GetDevice(callee), 1); break; default: MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run cublas for undefined MatOperation"); break; } }
public void Run(MatOperation operation, CudaDeviceVariable <float> A, int ACount, int AColumnHint, CudaDeviceVariable <float> B, int BCount, int BColumnHint, CudaDeviceVariable <float> Result, int ResultCount, int ResultColumnHint, float beta = 1.0f) { Result.Memset(BitConverter.ToUInt32(BitConverter.GetBytes(0.0f), 0)); switch (operation) { case MatOperation.Multiplication: // vectors/matrices have to be always in the correct dimesions! if (BCount > 1 && ACount >= 1 && BColumnHint == 1 && ACount / AColumnHint > 1 && BCount / BColumnHint == AColumnHint) //. A*vecB { MyCublasFactory.Instance.Gemv(Operation.Transpose, // transpose beacuase it does Ax row wise if x is a row vector :D AColumnHint, ACount / AColumnHint, 1.0f, A, AColumnHint, B, 1, beta, Result, 1); } else if (ACount >= 1 && BCount > 1 && ACount / AColumnHint == 1 && BColumnHint > 1 && BCount / BColumnHint == AColumnHint) // vecA*B { MyCublasFactory.Instance.Gemv(Operation.NonTranspose, // transpose beacuase it does Ax row wise if x is a row vector :D BColumnHint, BCount / BColumnHint, 1.0f, B, BColumnHint, A, 1, beta, Result, 1); } else if (ACount / AColumnHint == 1 && BColumnHint == 1 && ACount > 1 && BCount > 1) //. trans(vecA) * vecB { Run(MatOperation.DotProd, A, ACount, AColumnHint, B, BCount, BColumnHint, Result, ResultCount, ResultColumnHint, beta); } else if (ACount != 1 || BCount != 1) // A*B matrix multiplication { // Cublas is using fortran matrices.. thus tey have to be swapped such as described in: http://peterwittek.com/cublas-matrix-c-style.html int m = BColumnHint; int n = ACount / AColumnHint; int k = AColumnHint; int lda = BColumnHint; int ldb = AColumnHint; int ldc = ResultColumnHint; MyCublasFactory.Instance.Gemm(Operation.NonTranspose, Operation.NonTranspose, m, n, k, 1.0f, B, lda, A, ldb, beta, Result, ldc); } break; case MatOperation.DotProd: if (ACount != BCount || ResultCount != 1) { MyLog.Writer.WriteLine(MyLogLevel.ERROR, callee.Name + ": Inconsistent vector dimensions for MyMatrixCublasOps."); break; } MyCublasFactory.Instance.Gemv(Operation.Transpose, // transpose beacuase it does Ax row wise if x is a row vector :D ACount, 1, 1.0f, A, ACount, B, 1, beta, Result, 1); break; default: MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run cublas for undefined MatOperation"); break; } }
//private CudaBlas cublas = null; public MyMatrixCublasOps(MyWorkingNode callee, MatOperation operation = 0, MyMemoryBlock<float> A = null, MyMemoryBlock<float> tmp = null) { // cublas = new CudaBlas(); this.callee = callee; }
public static bool Validate(MatOperation operation, MyMemoryBlock<float> A, MyMemoryBlock<float> B, MyMemoryBlock<float> Result) { if (A == null || Result == null) return false; bool is_it_correct = true; if (operation == MatOperation.DotProd) { is_it_correct = (A.Count == B.Count) && (Result.Count == 1); } else if (operation == MatOperation.Multiplication) { // it should allow MAT*MAT, vec*MAT and MAT*vec , in correct sizes of course if (B == null) { is_it_correct = A.Count == Result.Count && A.ColumnHint == Result.ColumnHint; } else { is_it_correct = (A.ColumnHint == B.Count / B.ColumnHint) && (B.ColumnHint == Result.ColumnHint) && (A.Count / A.ColumnHint == Result.Count / Result.ColumnHint); is_it_correct = is_it_correct || (B.Count == 1) || (A.Count == 1); // it still allows A*5 :-) } } else if (operation == MatOperation.Addition || operation == MatOperation.MultiplElemntWise) { if (B == null) { is_it_correct = A.Count == Result.Count && A.ColumnHint == Result.ColumnHint; } else { is_it_correct = (A.Count == B.Count) && (A.ColumnHint == B.ColumnHint); // same size is_it_correct |= A.ColumnHint == B.ColumnHint || A.Count / A.ColumnHint == B.Count / B.ColumnHint; // same # of colums, rows is_it_correct |= A.Count == 1 || B.Count == 1; is_it_correct |= (Math.Max(A.Count, B.Count) == Result.Count) && (Math.Max(A.ColumnHint, B.ColumnHint) == Result.ColumnHint); } } else if (operation == MatOperation.EuclidDist) { is_it_correct = (A.ColumnHint == B.Count); } return is_it_correct; }
public MyMatrixCPUOps(MyWorkingNode callee = null, MatOperation operation = 0, MyMemoryBlock <float> A = null, MyMemoryBlock <float> tmp = null) { }
//private CudaBlas cublas = null; public MyMatrixCublasOps(MyWorkingNode callee, MatOperation operation = 0, MyMemoryBlock <float> A = null, MyMemoryBlock <float> tmp = null) { // cublas = new CudaBlas(); this.callee = callee; }
public override void Run(MatOperation operation, MyMemoryBlock <float> A, float value, MyMemoryBlock <float> Result) { MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run cpu mat ops. for undefined MatOperation"); }
public abstract void Run(MatOperation operation, MyMemoryBlock<float> A, MyMemoryBlock<float> Result, int AcolumnHint);