示例#1
0
        /// <summary>
        /// Loads the source and initializes the CLProgram
        /// </summary>
        private void Initialize(CLAPI instance)
        {
            int vnum = GetVectorNum(genType);

            string source = TextProcessorAPI.PreprocessSource(filePath, new Dictionary <string, bool>());

            string[] kernelNames = FindKernelNames(source);

            ClProgramHandle = CLAPI.CreateClProgramFromSource(instance, source);


            foreach (string kernelName in kernelNames)
            {
                Kernel k = CLAPI.CreateKernelFromName(ClProgramHandle, kernelName);
                int    kernelNameIndex = source.IndexOf(" " + kernelName + " ", StringComparison.InvariantCulture);
                kernelNameIndex = kernelNameIndex == -1
                    ? source.IndexOf(" " + kernelName + "(", StringComparison.InvariantCulture)
                    : kernelNameIndex;
                KernelParameter[] parameter = KernelParameter.CreateKernelParametersFromKernelCode(source,
                                                                                                   kernelNameIndex,
                                                                                                   source.Substring(kernelNameIndex, source.Length - kernelNameIndex).IndexOf(')') + 1);
                if (k == null)
                {
                    ContainedKernels.Add(kernelName, new CLKernel(instance, null, kernelName, parameter));
                }
                else
                {
                    ContainedKernels.Add(kernelName, new CLKernel(instance, k, kernelName, parameter));
                }
            }
        }
示例#2
0
        /// <summary>
        /// Parses the kernel parameters from the kernel signature
        /// </summary>
        /// <param name="code">The full program code</param>
        /// <param name="startIndex">The index where the kernel name starts</param>
        /// <param name="endIndex">the index after the bracket of the signature closed</param>
        /// <returns>A parsed list of Kernel parameters</returns>
        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("*", StringComparison.InvariantCulture) != -1 ||
                               parametr[parametr.Length - 1].IndexOf("*", StringComparison.InvariantCulture) != -1,
                    Id = i
                };
            }

            return(ret);
        }
示例#3
0
        /// <summary>
        /// Public constructor
        /// </summary>
        /// <param name="instance">CLAPI Instance for the current thread</param>
        /// <param name="folderName">Folder name where the kernels are located</param>
        /// <param name="genDataType">The DataTypes used to compile the FL Database</param>
        public KernelDatabase(CLAPI instance, string folderName, TypeEnums.DataTypes genDataType)
        {
            GenDataType = KernelParameter.GetDataString(genDataType);
            if (!CLAPI.DirectoryExists(folderName))
            {
                throw new Exception(folderName);
            }

            this.folderName = folderName;
            LoadedKernels   = new Dictionary <string, CLKernel>();
            Initialize(instance);
        }
示例#4
0
        /// <summary>
        /// Public constructor
        /// </summary>
        /// <param name="instance">CLAPI Instance for the current thread</param>
        /// <param name="folderName">Folder name where the kernels are located</param>
        /// <param name="genDataVectorType">The DataVectorTypes used to compile the FL Database</param>
        public KernelDatabase(CLAPI instance, string folderName, TypeEnums.DataVectorTypes genDataVectorType) : base(
                OpenCLDebugConfig.Settings)
        {
            GenDataType = KernelParameter.GetDataString(genDataVectorType);
            if (!IOManager.DirectoryExists(folderName))
            {
                throw new OpenClException("Can not find directory: " + folderName);
            }

            this.folderName = folderName;
            loadedPrograms  = new List <CLProgram>();
            loadedKernels   = new Dictionary <string, CLKernel>();
            Initialize(instance);
        }