Add instruction count method to HloModule.
authorMark Heffernan <meheff@google.com>
Wed, 17 Jan 2018 17:41:43 +0000 (09:41 -0800)
committerTensorFlower Gardener <gardener@tensorflow.org>
Wed, 17 Jan 2018 17:46:10 +0000 (09:46 -0800)
PiperOrigin-RevId: 182227249

tensorflow/compiler/xla/service/hlo_module.cc
tensorflow/compiler/xla/service/hlo_module.h

index 6103cab3e7e73079ef9e65b4ada181aa088c4541..58bb94221149c9a8b550add900dff52a53565985 100644 (file)
@@ -457,6 +457,14 @@ HloInstruction* HloModule::OutlineExpressionFromComputation(
   return call;
 }
 
+int64 HloModule::instruction_count() const {
+  int64 n = 0;
+  for (const auto& computation : computations_) {
+    n += computation->instruction_count();
+  }
+  return n;
+}
+
 std::list<HloComputation*> HloModule::MakeComputationPostOrder() const {
   // First determine all root computations by building a set of nonroot
   // computations (computations which are called by an instruction in the
index d3bb46bffca15549ef22e2908f129efd8586fa67..e377654d024819d00f73f43a70d363bd902dc981 100644 (file)
@@ -129,6 +129,9 @@ class HloModule {
   // Gets the number of computations in this module.
   int64 computation_count() const { return computations_.size(); }
 
+  // Gets the number of instructions in this module.
+  int64 instruction_count() const;
+
   // Compute and return a post order of all computations in the module. The sort
   // is defined like so: if computation A has an instruction which calls
   // computation B, then A will appear after B in the sort.