目录

TensorPlacementUtils

Function Description

Provides a group of functions to determine the position of TensorPlacement.

Function Prototype

class TensorPlacementUtils {
 public:
  // Check whether a tensor is located in the memory (including the HBM and P2P memory) on the device.
  static bool IsOnDevice(TensorPlacement placement) {
    return (placement == kOnDeviceHbm) || (placement == kOnDeviceP2p);
  }
  // Check whether a tensor is located on the host.
  static bool IsOnHost(TensorPlacement placement) {
    return (placement == kOnHost) || (placement == kFollowing);
  }
  // Check whether a tensor is located on the host and whether the data follows the structure.
  static bool IsOnHostFollowing(TensorPlacement placement) {
    return (placement == kFollowing);
  }
  // Check whether a tensor is located on the host and whether the data does not follow the structure.
  static bool IsOnHostNotFollowing(TensorPlacement placement) {
    return (placement == kOnHost);
  }
  // Check whether a tensor is located in the HBM on the device.
  static bool IsOnDeviceHbm(TensorPlacement placement) {
    return (placement == kOnDeviceHbm);
  }
  // Check whether a tensor is located in the P2P memory on the device.
  static bool IsOnDeviceP2p(TensorPlacement placement) {
    return (placement == kOnDeviceP2p);
  }
};

Parameters

Parameter Input/Output Description
placement Input TensorPlacement enumeration to be determined.

Return Value

Restrictions

None

Calling Example

TensorData tensor_data;
tensor_data.SetPlacement(TensorPlacement::kOnDeviceHbm);
auto on_device = TensorPlacementUtils::IsOnDevice(tensor_data.GetPlacement()); // on_device is set to true.