//後からActivationを追加する用 public void SetActivation(CompressibleActivation activation) { this.Activator = activation; if (this.Activator != null) { foreach (var activationParameterer in this._activationParameters) { this.KernelString = this.KernelString.Replace(activationParameterer.Key, activationParameterer.Value); } } //Kernelの再構築が必要 CreateKernel(); }
protected CompressibleFunction(string functionName, CompressibleActivation activation = null, KeyValuePair <string, string>[] activationParameters = null, string name = FUNCTION_NAME, string[] inputNames = null, string[] outputNames = null, bool gpuEnable = false) : base(name, inputNames, outputNames) { string kernelNameBase = functionName.Replace(" ", ""); this.ForwardKernelName = kernelNameBase + "Forward"; this.BackwardgWKernelName = kernelNameBase + "gWBackward"; this.BackwardgXKernelName = kernelNameBase + "gXBackward"; this.KernelString = Weaver.GetKernelSource(functionName); this._activationParameters = activationParameters; this.SetActivation(activation); this.SetGpuEnable(gpuEnable); }
//For later adding Activation public void SetActivation(CompressibleActivation activation) { this.Activator = activation; if (this.Activator != null) { foreach (var activationParameterer in _activationParameters) { KernelString = KernelString.Replace(activationParameterer.Key, activationParameterer.Value); } } //Kernel rebuild is necessary if (this.GpuEnable) { CreateKernel(); } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> For later adding Activation </summary> /// /// <param name="activation"> The activation. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// public void SetActivation([CanBeNull] CompressibleActivation activation) { Activator = activation; if (Activator != null) { foreach (var activationParameter in _activationParameters) { if (Verbose) { RILogManager.Default?.SendDebug("SetActivation -> Replacing " + activationParameter.Key + " with " + activationParameter.Value); RILogManager.Default?.SendDebug("New KernelString is " + KernelString); } KernelString = KernelString?.Replace(activationParameter.Key, activationParameter.Value); } } CreateKernel(); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes a new instance of the KelpNet.Common.Functions.CompressibleFunction class. /// </summary> /// /// <param name="functionName"> Name of the function. </param> /// <param name="activation"> (Optional) The activation. </param> /// <param name="activationParameters"> (Optional) Options for controlling the activation. </param> /// <param name="name"> (Optional) The name. </param> /// <param name="inputNames"> (Optional) List of names of the inputs. </param> /// <param name="outputNames"> (Optional) List of names of the outputs. </param> /// <param name="gpuEnable"> (Optional) True if GPU enable. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// protected CompressibleFunction(bool verbose, [NotNull] string functionName, [CanBeNull] CompressibleActivation activation = null, [CanBeNull] KeyValuePair <string, string>[] activationParameters = null, [CanBeNull] string name = FUNCTION_NAME, [CanBeNull] string[] inputNames = null, [CanBeNull] string[] outputNames = null, bool gpuEnable = false) : base(name, inputNames, outputNames) { Verbose = verbose; string kernelNameBase = functionName.Replace(" ", string.Empty); ForwardKernelName = kernelNameBase + string.Intern("Forward"); BackwardgWKernelName = kernelNameBase + string.Intern("gWBackward"); BackwardgXKernelName = kernelNameBase + string.Intern("gXBackward"); KernelString = Weaver.GetKernelSource(functionName); if (Verbose) { RILogManager.Default?.SendDebug("New ForwardKernelName is " + ForwardKernelName); RILogManager.Default?.SendDebug("New BackwardgWKernelName is " + BackwardgWKernelName); RILogManager.Default?.SendDebug("New BackwardgXKernelName is " + BackwardgXKernelName); RILogManager.Default?.SendDebug("New KernelString is " + KernelString); } _activationParameters = activationParameters; SetActivation(activation); SetGpuEnable(gpuEnable); }