public static bool SetParallel <T>(this ICompressibleActivation <T> compressibleActivation, bool enable, KeyValuePair <string, string>[] activationParameters = null) where T : unmanaged, IComparable <T> { compressibleActivation.IsParallel = enable & OpenCL.Enable; if (compressibleActivation.IsParallel) { string kernelNameBase = compressibleActivation.FunctionName.Replace(" ", ""); compressibleActivation.ActivateKernelString = OpenCL.GetKernelSource(Resources.Activation).Replace("/*kernelNameBase*/", kernelNameBase); compressibleActivation.ForwardKernelName = kernelNameBase + "Forward"; compressibleActivation.BackwardKernelName = kernelNameBase + "Backward"; string kernelSource = compressibleActivation.KernelSource; if (activationParameters != null) { foreach (var parameter in activationParameters) { kernelSource = kernelSource.Replace(parameter.Key, parameter.Value); } } kernelSource += compressibleActivation.ActivateKernelString; ComputeProgram program = OpenCL.CreateProgram <T>(kernelSource); compressibleActivation.ForwardKernel = program.CreateKernel(compressibleActivation.ForwardKernelName); compressibleActivation.BackwardKernel = program.CreateKernel(compressibleActivation.BackwardKernelName); } return(compressibleActivation.IsParallel); }
public bool SetParallel(bool enable) { KernelSource = OpenCL.GetKernelSource(Resources.TanhActivation); bool result = this.SetParallel <T>(enable); this.InitFunc(new StreamingContext()); return(result); }
public bool SetParallel(bool enable) { KernelSource = OpenCL.GetKernelSource(Resources.LeakyReLU); bool result = this.SetParallel <T>(enable, new[] { new KeyValuePair <string, string>(PARAM_NAME, this.Slope.ToString()) }); this.InitFunc(new StreamingContext()); return(result); }
public bool SetParallel(bool enable) { KernelSource = OpenCL.GetKernelSource(Resources.Dropout); this.IsParallel = enable & OpenCL.Enable; if (IsParallel) { ComputeProgram program = OpenCL.CreateProgram <T>(this.KernelSource); ForwardKernel = program.CreateKernel("DropoutForward"); BackwardKernel = program.CreateKernel("DropoutBackward"); } this.InitFunc(new StreamingContext()); return(IsParallel); }