Exemple #1
0
        public CLProgram AddProgram(CLAPI instance, string file, bool throwEx, out CLProgramBuildResult ex)
        {
            ex = new CLProgramBuildResult(file, "", new List <CLProgramBuildError>());

            if (!File.Exists(file))
            {
                Exception e = new FileNotFoundException("File not found: " + file);

                if (throwEx)
                {
                    throw e;
                }

                ex.BuildErrors.Add(new CLProgramBuildError(ErrorType.ProgramBuild, e));
            }

            string path = file;

            Logger.Log(LogType.Log, "Creating CLProgram from file: " + file, 3);
            CLProgramBuildResult br = CLProgram.TryBuildProgram(instance, path, out CLProgram program);

            ex.Source = br.Source;

            if (!br)
            {
                if (throwEx)
                {
                    throw br.GetAggregateException();
                }

                ex.BuildErrors.AddRange(br.BuildErrors);

                return(null);
            }

            loadedPrograms.Add(program);

            foreach (KeyValuePair <string, CLKernel> containedKernel in program.ContainedKernels)
            {
                if (!loadedKernels.ContainsKey(containedKernel.Key))
                {
                    Logger.Log(LogType.Log, "Adding Kernel: " + containedKernel.Key, 4);
                    loadedKernels.Add(containedKernel.Key, containedKernel.Value);
                }
                else
                {
                    Logger.Log(
                        LogType.Log,
                        "Kernel with name: " + containedKernel.Key + " is already loaded. Skipping...",
                        5
                        );
                }
            }

            return(program);
        }
Exemple #2
0
        public CLProgram AddProgram(
            CLAPI instance,
            string source,
            string filePath,
            bool throwEx,
            out CLProgramBuildResult ex)
        {
            ex = new CLProgramBuildResult(filePath, "", new List <CLProgramBuildError>());
            CLProgramBuildResult br = CLProgram.TryBuildProgram(instance, source, filePath, out CLProgram program);

            ex.Source = br.Source;

            if (!br)
            {
                if (throwEx)
                {
                    throw br.GetAggregateException();
                }

                ex.BuildErrors.AddRange(br.BuildErrors);

                return(null);
            }

            loadedPrograms.Add(program);

            foreach (KeyValuePair <string, CLKernel> containedKernel in program.ContainedKernels)
            {
                if (!loadedKernels.ContainsKey(containedKernel.Key))
                {
                    Logger.Log(LogType.Log, "Adding Kernel: " + containedKernel.Key, 4);
                    loadedKernels.Add(containedKernel.Key, containedKernel.Value);
                }
                else
                {
                    Logger.Log(
                        LogType.Log,
                        "Kernel with name: " + containedKernel.Key + " is already loaded. Skipping...",
                        5
                        );
                }
            }

            return(program);
        }