예제 #1
0
        /// <summary>
        /// Compiles the kernel.
        /// </summary>
        /// <param name="cls">The CLS.</param>
        public override void CompileKernel(Type cls)
        {
            StringBuilder source = new StringBuilder();

            source.AppendLine("#ifdef cl_khr_fp64");
            source.AppendLine("#pragma OPENCL EXTENSION cl_khr_fp64 : enable");
            source.AppendLine("#endif");
            source.AppendLine("#define NELEMS(x)  (sizeof(x) / sizeof((x)[0]))");
            source.AppendLine("typedef unsigned char byte;");
            source.AppendLine("typedef char sbyte;");
            if (_compiledInstances.Contains(cls))
            {
                throw new CompileException(string.Format("{0} is already compiled", cls.FullName));
            }

            _compiledInstances.Add(cls);
            _compiledInstances = _compiledInstances.OrderByDescending(x => (x.IsLayoutSequential)).ToList();
            KernelFunctions.Clear();
            foreach (var item in _compiledInstances)
            {
                if (item.IsLayoutSequential)
                {
                    source.AppendLine(GetStructCode(item));
                }
                else if (item.IsClass)
                {
                    source.AppendLine(GetKernelCode(item));
                }
            }

            CreateKernels(source.ToString());
            SourceCode = source.ToString();
        }
예제 #2
0
        /// <summary>
        /// Compiles the kernel directly from the source.
        /// </summary>
        /// <param name="source">The source code.</param>
        public override void CompileKernel(string source)
        {
            KernelFunctions.Clear();
            StringBuilder src = new StringBuilder();

            src.AppendLine("#ifdef cl_khr_fp64");
            src.AppendLine("#pragma OPENCL EXTENSION cl_khr_fp64 : enable");
            src.AppendLine("#endif");
            src.AppendLine("#define NELEMS(x)  (sizeof(x) / sizeof((x)[0]))");
            src.AppendLine("typedef unsigned char byte;");
            src.AppendLine("typedef char sbyte;");
            src.AppendLine(source);

            CreateKernels(src.ToString());
            SourceCode = src.ToString();
        }