Commit 4262a1f3 authored by Yureka's avatar Yureka
Browse files
parent afb10c30
Loading
Loading
Loading
Loading
+0 −45
Original line number Diff line number Diff line
diff --git a/onnxruntime/core/common/cpuid_info.cc b/onnxruntime/core/common/cpuid_info.cc
--- a/onnxruntime/core/common/cpuid_info.cc
+++ b/onnxruntime/core/common/cpuid_info.cc
@@ -3,6 +3,7 @@
 #include "core/common/cpuid_info.h"
 #include "core/common/logging/logging.h"
 #include "core/common/logging/severity.h"
+#include <iostream>
 
 #ifdef __linux__
 
@@ -364,8 +365,14 @@
 #if defined(CPUINFO_SUPPORTED)
   pytorch_cpuinfo_init_ = cpuinfo_initialize();
   if (!pytorch_cpuinfo_init_) {
-    LOGS_DEFAULT(WARNING) << "Failed to initialize PyTorch cpuinfo library. May cause CPU EP performance degradation "
-                             "due to undetected CPU features.";
+    constexpr const char* message =
+        "Failed to initialize PyTorch cpuinfo library. May cause CPU EP performance degradation due to undetected CPU "
+        "features.";
+    if (logging::LoggingManager::HasDefaultLogger()) {
+      LOGS_DEFAULT(WARNING) << message;
+    } else {
+      std::cerr << "onnxruntime cpuid_info warning: " << message << std::endl;
+    }
   }
 #endif  // defined(CPUINFO_SUPPORTED)
 #if defined(__linux__)
diff --git a/onnxruntime/core/platform/posix/env.cc b/onnxruntime/core/platform/posix/env.cc
--- a/onnxruntime/core/platform/posix/env.cc
+++ b/onnxruntime/core/platform/posix/env.cc
@@ -605,7 +605,12 @@
   PosixEnv() {
     cpuinfo_available_ = cpuinfo_initialize();
     if (!cpuinfo_available_) {
-      LOGS_DEFAULT(INFO) << "cpuinfo_initialize failed";
+      constexpr const char* message = "cpuinfo_initialize failed";
+      if (logging::LoggingManager::HasDefaultLogger()) {
+        LOGS_DEFAULT(INFO) << message;
+      } else {
+        std::cerr << "onnxruntime cpuid_info warning: " << message << std::endl;
+      }
     }
   }
   bool cpuinfo_available_{false};
+74 −47
Original line number Diff line number Diff line
{
  lib,
  config,
  stdenv,
  lib,
  fetchFromGitHub,
  applyPatches,
  fetchpatch,
  abseil-cpp_202407,
  cmake,
@@ -33,51 +34,68 @@
}@inputs:

let
  version = "1.22.2";

  src = fetchFromGitHub {
    owner = "microsoft";
    repo = "onnxruntime";
    tag = "v${version}";
    fetchSubmodules = true;
    hash = "sha256-X8Pdtc0eR0iU+Xi2A1HrNo1xqCnoaxNjj4QFm/E3kSE=";
  };

  stdenv = throw "Use effectiveStdenv instead";
  effectiveStdenv = if cudaSupport then cudaPackages.backendStdenv else inputs.stdenv;
  inherit (cudaPackages) cuda_nvcc;

  cudaArchitecturesString = cudaPackages.flags.cmakeCudaArchitecturesString;

  mp11 = fetchFromGitHub {
  # TODO: update the following dependencies according to:
  # https://github.com/microsoft/onnxruntime/blob/v<VERSION>/cmake/deps.txt

  mp11-src = fetchFromGitHub {
    name = "mp11-src";
    owner = "boostorg";
    repo = "mp11";
    tag = "boost-1.82.0";
    hash = "sha256-cLPvjkf2Au+B19PJNrUkTW/VPxybi1MpPxnIl4oo4/o=";
  };

  safeint = fetchFromGitHub {
  safeint-src = fetchFromGitHub {
    name = "safeint-src";
    owner = "dcleblanc";
    repo = "safeint";
    tag = "3.0.28";
    hash = "sha256-pjwjrqq6dfiVsXIhbBtbolhiysiFlFTnx5XcX77f+C0=";
  };

  onnx = fetchFromGitHub {
  onnx-src = applyPatches {
    name = "onnx-src";
    src = fetchFromGitHub {
      owner = "onnx";
      repo = "onnx";
    tag = "v1.17.0";
    hash = "sha256-9oORW0YlQ6SphqfbjcYb0dTlHc+1gzy9quH/Lj6By8Q=";
      tag = "v1.18.0";
      hash = "sha256-UhtF+CWuyv5/Pq/5agLL4Y95YNP63W2BraprhRqJOag=";
    };

    patches = [
      # Fix "error: conversion from 'onnx::OpSchema' to non-scalar type 'onnx::OpSchemaRegistry::OpSchemaRegisterOnce'"
      # https://github.com/microsoft/onnxruntime/issues/26229
      # Fix from https://github.com/onnx/onnx/pull/7390
      (fetchpatch {
        url = "https://github.com/onnx/onnx/commit/595a069aaac07586f111681245bc808ee63551f8.patch";
        includes = [ "onnx/defs/schema.h" ];
        hash = "sha256-FFAJuJse4nmNT3ixvEdlqzbr3edY46SqEFv7z/oo6m0=";
      })

      # Fix "undefined reference to `onnx::RNNShapeInference(onnx::InferenceContext&)'"
      (fetchpatch {
        url = "https://github.com/onnx/onnx/commit/6769c41ad64ebca0358da8c7211d2c6d0e627b2b.patch";
        hash = "sha256-VlTHs0om20kTNvSVQaasSsa5JROliQy4k9BECTsBtbU=";
      })
    ];
  };

  cutlass = fetchFromGitHub {
  cutlass-src = fetchFromGitHub {
    name = "cutlass-src";
    owner = "NVIDIA";
    repo = "cutlass";
    tag = "v3.5.1";
    hash = "sha256-sTGYN+bjtEqQ7Ootr/wvx3P9f8MCDSSj3qyCWjfdLEA=";
    tag = "v3.9.2";
    hash = "sha256-teziPNA9csYvhkG5t2ht8W8x5+1YGGbHm8VKx4JoxgI=";
  };

  dlpack = fetchFromGitHub {
  dlpack-src = fetchFromGitHub {
    name = "dlpack-src";
    owner = "dmlc";
    repo = "dlpack";
    rev = "5c210da409e7f1e51ddf445134a4376fdbd70d7d";
@@ -86,23 +104,31 @@ let

  isCudaJetson = cudaSupport && cudaPackages.flags.isJetsonBuild;
in
effectiveStdenv.mkDerivation rec {
effectiveStdenv.mkDerivation (finalAttrs: {
  pname = "onnxruntime";
  inherit src version;
  version = "1.23.2";

  src = fetchFromGitHub {
    owner = "microsoft";
    repo = "onnxruntime";
    tag = "v${finalAttrs.version}";
    fetchSubmodules = true;
    hash = "sha256-hZ2L5+0Enkw4rGDKVpRECnKXP87w6Kbiyp6Fdxwt6hk=";
  };

  patches = [
    # https://github.com/microsoft/onnxruntime/pull/24583
    # Missing cstdint include (GCC 15 compatibility)
    (fetchpatch {
      url = "https://github.com/microsoft/onnxruntime/commit/d6e712c5b7b6260a61e54d1fe40107cf5366ee77.patch";
      hash = "sha256-FSuPybX8f2VoxvLhcYx4rdChaiK8bSUDR32sN3Efwfc=";
    })

    # Correct maybe-uninitialized and range-loop-construct warnings
    # https://github.com/microsoft/onnxruntime/pull/26201
    (fetchpatch {
      name = "fix-compilation-with-gcc-15.patch";
      url = "https://github.com/microsoft/onnxruntime/commit/f7619dc93f592ddfc10f12f7145f9781299163a0.patch";
      hash = "sha256-jxfMB+/Zokcu5DSfZP7QV1E8mTrsLe/sMr+ZCX/Y3m0=";
      url = "https://github.com/microsoft/onnxruntime/commit/8ebd0bf1cf02414584d15d7244b07fa97d65ba02.patch";
      hash = "sha256-vX+kaFiNdmqWI91JELcLpoaVIHBb5EPbI7rCAMYAx04=";
    })
    # Handle missing default logger when cpuinfo initialization fails in the build sandbox
    # TODO: Remove on next release
    # https://github.com/microsoft/onnxruntime/issues/10038
    # https://github.com/microsoft/onnxruntime/pull/15661
    # https://github.com/microsoft/onnxruntime/pull/20509
    ./cpuinfo-logging.patch
  ];

  nativeBuildInputs = [
@@ -192,9 +218,9 @@ effectiveStdenv.mkDerivation rec {
  ++ lib.optionals pythonSupport (
    with python3Packages;
    [
      onnx
      pytest
      sympy
      onnx
    ]
  );

@@ -215,17 +241,17 @@ effectiveStdenv.mkDerivation rec {
    (lib.cmakeBool "FETCHCONTENT_FULLY_DISCONNECTED" true)
    (lib.cmakeBool "FETCHCONTENT_QUIET" false)
    (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_ABSEIL_CPP" "${abseil-cpp_202407.src}")
    (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_DLPACK" "${dlpack}")
    (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_DLPACK" "${dlpack-src}")
    (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_FLATBUFFERS" "${flatbuffers_23.src}")
    (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_MP11" "${mp11}")
    (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_ONNX" "${onnx}")
    (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_MP11" "${mp11-src}")
    (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_ONNX" "${onnx-src}")
    (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_RE2" "${re2.src}")
    (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_SAFEINT" "${safeint}")
    (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_SAFEINT" "${safeint-src}")
    (lib.cmakeFeature "FETCHCONTENT_TRY_FIND_PACKAGE_MODE" "ALWAYS")
    # fails to find protoc on darwin, so specify it
    (lib.cmakeFeature "ONNX_CUSTOM_PROTOC_EXECUTABLE" (lib.getExe protobuf))
    (lib.cmakeBool "onnxruntime_BUILD_SHARED_LIB" true)
    (lib.cmakeBool "onnxruntime_BUILD_UNIT_TESTS" doCheck)
    (lib.cmakeBool "onnxruntime_BUILD_UNIT_TESTS" finalAttrs.doCheck)
    (lib.cmakeBool "onnxruntime_USE_FULL_PROTOBUF" withFullProtobuf)
    (lib.cmakeBool "onnxruntime_USE_CUDA" cudaSupport)
    (lib.cmakeBool "onnxruntime_USE_NCCL" (cudaSupport && ncclSupport))
@@ -242,7 +268,7 @@ effectiveStdenv.mkDerivation rec {
  ++ lib.optionals cudaSupport [
    # Werror and cudnn_frontend deprecations make for a bad time.
    "--compile-no-warning-as-error"
    (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_CUTLASS" "${cutlass}")
    (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_CUTLASS" "${cutlass-src}")
    (lib.cmakeFeature "onnxruntime_CUDNN_HOME" "${cudaPackages.cudnn}")
    (lib.cmakeFeature "CMAKE_CUDA_ARCHITECTURES" cudaArchitecturesString)
    (lib.cmakeFeature "onnxruntime_NVCC_THREADS" "1")
@@ -296,8 +322,9 @@ effectiveStdenv.mkDerivation rec {
    substituteInPlace cmake/libonnxruntime.pc.cmake.in \
      --replace-fail '$'{prefix}/@CMAKE_INSTALL_ @CMAKE_INSTALL_
    echo "find_package(cudnn_frontend REQUIRED)" > cmake/external/cudnn_frontend.cmake

  ''
  # https://github.com/microsoft/onnxruntime/blob/c4f3742bb456a33ee9c826ce4e6939f8b84ce5b0/onnxruntime/core/platform/env.h#L249
  + ''
    substituteInPlace onnxruntime/core/platform/env.h --replace-fail \
      "GetRuntimePath() const { return PathString(); }" \
      "GetRuntimePath() const { return PathString(\"$out/lib/\"); }"
@@ -305,8 +332,8 @@ effectiveStdenv.mkDerivation rec {
  + lib.optionalString rocmSupport ''
    patchShebangs tools/ci_build/hipify-perl
  ''
  + lib.optionalString (effectiveStdenv.hostPlatform.system == "aarch64-linux") ''
  # https://github.com/NixOS/nixpkgs/pull/226734#issuecomment-1663028691
  + lib.optionalString (effectiveStdenv.hostPlatform.system == "aarch64-linux") ''
    rm -v onnxruntime/test/optimizer/nhwc_transformer_test.cc
  '';

@@ -314,8 +341,8 @@ effectiveStdenv.mkDerivation rec {
    ${python3Packages.python.interpreter} ../setup.py bdist_wheel
  '';

  postInstall = ''
  # perform parts of `tools/ci_build/github/linux/copy_strip_binary.sh`
  postInstall = ''
    install -m644 -Dt $out/include \
      ../include/onnxruntime/core/framework/provider_options.h \
      ../include/onnxruntime/core/providers/cpu/cpu_provider_factory.h \
@@ -348,7 +375,7 @@ effectiveStdenv.mkDerivation rec {
      compatibility.
    '';
    homepage = "https://github.com/microsoft/onnxruntime";
    changelog = "https://github.com/microsoft/onnxruntime/releases/tag/v${version}";
    changelog = "https://github.com/microsoft/onnxruntime/releases/tag/${finalAttrs.src.tag}";
    # https://github.com/microsoft/onnxruntime/blob/master/BUILD.md#architectures
    platforms = lib.platforms.unix;
    license = lib.licenses.mit;
@@ -357,4 +384,4 @@ effectiveStdenv.mkDerivation rec {
      ck3d
    ];
  };
}
})