|
16 | 16 | #ifndef _IMEX_XECOMMON_H_
|
17 | 17 | #define _IMEX_XECOMMON_H_
|
18 | 18 |
|
| 19 | +#include "imex/Dialect/XeGPU/IR/XeGPU.h" |
| 20 | +#include "imex/Dialect/XeTile/IR/XeTileOps.h" |
19 | 21 | #include <mlir/Dialect/GPU/IR/GPUDialect.h>
|
20 | 22 | #include <mlir/Dialect/SCF/IR/SCF.h>
|
21 | 23 | #include <mlir/IR/BuiltinOps.h>
|
22 | 24 | #include <mlir/IR/Value.h>
|
23 | 25 | #include <mlir/Transforms/DialectConversion.h>
|
24 | 26 | #include <mlir/Transforms/OneToNTypeConversion.h>
|
25 |
| - |
| 27 | +using namespace imex::xegpu; |
26 | 28 | namespace imex {
|
27 | 29 |
|
28 | 30 | // It checks each GPUFuncOp in the module to see
|
@@ -85,7 +87,7 @@ class TileUsageAnalysis {
|
85 | 87 | else if (idx == 2)
|
86 | 88 | Usage[op] |= (uint)UsageType::DPAS_C;
|
87 | 89 | else
|
88 |
| - llvm::dbgs() << "unknown usage: " << idx; |
| 90 | + op->emitOpError() << "unknown usage: " << idx; |
89 | 91 | }
|
90 | 92 |
|
91 | 93 | if (auto unpack =
|
@@ -269,6 +271,108 @@ class PropagateAnalysis {
|
269 | 271 | }
|
270 | 272 | };
|
271 | 273 |
|
| 274 | +std::pair<std::string, mlir::VectorType> |
| 275 | +encodeVectorType(mlir::ConversionPatternRewriter &rewriter, |
| 276 | + mlir::VectorType type, bool use64bitData = false, |
| 277 | + bool enforceInteger = false); |
| 278 | + |
| 279 | +unsigned encodeDataum(mlir::Type type); |
| 280 | + |
| 281 | +unsigned encodeOpcode(AtomicRMWKind kind); |
| 282 | + |
| 283 | +// L1 and L3 Cache Policies for Load Operation |
| 284 | +// L1 Cache Policies: Uncached (UC), Cached (C), Cache Streaming (S), |
| 285 | +// Invalidate-After-Read (IAR) L3 Cache Policies: Uncached (UC), Cached (C) |
| 286 | +#define L1UC_L3UC 1 |
| 287 | +#define L1UC_L3C 2 |
| 288 | +#define L1C_L3UC 3 |
| 289 | +#define L1C_L3C 4 |
| 290 | +#define L1S_L3UC 5 |
| 291 | +#define L1S_L3C 6 |
| 292 | +#define L1IAR_L3C 7 |
| 293 | + |
| 294 | +// L1 and L3 Cache Policies for Store operation |
| 295 | +// L1 Cache Policies: Uncached (UC), Write-Through (WT), Write-Back (WB), |
| 296 | +// Streaming (S) L3 Cache Policies: Uncached (UC), Cached (WB) |
| 297 | +#define L1UC_L3WB 2 |
| 298 | +#define L1WT_L3UC 3 |
| 299 | +#define L1WT_L3WB 4 |
| 300 | +#define L1S_L3UC 5 |
| 301 | +#define L1S_L3WB 6 |
| 302 | +#define L1WB_L3WB 7 |
| 303 | + |
| 304 | +template <typename OpType> unsigned encodeCacheHint(OpType op) { |
| 305 | + auto l1hint = op.getL1Hint(); |
| 306 | + auto l3hint = op.getL3Hint(); |
| 307 | + |
| 308 | + constexpr bool isStore = std::is_same_v<OpType, StoreNDOp> || |
| 309 | + std::is_same_v<OpType, StoreScatterOp>; |
| 310 | + unsigned cacheHint = L1UC_L3UC; |
| 311 | + |
| 312 | +#define SET_CACHEVALUE(hint, cacheHintVal) \ |
| 313 | + hint.has_value() ? hint.value() : cacheHintVal |
| 314 | + |
| 315 | + if constexpr (!isStore) { |
| 316 | + |
| 317 | + auto l1CacheValue = SET_CACHEVALUE(l1hint, CacheReadHint::UNCACHED); |
| 318 | + auto l3CacheValue = SET_CACHEVALUE(l3hint, CacheReadHint::UNCACHED); |
| 319 | + |
| 320 | +// Setting Cache policy override based on L3 Uncached/Cached value for Load |
| 321 | +// operation |
| 322 | +#define SET_L1L3_CACHEREADHINT(cacheHint, l3CacheValue, uncachedVal, \ |
| 323 | + cachedVal) \ |
| 324 | + if (l3CacheValue == CacheReadHint::UNCACHED) \ |
| 325 | + cacheHint = uncachedVal; \ |
| 326 | + else if (l3CacheValue == CacheReadHint::CACHED) \ |
| 327 | + cacheHint = cachedVal; |
| 328 | + |
| 329 | + switch (l1CacheValue) { |
| 330 | + case CacheReadHint::UNCACHED: |
| 331 | + SET_L1L3_CACHEREADHINT(cacheHint, l3CacheValue, L1UC_L3UC, L1UC_L3C); |
| 332 | + break; |
| 333 | + case CacheReadHint::CACHED: |
| 334 | + SET_L1L3_CACHEREADHINT(cacheHint, l3CacheValue, L1C_L3UC, L1C_L3C); |
| 335 | + break; |
| 336 | + case CacheReadHint::STREAMING: |
| 337 | + SET_L1L3_CACHEREADHINT(cacheHint, l3CacheValue, L1S_L3UC, L1S_L3C); |
| 338 | + break; |
| 339 | + case CacheReadHint::READ_INVALIDATE: |
| 340 | + if (l3CacheValue == CacheReadHint::CACHED) |
| 341 | + cacheHint = L1IAR_L3C; |
| 342 | + break; |
| 343 | + } |
| 344 | + |
| 345 | + } else { |
| 346 | + auto l1CacheValue = SET_CACHEVALUE(l1hint, CacheWriteHint::UNCACHED); |
| 347 | + auto l3CacheValue = SET_CACHEVALUE(l3hint, CacheWriteHint::UNCACHED); |
| 348 | + |
| 349 | +// Setting Cache policy override based on L3 Uncached/Write-Back value for Store |
| 350 | +// operation |
| 351 | +#define SET_L1L3_CACHEWRITEHINT(cacheHint, l3CacheValue, uncachedVal, \ |
| 352 | + cachedVal) \ |
| 353 | + if (l3CacheValue == CacheWriteHint::UNCACHED) \ |
| 354 | + cacheHint = uncachedVal; \ |
| 355 | + else if (l3CacheValue == CacheWriteHint::WRITE_BACK) \ |
| 356 | + cacheHint = cachedVal; |
| 357 | + |
| 358 | + switch (l1CacheValue) { |
| 359 | + case CacheWriteHint::UNCACHED: |
| 360 | + SET_L1L3_CACHEWRITEHINT(cacheHint, l3CacheValue, L1UC_L3UC, L1UC_L3WB); |
| 361 | + break; |
| 362 | + case CacheWriteHint::WRITE_THROUGH: |
| 363 | + SET_L1L3_CACHEWRITEHINT(cacheHint, l3CacheValue, L1WT_L3UC, L1WT_L3WB); |
| 364 | + break; |
| 365 | + case CacheWriteHint::STREAMING: |
| 366 | + SET_L1L3_CACHEWRITEHINT(cacheHint, l3CacheValue, L1S_L3UC, L1S_L3WB); |
| 367 | + break; |
| 368 | + case CacheWriteHint::WRITE_BACK: |
| 369 | + if (l3CacheValue == CacheWriteHint::WRITE_BACK) |
| 370 | + cacheHint = L1WB_L3WB; |
| 371 | + break; |
| 372 | + } |
| 373 | + } |
| 374 | + return cacheHint; |
| 375 | +} |
272 | 376 | class XeTypeConverter : public mlir::OneToNTypeConverter {
|
273 | 377 | public:
|
274 | 378 | // friend class XeConversionPattern;
|
|
0 commit comments