Exemple #1
0
        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);
        }
Exemple #2
0
        public static bool SetParallel <T>(this ICompressibleFunction <T> compressibleFunction, bool enable) where T : unmanaged, IComparable <T>
        {
            compressibleFunction.IsParallel = enable & OpenCL.Enable;

            if (compressibleFunction.IsParallel)
            {
                string kernelNameBase = compressibleFunction.FunctionName.Replace(" ", "");
                compressibleFunction.ForwardKernelName    = kernelNameBase + "Forward";
                compressibleFunction.BackwardgWKernelName = kernelNameBase + "gWBackward";
                compressibleFunction.BackwardgXKernelName = kernelNameBase + "gXBackward";

                string kernelSource = compressibleFunction.KernelSource;

                if (compressibleFunction.Activation is ICompressibleActivation <T> activator)
                {
                    //アクティベーションを活性化
                    kernelSource = activator.KernelSource + kernelSource.Replace("/*ForwardActivate*/", "ForwardActivate");
                }

                ComputeProgram program = OpenCL.CreateProgram <T>(kernelSource);
                compressibleFunction.ForwardKernel    = program.CreateKernel(compressibleFunction.ForwardKernelName);
                compressibleFunction.BackwardgWKernel = program.CreateKernel(compressibleFunction.BackwardgWKernelName);
                compressibleFunction.BackwardgXKernel = program.CreateKernel(compressibleFunction.BackwardgXKernelName);
            }

            return(compressibleFunction.IsParallel);
        }
        public bool SetParallel(bool enable)
        {
            this.IsParallel = enable & OpenCL.Enable;

            if (IsParallel)
            {
                ForwardKernel = OpenCL.CreateProgram(KernelSource).CreateKernel("MaxPoolingForward");
            }

            return(IsParallel);
        }
Exemple #4
0
        public bool SetParallel(bool enable)
        {
            this.IsParallel = enable & OpenCL.Enable;

            if (IsParallel)
            {
                ForwardKernel = OpenCL.CreateProgram <T>(KernelSource).CreateKernel("MaxPoolingForward");
            }

            InitFunc(new StreamingContext());
            return(IsParallel);
        }
Exemple #5
0
        public bool SetParallel(bool enable)
        {
            this.IsParallel = enable & OpenCL.Enable;

            if (IsParallel)
            {
                ComputeProgram program = OpenCL.CreateProgram(this.KernelSource);

                ForwardKernel  = program.CreateKernel("DropoutForward");
                BackwardKernel = program.CreateKernel("DropoutBackward");
            }

            return(IsParallel);
        }
Exemple #6
0
        public bool SetParallel(bool enable)
        {
            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);
        }