<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<blockquote style="border-color: rgb(200, 200, 200); border-left: 3px solid rgb(200, 200, 200); padding-left: 1ex; margin-left: 0.8ex; color: rgb(102, 102, 102);" itemscope="" itemtype="https://schemas.microsoft.com/QuotedText">
<div dir="ltr">
<div class="x_gmail_quote"><span>There's definitely some consensus or even roadmap/timeline on this transition missing IMO :)  And pls forgive me my possibly stupid question, but is there any way now to _conveniently_ incorporate MLIR flow for projects which
 are based on a good old clang->llvm->mir->machinecode way? I understand we have 'llvm' dialect and may recall last year there was a talk about the common C/C++ dialect, but it isn't public yet, is it?</span>
<div></div>
</div>
</div>
<div><br>
</div>
<span>Not that I am aware of, but I haven't followed the most recent development either! We're very interested into looking into this though :)</span><br>
</blockquote>
</div>
<div id="appendonsend"></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
FYI there was this thread about CIL last month</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<a href="https://lists.llvm.org/pipermail/cfe-dev/2021-February/067654.html" title="https://lists.llvm.org/pipermail/cfe-dev/2021-February/067654.html">https://lists.llvm.org/pipermail/cfe-dev/2021-February/067654.html</a>.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
It didn’t get a lot of traction yet but I think
<div>this topic could become more interesting to the community in the future. I am not</div>
<div>sure the IR generation in Clang can be completely replaced but CIL could certainly</div>
<div>start as an experimental alternative format that Clang could emit. I do believe it will</div>
<div>take a while until it will catch up with the quality and functionality that IR generation</div>
<div>provides. </div>
<div><br>
</div>
<div>Speaking on behalf of the OpenCL community that will greatly benefit from the<br>
</div>
<div>SPIR-V generation for OpenCL kernel languages in the LLVM project, having an</div>
<div>LLVM backend would improve the user experience and facilitate many other</div>
<div>improvements in Clang and LLVM for the OpenCL devices that are now blocked on</div>
<div>the unavailability of a common target that vendors without in-tree LLVM backend can</div>
<div>contribute to. The backend will also be the easiest way to integrate with the Clang</div>
<div>frontend because it is a conventional route. </div>
<div><br>
</div>
<div>I do acknowledge that MLIR can provide many benefits to the OpenCL community,
</div>
<div>however, on the Clang side a different approach than what is available right now
</div>
<div>would probably make more sense. It would be better to go via CIL i.e. Clang </div>
<div>would emit CIL flavor of MLIR that would then get converted to the SPIR-V flavor
</div>
<div>of MLIR bypassing the LLVM IR. This would be a preferable route but in order to
</div>
<div>support CIL for OpenCL we would need to have the support for C/C++ first as it
</div>
<div>is just a thin layer on top of the core languages that Clang supports. So this
</div>
<div>is not something we can target at the moment because we will likely depend on</div>
<div>the will and the time investment from the C/C++ community for that.</div>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Cheers,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Anastasia<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> llvm-dev <llvm-dev-bounces@lists.llvm.org> on behalf of Mehdi AMINI via llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Sent:</b> 02 March 2021 23:48<br>
<b>To:</b> Aleksandr Bezzubikov <zuban32s@gmail.com><br>
<b>Cc:</b> llvm-dev@lists.llvm.org <llvm-dev@lists.llvm.org>; Trifunovic, Konrad <konrad.trifunovic@intel.com>; aleksandr.bezzubikov@intel.com <aleksandr.bezzubikov@intel.com><br>
<b>Subject:</b> Re: [llvm-dev] [RFC] Upstreaming a proper SPIR-V backend</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr"><br>
</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Tue, Mar 2, 2021 at 3:45 PM Aleksandr Bezzubikov <<a href="mailto:zuban32s@gmail.com">zuban32s@gmail.com</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div>Please some some comments inlined</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Wed, Mar 3, 2021 at 2:19 AM James Y Knight via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div dir="ltr"></div>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Tue, Mar 2, 2021 at 4:40 PM Mehdi AMINI via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">On Tue, Mar 2, 2021 at 3:07 AM Trifunovic, Konrad via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
</div>
<div class="x_gmail_quote">
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
Hi,<br>
<br>
A very good question. I was actually expecting it 😊<br>
<br>
So, at the moment, it does not integrate into MLIR SPIRV backend and we have not thought about it. I guess You are referring to having a SPV dialect in MLIR and using a 'serialize' option to produce a SPIR-V binary?<br>
<br>
I agree that developing two backends in parallel is a bit redundant. If SPIR-V LLVM backend becomes a production quality it means actually it could consume any LLVM IR (provided it does conform to some SPIR-V restrictions).<br>
By any LLVM IR input I mean: it should be irrelevant whether it is produced by a clang, MLIR to LLVM IR lowering or just some other front-end that produces LLVM IR.</blockquote>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
The biggest 'impedance mismatch' that I currently see is that SPV MLIR dialect is now targeted mostly at Vulkan, while LLVM SPIR-V backend targets compute. Besides instruction set, the fundamental difference is a memory model.<br>
So if we want to unify those, we should actually make SPIR-V LLVM backend able to produce Vulkan dialect of SPIR-V as well.<br>
<br>
My answer is a bit elusive, but I totally agree with Your proposal: we should work towards having a one solution, and, LLVM SPIR-V backend seems like a more universal one (since it sits lower in the compiler stack).<br>
My proposal would be to include some MLIR -> LLVM-IR translated code in the testing so to have this final goal in mind.<br>
</blockquote>
<div><br>
</div>
<div>
<div style="color:rgb(0,0,0)">Something you're missing here, and maybe Lei clarified but I'll reiterate: the SPIRV dialect in MLIR is equivalent to what your GlobalISel pass will produce. It can actually round-trip to/from the SPIRV binary format. So it is
 sitting lower than your backend in my view.</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>What do you mean by lower? I'm not that familiar with the way MLIR deals with SPIR-V binaries, but isn't it still necessary to convert SPIR-V dialect to LLVM and then use some hardware-tied codegen to be able to _run_ a SPIR-V binary? </div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>What you're describing seems a bit orthogonal to the SPIRV backend: you're asking "how would someone run a SPIRV binary". That up to the SPIRV runtime implementation (it may or may not use LLVM to JIT the SPIRV to the native platform).</div>
<div>From what I understand, the proposal about a backend here is exclusively about a "LLVM -> SPIRV" flow, i.e. SPIRV is the abstract ISA (like NVPTX) and the final target of the workflow.</div>
<div><br>
</div>
<div> </div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div class="x_gmail_quote">
<div> </div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div class="x_gmail_quote">
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div class="x_gmail_quote">
<div>
<div style="color:rgb(0,0,0)">I can't figure out a situation where it would make sense to go from MLIR SPIRV dialect to LLVM to use this new backend, but I may miss something here...</div>
<div style="color:rgb(0,0,0)"><br>
</div>
</div>
<div style="color:rgb(0,0,0)">It would be really great to find a common path here before duplicating a lot of the same thing in the lllvm-project monorepo, for example being able to target the MLIR dialect from GlobalISel, or alternatively converting the MIR
 to it right after would be an interesting thing to explore.</div>
<div style="color:rgb(0,0,0)">I haven't seen it, but there was a talk last Sunday on this topic: <a href="https://llvm.org/devmtg/2021-02-28/#vm1" target="_blank">https://llvm.org/devmtg/2021-02-28/#vm1</a></div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>Oh, this sounds interesting actually. Would be nice if someone has any materials or code to share on the topic.<br>
</div>
<div> </div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div class="x_gmail_quote">
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div class="x_gmail_quote">
<div style="color:rgb(0,0,0)"><span style="color:rgb(34,34,34)"></span></div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>This sort of problem seems like just one of those unfortunate consequences of MLIR being effectively an "LLVM IR 2.0 -- Generic Edition", but not yet actually layered underneath LLVM where it really wants to be. I think it doesn't really make sense to
 tie <i>this</i> project to those long-term goals of layering MLIR under LLVM-IR, given the extremely long timescale that is likely to occur in. The "proper" solution probably won't be possible any time soon.</div>
<div><br>
</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>There's definitely some consensus or even roadmap/timeline on this transition missing IMO :)  And pls forgive me my possibly stupid question, but is there any way now to _conveniently_ incorporate MLIR flow for projects which are based on a good old clang->llvm->mir->machinecode
 way? I understand we have 'llvm' dialect and may recall last year there was a talk about the common C/C++ dialect, but it isn't public yet, is it?</div>
<div></div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>Not that I am aware of, but I haven't followed the most recent development either! We're very interested into looking into this though :)</div>
<div><br>
</div>
<div> </div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div class="x_gmail_quote">
<div> </div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div class="x_gmail_quote">
<div></div>
<div>So, in the meantime, we could implement a special-case hack just for SPIRV, to enable lowering it to MLIR-SPIRV dialect. But, what's the purpose? It wouldn't really help move towards the longer term goal, I don't think? And if someone does need that at
 the moment, they can just feed the SPIRV binary format back into the existing MLIR SPIRV dialect, right?</div>
</div>
</div>
</blockquote>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div class="x_gmail_quote">
<div><br>
</div>
<div><br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div class="x_gmail_quote">
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
PS: one more thought: SPIR-V does come with a set of builtin/intrinsic functions that expose the full capabilities of target architecture (mostly GPU). This set of intrinsics is actually a dialect in its own. So this is LLVM IR + SPIR-V specific intrinsics
 and their semantics that fully define the SPIR-V dialect at LLVM IR level. I believe this idea could be used in MLIR path: MLIR -> LLVM-IR with SPIR-V intrinsics (let's call it a LLVM IR SPIR-V dialect) -> SPIR-V binary (generated by a backend). So the idea
 of 'SPIR-V dialect' still exists, it is just now expressed at the LLVM IR level. </blockquote>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left-width:1px; border-left-style:solid; border-left-color:rgb(204,204,204); padding-left:1ex">
<br>
regards,<br>
konrad<br>
<br>
> From: Renato Golin <<a href="mailto:rengolin@gmail.com" target="_blank">rengolin@gmail.com</a>>
<br>
> Sent: Tuesday, March 2, 2021 11:12 AM<br>
> To: Trifunovic, Konrad <<a href="mailto:konrad.trifunovic@intel.com" target="_blank">konrad.trifunovic@intel.com</a>><br>
> Cc: <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>; Paszkowski, Michal <<a href="mailto:michal.paszkowski@intel.com" target="_blank">michal.paszkowski@intel.com</a>>; Bezzubikov, Aleksandr <<a href="mailto:aleksandr.bezzubikov@intel.com" target="_blank">aleksandr.bezzubikov@intel.com</a>>;
 Tretyakov, Andrey1 <<a href="mailto:andrey1.tretyakov@intel.com" target="_blank">andrey1.tretyakov@intel.com</a>><br>
> Subject: Re: [llvm-dev] [RFC] Upstreaming a proper SPIR-V backend<br>
> <br>
> On Tue, 2 Mar 2021 at 09:36, Trifunovic, Konrad via llvm-dev <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
> Hi all,<br>
> <br>
> We would like to propose this RFC for upstreaming a proper SPIR-V backend to LLVM:<br>
> <br>
> Hi,<br>
> <br>
> Perhaps a parallel question: how does that integrate with MLIR's SPIRV back-end?<br>
> <br>
> If this proposal goes through and we have a production-quality SPIRV back-end in LLVM, do we remove MLIR's own version and lower to LLVM, then to SPIRV? Or do we still need the MLIR version?<br>
> <br>
> In a perfect world, translating to LLVM IR then to SPIRV shouldn't make a difference, but there could be some impedance mismatch between MLIR->LLVM lowering that isn't compatible with SPIRV?<br>
> <br>
> But as a final goal, if SPIRV becomes an official LLVM target, it would be better if we could iron out the impedance problems and keep only one SPIRV backend.<br>
> <br>
> cheers,<br>
> --renato<br>
><br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote>
</div>
</div>
</div>
</div>
</div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote>
</div>
</div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
Thanks,
<div>Alex</div>
</div>
</blockquote>
</div>
</div>
</div>
</body>
</html>