Example #1
0
        public static FloatTensor Ones(FloatTensorFactory factory, int[] dims)
        {
            FloatTensor result = factory.ctrl.floatTensorFactory.Create(dims);

            result.Add(1.0F, inline: true);
            return(result);
        }
Example #2
0
        public FloatTensor createOnesTensorLike()
        {
            FloatTensor new_tensor = this.emptyTensorCopy();

            new_tensor.Zero_();
            new_tensor.Add((float)1, true);
            return(new_tensor);
        }
Example #3
0
        // parameters are overrides
        public FloatTensor Copy(FloatTensor result = null)
        {
            result = HookAutograd(ref result, "copy", false);
            result.Zero_();
            result.Add(this, inline: true);

            return(result);
        }
        public void DivElemGPU_(FloatTensor tensor)
        {
            Debug.LogFormat("<color=blue>FloatTensor.DivElemGPU_ dataOnGpu: {0}</color>", dataOnGpu);

            if (dataOnGpu)
            {
                if (tensor.id != this.id)
                {
                    shader.SetBuffer(DivElemKernel_, "DivElemDataA_", dataBuffer);
                    shader.SetBuffer(DivElemKernel_, "DivElemDataB_", tensor.dataBuffer);
                    shader.Dispatch(DivElemKernel_, this.size, 1, 1);
                }
                else
                {
                    tensor.Zero_();
                    tensor.Add(1, inline: true);
                }
            }
        }
        public FloatTensor DivElemGPU(FloatTensor tensor, FloatTensor result)
        {
            Debug.LogFormat("<color=blue>FloatTensor.DivElemGPU dataOnGpu: {0}</color>", dataOnGpu);

            if (dataOnGpu)
            {
                if (tensor.id != this.id)
                {
                    shader.SetBuffer(DivElemKernel, "DivElemDataA", dataBuffer);
                    shader.SetBuffer(DivElemKernel, "DivElemDataB", tensor.dataBuffer);
                    shader.SetBuffer(DivElemKernel, "DivElemDataResult", result.dataBuffer);
                    shader.Dispatch(DivElemKernel, this.size, 1, 1);
                }
                else
                {
                    result.Add(1, inline: true);
                    return(result);
                }
            }
            return(result);
        }
Example #6
0
        public string processMessage(Command msgObj, SyftController ctrl)
        {
            switch (msgObj.functionCall)
            {
            case "abs_":
            {
                // calls the function on our tensor object
                this.Abs_();
                // returns the function call name with the OK status
                return(this.Id + "");
            }

            case "add_":
            {
                this.Add_((float)msgObj.tensorIndexParams[0]);
                return(msgObj.functionCall + ": OK");
            }

            case "add":
            {
                FloatTensor tensor_1 = ctrl.getTensor(msgObj.tensorIndexParams [0]);
                FloatTensor output   = tensor_1.Add(tensor_1);
                return(ctrl.addTensor(output).ToString());
            }

            case "addmm_":
            {
                FloatTensor tensor_1 = ctrl.getTensor(msgObj.tensorIndexParams [0]);
                FloatTensor tensor_2 = ctrl.getTensor(msgObj.tensorIndexParams [1]);
                this.AddMatrixMultiply(tensor_1, tensor_2);
                return(msgObj.functionCall + ": OK");
            }

            case "ceil":
            {
                this.Ceil();
                return(msgObj.functionCall + ": OK");
            }

            case "cpu":
            {
                this.Cpu();
                return(msgObj.functionCall + ": OK");
            }

            case "gpu":
            {
                if (this.Gpu())
                {
                    return(msgObj.functionCall + ": OK : Moved data to GPU.");
                }
                else
                {
                    return(msgObj.functionCall + ": FAILED : Did not move data.");
                }
            }

            case "mul":
            {
                FloatTensor tensor_1 = ctrl.getTensor(msgObj.tensorIndexParams [0]);
                this.MulElementwise(tensor_1);
                return(msgObj.functionCall + ": OK");
            }

            case "mul_scalar":
            {
                this.MulScalar((float)msgObj.tensorIndexParams[0]);
                return(msgObj.functionCall + ": OK");
            }

            case "neg":
            {
                this.Neg();
                return(msgObj.functionCall + ": OK");
            }

            case "print":
            {
                bool dataOriginallyOnGpu = dataOnGpu;
                if (dataOnGpu)
                {
                    this.Cpu();
                }

                string data = string.Join(", ", this.Data);
                Debug.LogFormat("<color=cyan>print:</color> {0}", data);

                if (dataOriginallyOnGpu)
                {
                    this.Gpu();
                }

                return(data);
            }

            case "sub_":
            {
                FloatTensor tensor_1 = ctrl.getTensor(msgObj.tensorIndexParams [0]);
                this.ElementwiseSubtract(tensor_1);
                return(msgObj.functionCall + ": OK");
            }

            case "zero_":
            {
                this.Zero_();
                return(msgObj.functionCall + ": OK");
            }

            default: break;
            }
            return("SyftController.processMessage: Command not found.");
        }