public IntTensor Sub(IntTensor x, bool inline = false) { IntTensor result = factory.Create(this.shape); if (dataOnGpu) { result.Gpu(shader); if (inline) { SubGPU_(x); return(this); } else { return(SubGPU(x, result)); } } else { result = inline ? this : factory.Create(this.shape); // run Subtraction on the CPU result.Data = data.AsParallel().Zip(x.Data.AsParallel(), (a, b) => a - b).ToArray(); return(result); } }
public IntTensor Abs(bool inline = false) { IntTensor result = factory.Create(this.shape); if (dataOnGpu) { result.Gpu(shader); if (inline) { AbsGPU_(); return(this); } else { return(AbsGPU(result)); } } if (inline) { this.Data = data.AsParallel().Select(x => Math.Abs(x)).ToArray(); return(this); } else { result.Data = data.AsParallel().Select(x => Math.Abs(x)).ToArray(); return(result); } }
public IntTensor Reciprocal(bool inline = false) { IntTensor result = factory.Create(this.shape); if (dataOnGpu) { if (inline) { int kernel_id = shader.FindKernel("ReciprocalInt_"); shader.SetBuffer(kernel_id, "ReciprocalIntData_", this.DataBuffer); shader.Dispatch(kernel_id, this.size, 1, 1); return(this); } else { result.Gpu(shader); int kernel_id = shader.FindKernel("ReciprocalInt"); shader.SetBuffer(kernel_id, "ReciprocalIntData", this.DataBuffer); shader.SetBuffer(kernel_id, "ReciprocalIntDataResult", result.DataBuffer); shader.Dispatch(kernel_id, this.size, 1, 1); return(result); } } if (inline) { this.Data = data.AsParallel().Select(x => (int)(1 / x)).ToArray(); return(this); } result.Data = data.AsParallel().Select(x => (int)(1 / x)).ToArray(); return(result); }
public IntTensor UnfoldGPU(int[] new_shape, int size, int dimSize, int sizeBeforeDim, int sizeAfterDim, int step) { IntTensor result = factory.Create(new_shape); result.Gpu(shader); int kernel_id = shader.FindKernel("UnfoldInt"); var sizeBuffer = SendIntToGpu(kernel_id, size, "UnfoldIntSize"); var dimSizeBuffer = SendIntToGpu(kernel_id, dimSize, "UnfoldIntDimSize"); var sizeBeforeDimBuffer = SendIntToGpu(kernel_id, sizeBeforeDim, "UnfoldIntSizeBeforeDim"); var sizeAfterDimBuffer = SendIntToGpu(kernel_id, sizeAfterDim, "UnfoldIntSizeAfterDim"); var stepBuffer = SendIntToGpu(kernel_id, step, "UnfoldIntStep"); shader.SetBuffer(kernel_id, "UnfoldIntData", this.DataBuffer); shader.SetBuffer(kernel_id, "UnfoldIntResult", result.DataBuffer); shader.Dispatch(kernel_id, result.size, 1, 1); sizeBuffer.Release(); dimSizeBuffer.Release(); sizeBeforeDimBuffer.Release(); sizeAfterDimBuffer.Release(); stepBuffer.Release(); return(result); }
public IntTensor Add(IntTensor x, bool inline = false) { IntTensor result = factory.Create(this.shape); if (dataOnGpu) { result.Gpu(shader); if (inline) { AddElemGPU_(x); return(this); } else { return(AddElemGPU(x, result)); } } else { // run Addition on the CPU if (inline) { Data = data.AsParallel().Zip(x.Data.AsParallel(), (a, b) => a + b).ToArray(); return(this); } else { result.Data = data.AsParallel().Zip(x.Data.AsParallel(), (a, b) => a + b).ToArray(); return(result); } } }
public IntTensor Add(IntTensor x, bool inline = false) { IntTensor result = factory.Create(this.shape); if (dataOnGpu) { // move result tensor to GPU - TODO: init on gpu instead result.Gpu(shader); // find kernel - TOOD: find all kernels in factory int kernel_id = shader.FindKernel("AddElemInt"); // set function parameters for kernel shader.SetBuffer(kernel_id, "AddElemIntDataA", this.DataBuffer); shader.SetBuffer(kernel_id, "AddElemIntDataB", x.DataBuffer); shader.SetBuffer(kernel_id, "AddElemIntDataResult", result.DataBuffer); // execute kernel shader.Dispatch(kernel_id, this.size, 1, 1); // return result return(result); } result.Data = data.AsParallel().Zip(x.Data.AsParallel(), (a, b) => a + b).ToArray(); return(result); }
public IntTensor Neg(bool inline = false, IntTensor result = null) { if (dataOnGpu) { if (!inline) { result = factory.Create(this.shape); result.Gpu(shader); int kernel_id = shader.FindKernel("NegateInt"); shader.SetBuffer(kernel_id, "NegateIntData", this.DataBuffer); shader.SetBuffer(kernel_id, "NegateIntResult", result.DataBuffer); shader.Dispatch(kernel_id, this.size, 1, 1); return(result); } else { result = this; int kernel_id = shader.FindKernel("NegateInt_"); shader.SetBuffer(kernel_id, "NegateIntData_", result.DataBuffer); shader.Dispatch(kernel_id, this.size, 1, 1); return(result); } } result = this; if (!inline) { result = factory.Create(this.shape); } result.Data = data.AsParallel().Select(x => - x).ToArray(); return(result); }
public IntTensor Neg(bool inline = false, IntTensor result = null) { if (dataOnGpu) { result.Gpu(shader); if (inline) { NegGPU_(); return(this); } else { result = factory.Create(this.shape); return(NegGPU(result)); } } result = this; if (!inline) { result = factory.Create(this.shape); } result.Data = data.AsParallel().Select(x => - x).ToArray(); return(result); }
public IntTensor Reciprocal(bool inline = false) { IntTensor result = factory.Create(this.shape); if (dataOnGpu) { result.Gpu(shader); if (inline) { ReciprocalGPU_(); return(this); } else { return(ReciprocalGPU(result)); } } if (inline) { this.Data = data.AsParallel().Select(x => (int)(1 / x)).ToArray(); return(this); } result.Data = data.AsParallel().Select(x => (int)(1 / x)).ToArray(); return(result); }