[mlir][OpenACC] acc.host_data verifier aborts on block-argument data operands
An assertion-enabled MLIR parsing and verification helper built against the revision below aborted when acc.host_data used function block arguments as data operands. The helper registers all dialects, parses a module and verifies it; it does not run an optimization Pass.
Environment
- llvm-project revision:
67005b724c917e1bdca50c82ecaa1b21a69244ed. - Checker:
ggfa-ir-facts-r1; recorded binary SHA-256:ca624d03d1447d59e19672b53a99f8687e9700a933aa3b645b5804da8cda4a6b. - Saved build: GCC 11, C++17, Release, LLVM assertions enabled. The checker compile flags contain
-UNDEBUGafter-DNDEBUG. - Original input SHA-256:
5f0792cc7048d25a46fe0fcea91ce3946666d9407aaed78e38ec7363cf4ad741(210 bytes).
Reproducer
Save the complete input below as input.mlir:
func.func @host_data(%arg0: memref<?xf32>, %arg1: memref<?xf32>) {
%c0 = arith.constant 0 : index
acc.host_data dataOperands(%arg0, %arg1 : memref<?xf32>, memref<?xf32>) {
acc.terminator
}
return
}
Steps to reproduce
The recorded call passed no command-line arguments and supplied the input on stdin. The corresponding shell invocation is:
./ggfa-ir-facts-r1 < input.mlir
The exact checker source and CMake definition used by the saved build are included below. The helper calls parseSourceFile<ModuleOp> and then verify(*module) when parsing returns a module.
Checker source and build definition
The checker source has SHA-256 d9be3d464a1a6b7abb014988d6dd438cb2d3de52a714738289a696d4c6e558e8. The CMake definition has SHA-256 e70a76a737601547f105497b3c9167464afe35355f11da65f4efb4a2ed321858. Both are the bytes from the source directory named by the saved build cache and dependency file. The recorded checker binary matches the original call receipt.
// Read-only, verifier-backed IR facts. No pass execution or source generation.
#include "mlir/IR/AsmState.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Verifier.h"
#include "mlir/InitAllDialects.h"
#include "mlir/Parser/Parser.h"
#include "mlir/Dialect/Linalg/IR/Linalg.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Interfaces/LoopLikeInterface.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/JSON.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
using namespace mlir;
namespace json = llvm::json;
static std::string printType(Type type) {
std::string s;
llvm::raw_string_ostream stream(s);
type.print(stream);
return s;
}
static json::Object typeFacts(Type type) {
json::Object result{{"text", printType(type)}, {"kind", "other"}};
if (auto integer = dyn_cast<IntegerType>(type)) {
result["kind"] = "integer";
result["width"] = int64_t(integer.getWidth());
} else if (isa<IndexType>(type)) {
result["kind"] = "index";
}
if (auto shaped = dyn_cast<ShapedType>(type)) {
result["kind"] = isa<BaseMemRefType>(type) ? "memref" :
isa<TensorType>(type) ? "tensor" : "shaped";
result["element_type"] = printType(shaped.getElementType());
result["ranked"] = shaped.hasRank();
json::Array shape;
if (shaped.hasRank())
for (int64_t dim : shaped.getShape())
shape.push_back(ShapedType::isDynamic(dim) ? json::Value(nullptr) : json::Value(dim));
result["shape"] = std::move(shape);
if (auto memref = dyn_cast<MemRefType>(type)) {
std::string layout;
llvm::raw_string_ostream stream(layout);
memref.getLayout().print(stream);
result["layout"] = layout;
SmallVector<int64_t> strides;
int64_t offset;
if (succeeded(memref.getStridesAndOffset(strides, offset))) {
result["offset"] = ShapedType::isDynamic(offset) ? json::Value(nullptr) : json::Value(offset);
json::Array values;
for (int64_t stride : strides)
values.push_back(ShapedType::isDynamic(stride) ? json::Value(nullptr) : json::Value(stride));
result["strides"] = std::move(values);
}
}
}
return result;
}
int main(int argc, char **argv) {
if (argc != 1) {
llvm::errs() << "usage: ggfa-ir-facts-r1 < input.mlir\n";
return 2;
}
auto input = llvm::MemoryBuffer::getSTDIN();
if (!input || (*input)->getBufferSize() > 262144) {
llvm::errs() << "input missing or exceeds admitted 262144 bytes\n";
return 2;
}
DialectRegistry registry;
registerAllDialects(registry);
MLIRContext context(registry);
context.disableMultithreading();
llvm::SourceMgr mgr;
mgr.AddNewSourceBuffer(std::move(*input), llvm::SMLoc());
auto module = parseSourceFile<ModuleOp>(mgr, &context);
if (!module || failed(verify(*module))) {
llvm::outs() << "{\"schema\":\"ggfa.ir_facts.r1\",\"verified\":false}\n";
return 1;
}
llvm::DenseMap<Operation *, int64_t> opIds;
llvm::DenseMap<Value, int64_t> valueIds;
llvm::DenseMap<Region *, int64_t> regionIds;
int64_t oi = 0, vi = 0, ri = 0;
module->walk<WalkOrder::PreOrder>([&](Operation *op) {
opIds[op] = oi++;
for (Value value : op->getResults()) valueIds[value] = vi++;
for (Region ®ion : op->getRegions()) {
regionIds[®ion] = ri++;
for (Block &block : region)
for (Value value : block.getArguments()) valueIds[value] = vi++;
}
});
if (oi > 4096) {
llvm::errs() << "operation bound exceeded\n";
return 2;
}
auto valueFact = [&](Value value) {
return json::Object{{"id", valueIds.lookup(value)}, {"type", typeFacts(value.getType())}};
};
json::Array operations;
module->walk<WalkOrder::PreOrder>([&](Operation *op) {
json::Object node{{"id", opIds.lookup(op)}, {"name", op->getName().getStringRef().str()},
{"regions", int64_t(op->getNumRegions())},
{"loop_like", isa<LoopLikeOpInterface>(op)}};
node["parent"] = op->getParentOp() ? json::Value(opIds.lookup(op->getParentOp())) : json::Value(nullptr);
node["region"] = op->getParentRegion() ? json::Value(regionIds.lookup(op->getParentRegion())) : json::Value(nullptr);
json::Array operands, results, arguments;
for (Value value : op->getOperands()) operands.push_back(valueFact(value));
for (Value value : op->getResults()) results.push_back(valueFact(value));
for (Region ®ion : op->getRegions())
for (Block &block : region)
for (Value value : block.getArguments()) arguments.push_back(valueFact(value));
node["operands"] = std::move(operands);
node["results"] = std::move(results);
node["block_arguments"] = std::move(arguments);
if (auto linalg = dyn_cast<linalg::LinalgOp>(op))
node["linalg_semantics"] = linalg.hasPureTensorSemantics() ? "tensor" :
linalg.hasPureBufferSemantics() ? "buffer" : "mixed";
if (auto load = dyn_cast<memref::LoadOp>(op))
node["access_memref"] = valueIds.lookup(load.getMemRef());
if (auto store = dyn_cast<memref::StoreOp>(op))
node["access_memref"] = valueIds.lookup(store.getMemRef());
operations.push_back(std::move(node));
});
std::string canonical;
llvm::raw_string_ostream stream(canonical);
module->print(stream, OpPrintingFlags().enableDebugInfo(false));
json::Object result{{"schema", "ggfa.ir_facts.r1"}, {"verified", true},
{"operations", std::move(operations)}, {"canonical_ir", canonical}};
llvm::outs() << json::Value(std::move(result)) << "\n";
return 0;
}
cmake_minimum_required(VERSION 3.20)
project(mlirvkf_native LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(MLIR REQUIRED CONFIG)
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}" "${LLVM_CMAKE_DIR}")
include(AddLLVM)
include(AddMLIR)
include(HandleLLVMOptions)
include_directories(${LLVM_INCLUDE_DIRS} ${MLIR_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
add_llvm_executable(ggfa-ir-facts-r1 ir_facts_r1.cpp)
llvm_update_compile_flags(ggfa-ir-facts-r1)
get_property(MLIRVKF_DIALECT_LIBS GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(MLIRVKF_EXTENSION_LIBS GLOBAL PROPERTY MLIR_EXTENSION_LIBS)
# Newer MLIR releases moved registerAllDialects out of the header.
if(TARGET MLIRRegisterAllDialects)
list(APPEND MLIRVKF_REGISTRATION_LIBS MLIRRegisterAllDialects)
endif()
target_link_libraries(ggfa-ir-facts-r1 PRIVATE
${MLIRVKF_REGISTRATION_LIBS} ${MLIRVKF_DIALECT_LIBS} ${MLIRVKF_EXTENSION_LIBS} MLIRIR MLIRParser
MLIRLinalgDialect MLIRMemRefDialect MLIRLoopLikeInterface LLVMSupport)
mlir_check_all_link_libraries(ggfa-ir-facts-r1)
install(TARGETS ggfa-ir-facts-r1 RUNTIME DESTINATION bin)
The saved build used CMake 3.28 with the Unix Makefiles generator. MLIR_DIR and LLVM_DIR identify the matching LLVM/MLIR CMake package directories; the LLVM build enabled MLIR and the X86, NVPTX and AMDGPU targets.
Actual behavior
The checker terminated with SIGABRT (signal 6; subprocess return code -6) and was reaped. Stdout was empty. The saved stderr contained this assertion, with the private source-directory prefix removed:
Casting.h:656: decltype(auto) llvm::dyn_cast(From*)
[with To = mlir::acc::UseDeviceOp; From = mlir::Operation]:
Assertion `detail::isPresent(Val) && "dyn_cast on a non-existent value"` failed.
Expected behavior
Verification should reject these invalid acc.host_data data operands with a diagnostic instead of aborting when an operand has no defining operation.
Analysis
In the fixed revision's HostDataOp::verify, the verifier calls dyn_cast<acc::UseDeviceOp>(operand.getDefiningOp()) before checking whether the cast succeeded. The input's data operands are function block arguments, whose getDefiningOp() is null. This source path is consistent with the recorded assertion. The saved diagnostic does not include a symbolized frame identifying the invocation of the verifier.
The same call is present in the inspected main source snapshot.
Related issues
#205284 reports a similar LLVM casting assertion, but its stack identifies CopyinOp in the acc-implicit-data path. This observation concerns UseDeviceOp in the HostDataOp verifier. The common assertion alone does not establish a duplicate.
@llvm/issue-subscribers-mlir
Author: lin334141-cell
Environment
- llvm-project revision:
67005b724c917e1bdca50c82ecaa1b21a69244ed. - Checker:
ggfa-ir-facts-r1; recorded binary SHA-256:ca624d03d1447d59e19672b53a99f8687e9700a933aa3b645b5804da8cda4a6b. - Saved build: GCC 11, C++17, Release, LLVM assertions enabled. The checker compile flags contain
-UNDEBUGafter-DNDEBUG. - Original input SHA-256:
5f0792cc7048d25a46fe0fcea91ce3946666d9407aaed78e38ec7363cf4ad741(210 bytes).
Reproducer
Save the complete input below as input.mlir:
func.func @<!-- -->host_data(%arg0: memref<?xf32>, %arg1: memref<?xf32>) {
%c0 = arith.constant 0 : index
acc.host_data dataOperands(%arg0, %arg1 : memref<?xf32>, memref<?xf32>) {
acc.terminator
}
return
}
Steps to reproduce
The recorded call passed no command-line arguments and supplied the input on stdin. The corresponding shell invocation is:
./ggfa-ir-facts-r1 < input.mlir
The exact checker source and CMake definition used by the saved build are included below. The helper calls parseSourceFile<ModuleOp> and then verify(*module) when parsing returns a module.
<details> <summary>Checker source and build definition</summary>
The checker source has SHA-256 d9be3d464a1a6b7abb014988d6dd438cb2d3de52a714738289a696d4c6e558e8. The CMake definition has SHA-256 e70a76a737601547f105497b3c9167464afe35355f11da65f4efb4a2ed321858. Both are the bytes from the source directory named by the saved build cache and dependency file. The recorded checker binary matches the original call receipt.
// Read-only, verifier-backed IR facts. No pass execution or source generation.
#include "mlir/IR/AsmState.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Verifier.h"
#include "mlir/InitAllDialects.h"
#include "mlir/Parser/Parser.h"
#include "mlir/Dialect/Linalg/IR/Linalg.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Interfaces/LoopLikeInterface.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/JSON.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
using namespace mlir;
namespace json = llvm::json;
static std::string printType(Type type) {
std::string s;
llvm::raw_string_ostream stream(s);
type.print(stream);
return s;
}
static json::Object typeFacts(Type type) {
json::Object result{{"text", printType(type)}, {"kind", "other"}};
if (auto integer = dyn_cast<IntegerType>(type)) {
result["kind"] = "integer";
result["width"] = int64_t(integer.getWidth());
} else if (isa<IndexType>(type)) {
result["kind"] = "index";
}
if (auto shaped = dyn_cast<ShapedType>(type)) {
result["kind"] = isa<BaseMemRefType>(type) ? "memref" :
isa<TensorType>(type) ? "tensor" : "shaped";
result["element_type"] = printType(shaped.getElementType());
result["ranked"] = shaped.hasRank();
json::Array shape;
if (shaped.hasRank())
for (int64_t dim : shaped.getShape())
shape.push_back(ShapedType::isDynamic(dim) ? json::Value(nullptr) : json::Value(dim));
result["shape"] = std::move(shape);
if (auto memref = dyn_cast<MemRefType>(type)) {
std::string layout;
llvm::raw_string_ostream stream(layout);
memref.getLayout().print(stream);
result["layout"] = layout;
SmallVector<int64_t> strides;
int64_t offset;
if (succeeded(memref.getStridesAndOffset(strides, offset))) {
result["offset"] = ShapedType::isDynamic(offset) ? json::Value(nullptr) : json::Value(offset);
json::Array values;
for (int64_t stride : strides)
values.push_back(ShapedType::isDynamic(stride) ? json::Value(nullptr) : json::Value(stride));
result["strides"] = std::move(values);
}
}
}
return result;
}
int main(int argc, char **argv) {
if (argc != 1) {
llvm::errs() << "usage: ggfa-ir-facts-r1 < input.mlir\n";
return 2;
}
auto input = llvm::MemoryBuffer::getSTDIN();
if (!input || (*input)->getBufferSize() > 262144) {
llvm::errs() << "input missing or exceeds admitted 262144 bytes\n";
return 2;
}
DialectRegistry registry;
registerAllDialects(registry);
MLIRContext context(registry);
context.disableMultithreading();
llvm::SourceMgr mgr;
mgr.AddNewSourceBuffer(std::move(*input), llvm::SMLoc());
auto module = parseSourceFile<ModuleOp>(mgr, &context);
if (!module || failed(verify(*module))) {
llvm::outs() << "{\"schema\":\"ggfa.ir_facts.r1\",\"verified\":false}\n";
return 1;
}
llvm::DenseMap<Operation *, int64_t> opIds;
llvm::DenseMap<Value, int64_t> valueIds;
llvm::DenseMap<Region *, int64_t> regionIds;
int64_t oi = 0, vi = 0, ri = 0;
module->walk<WalkOrder::PreOrder>([&](Operation *op) {
opIds[op] = oi++;
for (Value value : op->getResults()) valueIds[value] = vi++;
for (Region &region : op->getRegions()) {
regionIds[&region] = ri++;
for (Block &block : region)
for (Value value : block.getArguments()) valueIds[value] = vi++;
}
});
if (oi > 4096) {
llvm::errs() << "operation bound exceeded\n";
return 2;
}
auto valueFact = [&](Value value) {
return json::Object{{"id", valueIds.lookup(value)}, {"type", typeFacts(value.getType())}};
};
json::Array operations;
module->walk<WalkOrder::PreOrder>([&](Operation *op) {
json::Object node{{"id", opIds.lookup(op)}, {"name", op->getName().getStringRef().str()},
{"regions", int64_t(op->getNumRegions())},
{"loop_like", isa<LoopLikeOpInterface>(op)}};
node["parent"] = op->getParentOp() ? json::Value(opIds.lookup(op->getParentOp())) : json::Value(nullptr);
node["region"] = op->getParentRegion() ? json::Value(regionIds.lookup(op->getParentRegion())) : json::Value(nullptr);
json::Array operands, results, arguments;
for (Value value : op->getOperands()) operands.push_back(valueFact(value));
for (Value value : op->getResults()) results.push_back(valueFact(value));
for (Region &region : op->getRegions())
for (Block &block : region)
for (Value value : block.getArguments()) arguments.push_back(valueFact(value));
node["operands"] = std::move(operands);
node["results"] = std::move(results);
node["block_arguments"] = std::move(arguments);
if (auto linalg = dyn_cast<linalg::LinalgOp>(op))
node["linalg_semantics"] = linalg.hasPureTensorSemantics() ? "tensor" :
linalg.hasPureBufferSemantics() ? "buffer" : "mixed";
if (auto load = dyn_cast<memref::LoadOp>(op))
node["access_memref"] = valueIds.lookup(load.getMemRef());
if (auto store = dyn_cast<memref::StoreOp>(op))
node["access_memref"] = valueIds.lookup(store.getMemRef());
operations.push_back(std::move(node));
});
std::string canonical;
llvm::raw_string_ostream stream(canonical);
module->print(stream, OpPrintingFlags().enableDebugInfo(false));
json::Object result{{"schema", "ggfa.ir_facts.r1"}, {"verified", true},
{"operations", std::move(operations)}, {"canonical_ir", canonical}};
llvm::outs() << json::Value(std::move(result)) << "\n";
return 0;
}
cmake_minimum_required(VERSION 3.20)
project(mlirvkf_native LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(MLIR REQUIRED CONFIG)
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}" "${LLVM_CMAKE_DIR}")
include(AddLLVM)
include(AddMLIR)
include(HandleLLVMOptions)
include_directories(${LLVM_INCLUDE_DIRS} ${MLIR_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
add_llvm_executable(ggfa-ir-facts-r1 ir_facts_r1.cpp)
llvm_update_compile_flags(ggfa-ir-facts-r1)
get_property(MLIRVKF_DIALECT_LIBS GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(MLIRVKF_EXTENSION_LIBS GLOBAL PROPERTY MLIR_EXTENSION_LIBS)
# Newer MLIR releases moved registerAllDialects out of the header.
if(TARGET MLIRRegisterAllDialects)
list(APPEND MLIRVKF_REGISTRATION_LIBS MLIRRegisterAllDialects)
endif()
target_link_libraries(ggfa-ir-facts-r1 PRIVATE
${MLIRVKF_REGISTRATION_LIBS} ${MLIRVKF_DIALECT_LIBS} ${MLIRVKF_EXTENSION_LIBS} MLIRIR MLIRParser
MLIRLinalgDialect MLIRMemRefDialect MLIRLoopLikeInterface LLVMSupport)
mlir_check_all_link_libraries(ggfa-ir-facts-r1)
install(TARGETS ggfa-ir-facts-r1 RUNTIME DESTINATION bin)
The saved build used CMake 3.28 with the Unix Makefiles generator. MLIR_DIR and LLVM_DIR identify the matching LLVM/MLIR CMake package directories; the LLVM build enabled MLIR and the X86, NVPTX and AMDGPU targets.
</details>
Actual behavior
The checker terminated with SIGABRT (signal 6; subprocess return code -6) and was reaped. Stdout was empty. The saved stderr contained this assertion, with the private source-directory prefix removed:
Casting.h:656: decltype(auto) llvm::dyn_cast(From*)
[with To = mlir::acc::UseDeviceOp; From = mlir::Operation]:
Assertion `detail::isPresent(Val) && "dyn_cast on a non-existent value"` failed.
Expected behavior
Verification should reject these invalid acc.host_data data operands with a diagnostic instead of aborting when an operand has no defining operation.
Analysis
In the fixed revision's HostDataOp::verify, the verifier calls dyn_cast<acc::UseDeviceOp>(operand.getDefiningOp()) before checking whether the cast succeeded. The input's data operands are function block arguments, whose getDefiningOp() is null. This source path is consistent with the recorded assertion. The saved diagnostic does not include a symbolized frame identifying the invocation of the verifier.
The same call is present in the inspected main source snapshot.
Related issues
#205284 reports a similar LLVM casting assertion, but its stack identifies CopyinOp in the acc-implicit-data path. This observation concerns UseDeviceOp in the HostDataOp verifier. The common assertion alone does not establish a duplicate.
hi, can i take a look at this?
Which input produced the problematic IR?