Пример #1
0
        public static byte[] EmitModule(IEnumerable <Tuple <MethodDeclarationSyntax, ISemanticModel> > kernels)
        {
            var module = new Module("Module", Context.Global);

            if (Environment.Is64BitOperatingSystem)
            {
                module.SetTarget("nvptx64-nvidia-cuda");
                module.SetDataLayout("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64");
            }
            else
            {
                module.SetTarget("nvptx-nvidia-cuda");
                module.SetDataLayout("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64");
            }

            foreach (var kernel in kernels)
            {
                Translate(module, kernel.Item1, kernel.Item2);
            }

            var ptx = PInvokeHelper.EmitInMemory(module, "sm_35");

            //llvmIr = Marshal.PtrToStringAnsi(PInvoke.LLVMPrintModuleToString(module));
            //ptxIr = Encoding.UTF8.GetString(ptx);
            return(ptx);
        }