Building Tensorflow from source with Local LLVM Repo

47 views
Skip to first unread message

Abdul Rafae Noor

unread,
Feb 23, 2022, 6:37:49 PM2/23/22
to XLA development
Hi,
I am trying to build TensorFlow from source because I wanted to extend the XLA to LLVM path through our internal LLVM repository which extends LLVM.  After looking into the https://groups.google.com/a/tensorflow.org/g/mlir/c/EVWnlwPKLT4 email list and have found that --override_repository=llvm-project=<PATH TO LLVM Source> enables users to override the LLVM paths. However when doing so, the compilation does not work particularly as some MLIR related compilation issue is happening. After looking into it, it looks like certain Bazel files might be missing in the LLVM monorepo which TensorFlow is expecting to be there. 

According to this file https://github.com/tensorflow/tensorflow/blob/master/tensorflow/compiler/mlir/README.md , to use a seperate LLVM monorepo you would need to copy over certain BUILD files. However, there are no third_party/mlir/ directory currently and so I'm not sure what BUILD files need copying. 

The local LLVM repo is branched off from LLVM version 12. Any help/pointers would be appreciated  :)

Regards,
Rafae

George Karpenkov

unread,
Feb 23, 2022, 6:46:45 PM2/23/22
to Abdul Rafae Noor, XLA development
I don't have an answer to your question, but it seems exceedingly unlikely to work with a local fork given how tightly coupled MLIR headers are to TF usage.

--
You received this message because you are subscribed to the Google Groups "XLA development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xla-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xla-dev/031367c9-5d13-47f0-a3ef-edd74bbcdf6fn%40googlegroups.com.

Noor, Abdul Rafae

unread,
Feb 23, 2022, 6:54:36 PM2/23/22
to George Karpenkov, XLA development
Hey George,
It doesn’t have to be the latest Tensorflow/XLA commit. If there is a possibility with some prior stable release which originally worked on LLVM version 12. We haven’t modified any of the MLIR files and so hopefully MLIR compatibility would be there

– Rafae


From: 'George Karpenkov' via XLA development <xla...@googlegroups.com>
Sent: Wednesday, February 23, 2022 5:46:32 PM
To: Noor, Abdul Rafae <arn...@illinois.edu>
Cc: XLA development <xla...@googlegroups.com>
Subject: Re: [xla-dev] Building Tensorflow from source with Local LLVM Repo
 

Jacques Pienaar

unread,
Feb 23, 2022, 6:57:31 PM2/23/22
to Abdul Rafae Noor, XLA development
Hey Rafae,

Those instructions are no longer up to date post upstreaming of bazel build files to LLVM, you now would want to use the build files from llvm repo itself (under utils/bazel/). Although if you have an LLVM that old those files may not be in there, there isn't even a guarantee that you'd be able to build llvm 12 version unless you use a version checked out when that version was being used (you can look at workspace history and correlate with a commit close to where you branched off), and then you may have the situation documented and could follow the instructions.

-- Jacques

--

Stephan Herhut

unread,
Mar 9, 2022, 4:57:54 AM3/9/22
to Noor, Abdul Rafae, George Karpenkov, XLA development
That information is outdated and the mlir directory was removed in https://cs.opensource.google/tensorflow/tensorflow/+/982608d75d1493b4e351ef84d58bc0fdf78203c8. TensorFlow now uses OSS BUILD files that come as part of LLVM.

If your checkout of LLVM is too old for this, you might need to restore the setup before the above change or even build TensorFlow before that change. MLIR is still evolving rapidly and building against an older version is likely not going to work. You could try to merge a new version of MLIR (essentially the llvm/mlir directory) into your version of LLVM.

Cheers
  Stephan



--

Stephan Herhut

Software Engineer

her...@google.com


Google Germany GmbH

Erika-Mann-Straße 33

80636 München


Geschäftsführer: Paul Manicle, Liana Sebastian

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg


Diese E-Mail ist vertraulich. Falls Sie diese fälschlicherweise erhalten haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen, dass die E-Mail an die falsche Person gesendet wurde. 

     

This e-mail is confidential. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person.


Mehdi AMINI

unread,
Mar 19, 2022, 7:17:24 PM3/19/22
to Stephan Herhut, Noor, Abdul Rafae, George Karpenkov, XLA development
I think the issue is that the Bazel files are now in the LLVM repository, but needs some sort of initial setup that does not happen when using --override_repository ; this is defined here: https://github.com/tensorflow/tensorflow/blob/master/third_party/llvm/setup.bzl#L3-L26




Abdul Rafae Noor

unread,
Mar 22, 2022, 1:09:27 PM3/22/22
to XLA development
Thank you all for your suggestions. I was able to get my llvm repository compiled with Tensorflow/XLA. As mentioned above, since the XLA is so tied with MLIR and LLVM and the file structure changes across commits to the LLVM project not all TensorFlow versions can easily be interchanged with a LLVM version (certain TensorFlow passes expect imports to be in specific directories). I went through identifying which stable release of Tensorflow is closest to the stable version of LLVM we're using (LLVM-13.0.0) and appropriately modified our code base to be compatible with the specific commit XLA is expecting. Then I copied over the specific Bazel files in the appropriate places to ensure override_repository works.
Reply all
Reply to author
Forward
0 new messages