Files
clang-p2996/mlir/lib/Dialect/DLTI/Traits.cpp
Niranjan Hasabnis abd95342f0 Reimplementing target description concept using DLTI attribute (#92138)
and Interfaces. This is a newer implementation of PR
https://github.com/llvm/llvm-project/pull/85141 and
[RFC](https://discourse.llvm.org/t/rfc-target-description-and-cost-model-in-mlir/76990)
by considering reviews and comments on the original PR.

As an example of attributes supported by this commit:

```
module attributes {
   dlti.target_system_spec =
     #dlti.target_device_spec<
       #dlti.dl_entry<"dlti.device_id", 0: ui32>,
       #dlti.dl_entry<"dlti.device_type", "CPU">,
       #dlti.dl_entry<"dlti.L1_cache_size_in_bytes", 8192 : ui32>>,
     #dlti.target_device_spec <
       #dlti.dl_entry<"dlti.device_id", 1: ui32>,
       #dlti.dl_entry<"dlti.device_type", "GPU">,
       #dlti.dl_entry<"dlti.max_vector_op_width", 64 : ui32>>,
    #dlti.target_device_spec <
       #dlti.dl_entry<"dlti.device_id", 2: ui32>,
       #dlti.dl_entry<"dlti.device_type", "XPU">>>
}
```
2024-06-19 19:40:08 +01:00

35 lines
1.3 KiB
C++

//===- Traits.cpp - Traits for MLIR DLTI dialect --------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/DLTI/Traits.h"
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Interfaces/DataLayoutInterfaces.h"
using namespace mlir;
LogicalResult mlir::impl::verifyHasDefaultDLTIDataLayoutTrait(Operation *op) {
// TODO: consider having trait inheritance so that HasDefaultDLTIDataLayout
// trait can inherit DataLayoutOpInterface::Trait and enforce the validity of
// the assertion below.
assert(
isa<DataLayoutOpInterface>(op) &&
"HasDefaultDLTIDataLayout trait unexpectedly attached to an op that does "
"not implement DataLayoutOpInterface");
return success();
}
DataLayoutSpecInterface mlir::impl::getDataLayoutSpec(Operation *op) {
return op->getAttrOfType<DataLayoutSpecAttr>(
DLTIDialect::kDataLayoutAttrName);
}
TargetSystemSpecInterface mlir::impl::getTargetSystemSpec(Operation *op) {
return op->getAttrOfType<TargetSystemSpecAttr>(
DLTIDialect::kTargetSystemDescAttrName);
}