tensorflow/stream_executor/rocm/rocm_diagnostics.cc
// Iterates through loaded DSOs with DlIteratePhdrCallback to find the
// driver-interfacing DSO version number. Returns it as a string.
Iterates through loaded DSOs with DlIteratePhdrCallback to find the
driver-interfacing DSO version number. Returns it as a string.
Iterates through loaded DSOs with DlIteratePhdrCallback to find the driver - interfacing DSO version number . Returns it as a string .
port::StatusOr<DriverVersion> Diagnostician::FindDsoVersion() {
  port::StatusOr<DriverVersion> result{port::Status{
      port::error::NOT_FOUND,
      "was unable to find librocm.so DSO loaded into this program"}};
  auto iterate_phdr = [](struct dl_phdr_info* info, size_t size,
                         void* data) -> int {
    if (strstr(info->dlpi_name, "librocm.so.1")) {
      VLOG(1) << "found DLL info with name: " << info->dlpi_name;
      char resolved_path[PATH_MAX] = {0};
      if (realpath(info->dlpi_name, resolved_path) == nullptr) {
        return 0;
      }
      VLOG(1) << "found DLL info with resolved path: " << resolved_path;
      const char* slash = rindex(resolved_path, '/');
      if (slash == nullptr) {
        return 0;
      }
      const char* so_suffix = ".so.";
      const char* dot = strstr(slash, so_suffix);
      if (dot == nullptr) {
        return 0;
      }
      string dso_version = dot + strlen(so_suffix);
      auto stripped_dso_version = absl::StripSuffix(dso_version, ".ld64");
      auto result = static_cast<port::StatusOr<DriverVersion>*>(data);
      *result = rocm::StringToDriverVersion(string(stripped_dso_version));
      return 1;
    }
    return 0;
  };
  dl_iterate_phdr(iterate_phdr, &result);
  return result;
}
port :: StatusOr < DriverVersion > Diagnostician :: FindDsoVersion ( ) { port :: StatusOr < DriverVersion > result { port :: Status { port :: error :: NOT_FOUND , " " } } ; auto iterate_phdr = [ ] ( struct dl_phdr_info * info , size_t size , void * data ) -> int { if ( strstr ( info -> dlpi_name , " " ) ) { VLOG ( 1 ) << " " << info -> dlpi_name ; char resolved_path [ PATH_MAX ] = { 0 } ; if ( realpath ( info -> dlpi_name , resolved_path ) == nullptr ) { return 0 ; } VLOG ( 1 ) << " " << resolved_path ; const char * slash = rindex ( resolved_path , ' ' ) ; if ( slash == nullptr ) { return 0 ; } const char * so_suffix = " " ; const char * dot = strstr ( slash , so_suffix ) ; if ( dot == nullptr ) { return 0 ; } string dso_version = dot + strlen ( so_suffix ) ; auto stripped_dso_version = absl :: StripSuffix ( dso_version , " " ) ; auto result = static_cast < port :: StatusOr < DriverVersion > * > ( data ) ; * result = rocm :: StringToDriverVersion ( string ( stripped_dso_version ) ) ; return 1 ; } return 0 ; } ; dl_iterate_phdr ( iterate_phdr , & result ) ; return result ; }
Iterates through loaded DSOs with DlIteratePhdrCallback to find the
driver-interfacing DSO version number.
Iterates through loaded DSOs with DlIteratePhdrCallback to find the driver - interfacing DSO version number .
// Callback used when iterating through DSOs. Looks for the driver-interfacing // DSO and yields its version number into the callback data, when found. // TODO(b/22689637): Eliminate the explicit namespace if possible.