コード例 #1
0
        private List <FunctionParameter> ParseOutParams(string function)
        {
            var outParams = new List <FunctionParameter>();

            string functionHeader = SourceHelper.ExtractFunctionHeader(function);

            string[] headerSplit = functionHeader.Split(',');

            foreach (string variable in headerSplit)
            {
                string[] variableSplit = variable.Trim().Split(' ');

                if (variableSplit.Length == 3 && variableSplit[0] == "out")
                {
                    outParams.Add(new FunctionParameter
                    {
                        // Fix any parameter names that come at the end of the function
                        Name = variableSplit[2].Replace(")", string.Empty),
                        Type = variableSplit[1]
                    });
                }
            }

            return(outParams);
        }
コード例 #2
0
ファイル: KernelManager.cs プロジェクト: stauders/SpaceSim
        private static KernelFile CreateKernel(string codePath, ConstantMapping constants, FunctionMapping functions)
        {
            string[] lines = File.ReadAllLines(codePath);

            int kernelIndex = SourceHelper.ParseDown(lines, "public void Run", 0);

            string kernelFunction = lines[kernelIndex];

            string kernelParameters = SourceHelper.ExtractFunctionHeader(kernelFunction);

            kernelParameters = kernelParameters.Replace("int[]", "global int*");
            kernelParameters = kernelParameters.Replace("float[]", "global float*");

            var clCode = new List <string>();

            if (IsFP64(kernelFunction))
            {
                clCode.Add("#pragma OPENCL EXTENSION cl_khr_fp64 : enable");
            }

            clCode.Add("kernel void Run " + kernelParameters);

            int codeEnd = lines.Length;

            for (int i = 0; i < 3; i++)
            {
                codeEnd = SourceHelper.ParseUp(lines, "}", codeEnd - 1);
            }

            for (int i = kernelIndex + 1; i < codeEnd + 1; i++)
            {
                clCode.Add(lines[i].Trim());
            }

            // Replace constants and inline functions
            functions.Inline(clCode);
            constants.Replace(clCode);

            return(new KernelFile {
                Code = string.Join("\n", clCode)
            });
        }