@@ -376,74 +376,6 @@ LogicalResult TensorDescType::verify(
376376 return success ();
377377}
378378
379- // If tensor descriptor has a layout attribute it is used in SIMT mode.
380- // In this mode, the distributed vector shape is determined as follows:
381- // Definitions:
382- // lane_data_size = lane_data[0] × lane_data[1]
383- // subgroup_size = lane_layout[0] × lane_layout[1]
384- // distribution_unit_size = subgroup_size × lane_data_size
385- // ---------------------------------------------------------------------
386- // Case 1: Regular loads/stores.
387- // ---------------------------------------------------------------------
388- // The following conditions must be met:
389- // * tensor_desc[0] == lane_layout[0]
390- // Distributed vector is a 1D vector with shape:
391- // [chunk_size]
392- // ---------------------------------------------------------------------
393- // Case 2: Block loads/stores
394- // ---------------------------------------------------------------------
395- // Additional definitions:
396- // tensor_size = tensor_desc[0] * .. * tensor_desc[r-1] * array_length
397- // n_distribution_units = tensor_size / distribution_unit_size
398- // fragment_size = n_distribution_units * lane_data_size
399- // Given above definitions, the following conditions must be met:
400- // * tensor_desc[0] % (lane_layout[0] × lane_data[0]) == 0
401- // * tensor_desc[1] % (lane_layout[1] × lane_data[1]) == 0
402- // Distributed vector is a 1D vector with shape:
403- // [fragment_size]
404- FailureOr<VectorType> TensorDescType::getDistributedVectorType () {
405- auto layout = llvm::dyn_cast_if_present<LayoutAttr>(getLayout ());
406- // It only works for subgroup level layout, which only has lane_layout
407- // and lane_data, and is to distribute a SIMD code into SIMT code.
408- if (!layout || !layout.isSgLayout ())
409- return failure ();
410-
411- SmallVector<int64_t > laneData (layout.getLaneData ().asArrayRef ());
412- SmallVector<int64_t > laneLayout (layout.getLaneLayout ().asArrayRef ());
413- auto tdescShape = getShape ();
414-
415- // compute sgSize by multiply elements of laneLayout
416- // e.g. for 2D layout, sgSize = laneLayout[0] * laneLayout[1]
417- // e.g. for 1D layout, sgSize = laneLayout[0]
418- auto sgSize = std::accumulate (laneLayout.begin (), laneLayout.end (), 1 ,
419- std::multiplies<int64_t >());
420-
421- // Case 1: regular loads/stores
422- auto scatterAttr = getEncodingAsScatterTensorDescAttr ();
423- if (scatterAttr) {
424- auto chunkSize = scatterAttr.getChunkSize ().getInt ();
425- // Verify if the first dimension of the tensor descriptor shape is
426- // distributable.
427- assert (tdescShape[0 ] == laneLayout[0 ] &&
428- " tensor descriptor shape is not distributable" );
429- return VectorType::get ({chunkSize}, getElementType ());
430- }
431-
432- // Case 2: block loads/stores
433- // Check if the tensor descriptor shape is distributable.
434- int64_t tensorSize = 1 ;
435- for (auto [tdescDim, laneDim, laneDataDim] :
436- llvm::zip_equal (tdescShape, laneLayout, laneData)) {
437- assert ((tdescDim % (laneDim * laneDataDim) == 0 ) &&
438- " tensor descriptor shape is not distributable" );
439- tensorSize *= tdescDim;
440- }
441- // tensorSize must be adjusted for array_length.
442- tensorSize *= getArrayLength ();
443-
444- return VectorType::get ({tensorSize / sgSize}, getElementType ());
445- }
446-
447379} // namespace xegpu
448380} // namespace mlir
449381
0 commit comments