示例#1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Creates the kernel. </summary>
        ///
        /// <seealso cref="M:KelpNet.Common.Functions.IParallelizable.CreateKernel()"/>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public void CreateKernel()
        {
            if (GpuEnable)
            {
                ForwardKernel = Weaver.CreateProgram(Weaver.GetKernelSource(FUNCTION_NAME)).CreateKernel("MaxPoolingForward");
            }
        }
示例#2
0
        public void CreateKernel()
        {
            string         kernelSource = Weaver.GetKernelSource(FUNCTION_NAME);
            ComputeProgram program      = Weaver.CreateProgram(kernelSource);

            ForwardKernel  = program.CreateKernel("DropoutForward");
            BackwardKernel = program.CreateKernel("DropoutBackward");
        }
        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);
        }
示例#4
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <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 CompressibleLayer(bool verbose, [NotNull] string functionName, [CanBeNull] CompressibleActivationLayer 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);

            _activationParameters = activationParameters;

            SetActivation(activation);

            SetGpuEnable(gpuEnable);
        }
示例#5
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Initializes a new instance of the KelpNet.Common.Functions.CompressibleActivation class.
        /// </summary>
        ///
        /// <param name="functionName"> Name of the function. </param>
        /// <param name="parameters">   Options for controlling the operation. </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 CompressibleActivation([NotNull] string functionName, [CanBeNull] KeyValuePair <string, string>[] parameters, [CanBeNull] string name = FUNCTION_NAME, [CanBeNull] string[] inputNames = null, [CanBeNull] string[] outputNames = null, bool gpuEnable = false) : base(name, inputNames, outputNames)
        {
            string kernelNameBase = functionName?.Replace(" ", string.Empty);

            ForwardKernelName  = kernelNameBase + string.Intern("Forward");
            BackwardKernelName = kernelNameBase + string.Intern("Backward");

            ActivateKernelString   = Weaver.GetKernelSource(FUNCTION_NAME)?.Replace("/*kernelNameBase*/", kernelNameBase);
            ActivateFunctionString = Weaver.GetKernelSource(functionName);

            if (parameters != null)
            {
                foreach (var parameter in parameters)
                {
                    ActivateFunctionString = ActivateFunctionString?.Replace(parameter.Key, parameter.Value);
                }
            }

            SetGpuEnable(gpuEnable);
        }
        protected CompressibleActivation(string functionName, KeyValuePair <string, string>[] parameters, 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.BackwardKernelName = kernelNameBase + "Backward";

            this.ActivateKernelString   = Weaver.GetKernelSource(FUNCTION_NAME).Replace("/*kernelNameBase*/", kernelNameBase);
            this.ActivateFunctionString = Weaver.GetKernelSource(functionName);

            if (parameters != null)
            {
                foreach (var parameter in parameters)
                {
                    this.ActivateFunctionString = this.ActivateFunctionString.Replace(parameter.Key, parameter.Value);
                }
            }

            this.SetGpuEnable(gpuEnable);
        }
示例#7
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <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);
        }