Skip to content

Commit

Permalink
Do not throw error when executing empty StableHLO modules (#1864)
Browse files Browse the repository at this point in the history
This PR addresses a bug introduced by PR #1797 where as a result of the
new interpreter API, running empty StableHLO modules would result in an
error `Requested main function not found.` whereas previously, the
`stablehlo-translate` utility would not throw any error.

(Found by @ghpvnist in #1841).
  • Loading branch information
penagos authored Dec 1, 2023
1 parent 57e5a4a commit ad6a900
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions stablehlo/reference/Api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ limitations under the License.
==============================================================================*/
#include "stablehlo/reference/Api.h"

#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
Expand Down Expand Up @@ -106,6 +107,9 @@ class DefaultInterpreterFallback : public InterpreterFallback {
llvm::ErrorOr<SmallVector<InterpreterValue>> evalModule(
ModuleOp module, ArrayRef<InterpreterValue> inputs,
const InterpreterConfiguration &config) {
if (module.getOps<func::FuncOp>().empty())
return SmallVector<InterpreterValue>();

auto mainFunc = getMainFunction(module, config.mainFunction);
if (!mainFunc) llvm::report_fatal_error("Requested main function not found.");

Expand Down
4 changes: 4 additions & 0 deletions stablehlo/tests/interpret_probe.mlir
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// RUN: stablehlo-translate --interpret --probe-output-dir=%T -split-input-file %s

// Test an empty module

// -----

func.func @probe_i1() {
%0 = stablehlo.constant dense<[[0], [0], [0]]> : tensor<3x1xi1>
%1 = stablehlo.constant dense<[[1], [1], [1]]> : tensor<3x1xi1>
Expand Down

0 comments on commit ad6a900

Please sign in to comment.