public void LoadKernel(string filepath)
        {
            this.Log("Loading File: " + filepath, DebugChannel.Log, 8);
            string path   = Path.GetFullPath(filepath);
            string source = PPAPI.PreprocessSource(path, null);

            string[] kernelNames = FindKernelNames(source);

            foreach (var kernelName in kernelNames)
            {
                this.Log("Trying to Load Kernel: " + kernelName, DebugChannel.Log, 8);
                if (_kernels.ContainsKey(kernelName))
                {
                    this.Log("Kernel " + kernelName + " was already cached.", DebugChannel.Log, 7);
                    return;
                }

                this.Log("Building Program from source..", DebugChannel.Log, 8);
                CLProgram p = c.CreateAndBuildProgramFromString(source);
                int       kernelNameIndex = source.IndexOf(" " + kernelName + " ");
                kernelNameIndex = (kernelNameIndex == -1) ? source.IndexOf(" " + kernelName + "(") : kernelNameIndex;
                _kernels.Add(kernelName,
                             new CLFilter(kernelName, p.CreateKernel(kernelName),
                                          KernelParameter.CreateKernelParametersFromKernelCode(source, kernelNameIndex,
                                                                                               source.Substring(kernelNameIndex, source.Length - kernelNameIndex).IndexOf(')') + 1)));
            }
        }
        public void LoadKernel(string filepath, string kernel)
        {
            this.Log("Loading File: " + filepath, DebugChannel.Log, 8);
            string path = Path.GetFullPath(filepath);

            this.Log("Trying to Load Kernel:" + kernel, DebugChannel.Log, 8);
            if (_kernels.ContainsKey(kernel))
            {
                this.Log("Kernel " + kernel + " was already cached.", DebugChannel.Log, 7);
                return;
            }

            this.Log("Building Program from source..", DebugChannel.Log, 8);
            string    source          = File.ReadAllText(filepath);
            CLProgram p               = c.CreateAndBuildProgramFromString(source);
            int       kernelNameIndex = source.IndexOf(kernel);

            _kernels.Add(kernel, new CLFilter(kernel, p.CreateKernel(kernel),
                                              KernelParameter.CreateKernelParametersFromKernelCode(source, kernelNameIndex,
                                                                                                   source.Substring(kernelNameIndex, source.Length - kernelNameIndex).IndexOf(')') + 1)));
        }
Beispiel #3
0
        public static KernelParameter[] CreateKernelParametersFromKernelCode(string code, int startIndex, int endIndex)
        {
            string kernelHeader = code.Substring(startIndex, endIndex);
            int    start = kernelHeader.IndexOf('('), end = kernelHeader.LastIndexOf(')');
            string parameters = kernelHeader.Substring(start + 1, (end - start) - 1);

            string[]          pars = parameters.Split(',');
            KernelParameter[] ret  = new KernelParameter[pars.Length];
            for (int i = 0; i < pars.Length; i++)
            {
                string[] parametr = pars[i].Trim().Split(' ');

                ret[i] = new KernelParameter
                {
                    name     = parametr[parametr.Length - 1].Replace('*', ' ').Trim(),
                    dataType = GetDataType(parametr[parametr.Length - 2].Replace('*', ' ').Trim()),
                    memScope = GetMemoryScope(parametr.Length == 3 ? parametr[0] : ""),
                    isArray  = (parametr[parametr.Length - 2].IndexOf("*") != -1 ||
                                parametr[parametr.Length - 1].IndexOf("*") != -1),
                    id = i
                };
            }
            return(ret);
        }