tensorflow/stream_executor/rocm/rocm_gpu_executor.cc
// Attempts to read the NUMA node corresponding to the GPU device's PCI bus out
// of SysFS. Returns -1 if it cannot.
//
// For anything more complicated/prod-focused than this, you'll likely want to
// turn to gsys' topology modeling.
Attempts to read the NUMA node corresponding to the GPU device's PCI bus out
of SysFS. Returns -1 if it cannot.

For anything more complicated/prod-focused than this, you'll likely want to
turn to gsys' topology modeling.
Attempts to read the NUMA node corresponding to the GPU device ' s PCI bus out of SysFS . Returns - 1 if it cannot . For anything more complicated / prod - focused than this you ' ll likely want to turn to gsys ' topology modeling .
static int TryToReadNumaNode(const string& pci_bus_id, int device_ordinal) {
  VLOG(2) << "trying to read NUMA node for device ordinal: " << device_ordinal;
  static const int kUnknownNumaNode = -1;
  if (pci_bus_id.empty()) {
    LOG(INFO) << "no PCI bus ID for device ordinal: " << device_ordinal;
    return kUnknownNumaNode;
  }
  std::string filename =
      absl::StrFormat("/sys/bus/pci/devices/%s/numa_node", pci_bus_id);
  FILE* file = fopen(filename.c_str(), "r");
  if (file == nullptr) {
    LOG(INFO) << "could not open file to read NUMA node: " << filename
              << "\nYour kernel may have been built without NUMA support.";
    return kUnknownNumaNode;
  }
  std::string content;
  char buf[32];
  size_t did_read = fread(buf, sizeof(buf[0]), sizeof(buf) - 1, file);
  buf[did_read] = '\0';
  content = buf;
  int32_t value;
  if (port::safe_strto32(content, &value)) {
    if (value < 0) {  
      LOG(INFO) << "successful NUMA node read from SysFS had negative value ("
                << value
                << "), but there must be at least one NUMA node"
                   ", so returning NUMA node zero";
      fclose(file);
      return 0;
    }
    fclose(file);
    return value;
  }
  LOG(WARNING)
      << "could not convert SysFS file contents to integral NUMA node value: "
      << content;
  fclose(file);
  return kUnknownNumaNode;
}
static int TryToReadNumaNode ( const string & pci_bus_id , int device_ordinal ) { VLOG ( 2 ) << " " << device_ordinal ; static const int kUnknownNumaNode = -1 ; if ( pci_bus_id . empty ( ) ) { LOG ( INFO ) << " " << device_ordinal ; return kUnknownNumaNode ; } std :: string filename = absl :: StrFormat ( " " , pci_bus_id ) ; FILE * file = fopen ( filename . c_str ( ) , " " ) ; if ( file == nullptr ) { LOG ( INFO ) << " " << filename << " \n " ; return kUnknownNumaNode ; } std :: string content ; char buf [ 32 ] ; size_t did_read = fread ( buf , sizeof ( buf [ 0 ] ) , sizeof ( buf ) - 1 , file ) ; buf [ did_read ] = ' \0 ' ; content = buf ; int32_t value ; if ( port :: safe_strto32 ( content , & value ) ) { if ( value < 0 ) { LOG ( INFO ) << " " << value << " " " " ; fclose ( file ) ; return 0 ; } fclose ( file ) ; return value ; } LOG ( WARNING ) << " " << content ; fclose ( file ) ; return kUnknownNumaNode ; }
Attempts to read the NUMA node corresponding to the GPU device's PCI bus out
of SysFS.
Attempts to read the NUMA node corresponding to the GPU device ' s PCI bus out of SysFS .
// We have to use fopen/fread here so that the device properties can be // populated before InitGoogle procedure has been completed (at which point we // could use the file::* utilities). // See http://b/18228951 for details on this path.