[PATCH] D99992: [mlgo] Skip AOT-compiling a model if a header/object pair is provided

Mircea Trofin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 6 14:09:30 PDT 2021


mtrofin created this revision.
mtrofin added a reviewer: phosek.
Herald added subscribers: kristof.beyls, mgorny.
mtrofin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This allows one to cross-compile the header/object for a model in a
setup where the compiler is built on a system that cannot host the AOT
compiler. For example, if arm-hostable clang is desired, while the AOT
Tensorflow compiler can cross-compile to arm, it can't currently run on
arm.

The only alternative in that scenario would be to cross-compile clang
itself, but that gets complicated when trying to run tests after that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99992

Files:
  llvm/cmake/modules/TensorFlowCompile.cmake


Index: llvm/cmake/modules/TensorFlowCompile.cmake
===================================================================
--- llvm/cmake/modules/TensorFlowCompile.cmake
+++ llvm/cmake/modules/TensorFlowCompile.cmake
@@ -16,20 +16,32 @@
 # ${CMAKE_CURRENT_BINARY_DIR}. The generated header will define a C++ class
 # called ${cpp_class} - which may be a namespace-qualified class name.
 function(tfcompile model tag_set signature_def_key fname cpp_class)
-  tfgetmodel(${model} LLVM_ML_MODELS_ABSOLUTE)
-  message("Using model at " ${LLVM_ML_MODELS_ABSOLUTE})
   set(prefix ${CMAKE_CURRENT_BINARY_DIR}/${fname})
   set(obj_file ${prefix}.o)
   set(hdr_file ${prefix}.h)
-  add_custom_command(OUTPUT ${obj_file} ${hdr_file}
-    COMMAND "XLA_FLAGS=\"--xla_cpu_multi_thread_eigen=false\"" ${TENSORFLOW_AOT_COMPILER} aot_compile_cpu
-          --dir ${LLVM_ML_MODELS_ABSOLUTE}
-          --tag_set ${tag_set}
-          --signature_def_key ${signature_def_key}
-          --output_prefix ${prefix}
-          --cpp_class ${cpp_class}
-          --target_triple ${LLVM_HOST_TRIPLE}
-  )
+  string(TOUPPER ${fname} fname_allcaps)
+  set(OVERRIDE_HEADER ${LLVM_OVERRIDE_MODEL_HEADER_${fname_allcaps}})
+  set(OVERRIDE_OBJECT ${LLVM_OVERRIDE_MODEL_OBJECT_${fname_allcaps}})
+  if (EXISTS "${OVERRIDE_HEADER}" AND EXISTS "${OVERRIDE_OBJECT}")
+    configure_file(${OVERRIDE_HEADER} ${hdr_file} COPYONLY)  
+    configure_file(${OVERRIDE_OBJECT} ${obj_file} COPYONLY)
+    message("Using provided header "   
+      ${hdr_file} " and object "   ${obj_file} 
+      " files for model " ${model})
+  else()
+    
+    tfgetmodel(${model} LLVM_ML_MODELS_ABSOLUTE)
+    message("Using model at " ${LLVM_ML_MODELS_ABSOLUTE})
+    add_custom_command(OUTPUT ${obj_file} ${hdr_file}
+      COMMAND "XLA_FLAGS=\"--xla_cpu_multi_thread_eigen=false\"" ${TENSORFLOW_AOT_COMPILER} aot_compile_cpu
+            --dir ${LLVM_ML_MODELS_ABSOLUTE}
+            --tag_set ${tag_set}
+            --signature_def_key ${signature_def_key}
+            --output_prefix ${prefix}
+            --cpp_class ${cpp_class}
+            --target_triple ${LLVM_HOST_TRIPLE}
+    )
+  endif()
 
   # Aggregate the objects so that results of different tfcompile calls may be
   # grouped into one target.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99992.335658.patch
Type: text/x-patch
Size: 2259 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210406/93325225/attachment.bin>


More information about the llvm-commits mailing list