Example #1
0
 /// <summary>
 /// Constructs a new compiled kernel in OpenCL source form.
 /// </summary>
 /// <param name="context">The associated context.</param>
 /// <param name="entryPoint">The entry point.</param>
 /// <param name="source">The source code.</param>
 /// <param name="version">The OpenCL C version.</param>
 public CLCompiledKernel(
     Context context,
     SeparateViewEntryPoint entryPoint,
     string source,
     CLCVersion version)
     : base(context, entryPoint)
 {
     Source   = source;
     CVersion = version;
 }
Example #2
0
        /// <summary>
        /// Tries to parse the given string expression into an OpenCL C version.
        /// </summary>
        /// <param name="expression">The expression to parse.</param>
        /// <param name="version">The parsed version (if any).</param>
        /// <returns>True, if the given expression could be parsed into an OpenCL C version.</returns>
        public static bool TryParse(string expression, out CLCVersion version)
        {
            version = default;
            var match = VersionRegex.Match(expression);

            if (!match.Success)
            {
                return(false);
            }
            version = new CLCVersion(
                int.Parse(match.Groups[2].Value),
                int.Parse(match.Groups[3].Value));
            return(true);
        }
Example #3
0
        /// <summary>
        /// Constructs a new OpenCL source backend.
        /// </summary>
        /// <param name="context">The context to use.</param>
        /// <param name="capabilities">The supported capabilities.</param>
        /// <param name="vendor">The associated major vendor.</param>
        /// <param name="clStdVersion">The OpenCL C version passed to -cl-std.</param>
        public CLBackend(
            Context context,
            CLCapabilityContext capabilities,
            CLDeviceVendor vendor,
            CLCVersion clStdVersion)
            : base(
                context,
                capabilities,
                BackendType.OpenCL,
                new CLArgumentMapper(context))
        {
            Vendor       = vendor;
            CLStdVersion = clStdVersion;

            InitIntrinsicProvider();
            InitializeKernelTransformers(builder =>
            {
                var transformerBuilder = Transformer.CreateBuilder(
                    TransformerConfiguration.Empty);
                transformerBuilder.AddBackendOptimizations <CodePlacement.GroupOperands>(
                    new CLAcceleratorSpecializer(
                        PointerType,
                        Context.Properties.EnableIOOperations),
                    context.Properties.InliningMode,
                    context.Properties.OptimizationLevel);
                builder.Add(transformerBuilder.ToTransformer());
            });

            // Build a list of extensions to enable for each OpenCL kernel.
            var extensionBuilder = new StringBuilder();

            foreach (var extensionName in Capabilities.Extensions)
            {
                extensionBuilder.Append("#pragma OPENCL EXTENSION ");
                extensionBuilder.Append(extensionName);
                extensionBuilder.AppendLine(" : enable");
            }
            extensions = extensionBuilder.ToString();
        }