news 2026/5/9 13:51:36

CANN/TensorFlow 1.15安装指南

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
CANN/TensorFlow 1.15安装指南

安装开源框架TensorFlow 1.15

【免费下载链接】tensorflowAscend TensorFlow Adapter项目地址: https://gitcode.com/cann/tensorflow

安装前准备

[!NOTE]说明 TensorFlow 1.15配套的Python版本是:Python3.7.x(3.7.5~3.7.11)。

  • 对于x86架构,可直接跳过安装前准备。

  • 对于aarch64架构,由于TensorFlow依赖h5py,而h5py依赖HDF5,需要先编译安装HDF5,否则使用pip安装h5py会报错,以下步骤以root用户操作。

    1. 确保已安装配套版本的Python。

    2. 编译安装HDF5 1.10.5版本。

      1. 访问下载链接下载HDF5源码包,并上传到安装环境的任意目录。

      2. 进入源码包所在目录,执行如下命令解压源码包。

        tar -zxvf hdf5-1.10.5.tar.gz
      3. 进入解压后的文件夹,执行配置、编译和安装命令:

        cd hdf5-1.10.5/ ./configure --prefix=/usr/local/hdf5 make -j16 && make install
      4. 配置环境变量。

        export CPATH=/usr/local/hdf5/include/:/usr/local/hdf5/lib/ export LD_LIBRARY_PATH=/usr/local/hdf5/lib/:$LD_LIBRARY_PATH
    3. 安装h5py。

      1. root用户下执行如下命令安装h5py依赖包。

        pip3 install "Cython<3" pip3 install wheel
      2. root用户下执行如下命令安装h5py。

        pip3 install numpy #未安装numpy时,h5py 2.8.0在线安装会失败 pip3 install h5py==2.8.0

安装TensorFlow

需要安装TensorFlow才可以进行算子开发验证、训练业务开发。

  • 对于x86架构:直接从pip源下载即可,系统要求等具体请参考TensorFlow官网。需要注意TensorFlow官网提供的指导描述有误,从pip源下载CPU版本需要显式指定tensorflow-cpu,如果不指定CPU,默认下载的是GPU版本。安装命令参考如下:

    如下命令如果使用非root用户安装,需要在安装命令后加上--user,例如:pip3 install tensorflow-cpu==1.15 --user

    安装TensorFlow 1.15:

    pip3 install tensorflow-cpu==1.15
  • 对于aarch64架构:由于pip源未提供对应的版本,所以需要用户使用官网要求的linux_gcc7.3.0编译器编译TensorFlow 1.15,编译步骤参考官网TensorFlow官网。特别注意点如下。

    在下载完tensorflow tag v1.15.0后需要执行如下步骤:

  1. 下载“nsync-1.22.0.tar.gz”源码包。

    1. 进入源码目录,打开“tensorflow/workspace.bzl”文件,找到其中name为nsync的“tf_http_archive”定义。

      tf_http_archive( name = "nsync", sha256 = "caf32e6b3d478b78cff6c2ba009c3400f8251f646804bcb65465666a9cea93c4", strip_prefix = "nsync-1.22.0", system_build_file = clean_dep("//third_party/systemlibs:nsync.BUILD"), urls = [ "https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/nsync/archive/1.22.0.tar.gz", "https://github.com/google/nsync/archive/1.22.0.tar.gz", ], )
    2. 从urls中的任一路径下载nsync-1.22.0.tar.gz的源码包,保存到任意路径。

  2. 修改“nsync-1.22.0.tar.gz”源码包。

    1. 切换到nsync-1.22.0.tar.gz所在路径,解压缩该源码包。解压缩后存在“nsync-1.22.0”文件夹和“pax_global_header”文件。

    2. 编辑“nsync-1.22.0/platform/c++11/atomic.h”。

      修改前:

      #include "nsync_cpp.h" #include "nsync_atomic.h" NSYNC_CPP_START_ static INLINE int atm_cas_nomb_u32_ (nsync_atomic_uint32_ *p, uint32_t o, uint32_t n) { return (std::atomic_compare_exchange_strong_explicit (NSYNC_ATOMIC_UINT32_PTR_ (p), &o, n, std::memory_order_relaxed, std::memory_order_relaxed)); } static INLINE int atm_cas_acq_u32_ (nsync_atomic_uint32_ *p, uint32_t o, uint32_t n) { return (std::atomic_compare_exchange_strong_explicit (NSYNC_ATOMIC_UINT32_PTR_ (p), &o, n, std::memory_order_acquire, std::memory_order_relaxed)); } static INLINE int atm_cas_rel_u32_ (nsync_atomic_uint32_ *p, uint32_t o, uint32_t n) { return (std::atomic_compare_exchange_strong_explicit (NSYNC_ATOMIC_UINT32_PTR_ (p), &o, n, std::memory_order_release, std::memory_order_relaxed)); } static INLINE int atm_cas_relacq_u32_ (nsync_atomic_uint32_ *p, uint32_t o, uint32_t n) { return (std::atomic_compare_exchange_strong_explicit (NSYNC_ATOMIC_UINT32_PTR_ (p), &o, n, std::memory_order_acq_rel, std::memory_order_relaxed)); }

      修改后:

      #include "nsync_cpp.h" #include "nsync_atomic.h" NSYNC_CPP_START_ #define ATM_CB_() __sync_synchronize() static INLINE int atm_cas_nomb_u32_ (nsync_atomic_uint32_ *p, uint32_t o, uint32_t n) { int result = (std::atomic_compare_exchange_strong_explicit (NSYNC_ATOMIC_UINT32_PTR_ (p), &o, n, std::memory_order_relaxed, std::memory_order_relaxed)); ATM_CB_(); return result; } static INLINE int atm_cas_acq_u32_ (nsync_atomic_uint32_ *p, uint32_t o, uint32_t n) { int result = (std::atomic_compare_exchange_strong_explicit (NSYNC_ATOMIC_UINT32_PTR_ (p), &o, n, std::memory_order_acquire, std::memory_order_relaxed)); ATM_CB_(); return result; } static INLINE int atm_cas_rel_u32_ (nsync_atomic_uint32_ *p, uint32_t o, uint32_t n) { int result = (std::atomic_compare_exchange_strong_explicit (NSYNC_ATOMIC_UINT32_PTR_ (p), &o, n, std::memory_order_release, std::memory_order_relaxed)); ATM_CB_(); return result; } static INLINE int atm_cas_relacq_u32_ (nsync_atomic_uint32_ *p, uint32_t o, uint32_t n) { int result = (std::atomic_compare_exchange_strong_explicit (NSYNC_ATOMIC_UINT32_PTR_ (p), &o, n, std::memory_order_acq_rel, std::memory_order_relaxed)); ATM_CB_(); return result; }
  3. 重新压缩“nsync-1.22.0.tar.gz”源码包。

    将上个步骤中解压出的内容压缩为一个新的“nsync-1.22.0.tar.gz”源码包,保存(例如,保存在“/tmp/nsync-1.22.0.tar.gz”)。

  4. 重新生成“nsync-1.22.0.tar.gz”源码包的sha256sum校验码。

    执行如下命令后得到sha256sum校验码(一串数字和字母的组合)。

    sha256sum /tmp/nsync-1.22.0.tar.gz
  5. 修改sha256sum校验码和urls。

    进入tensorflow tag源码目录,打开“tensorflow/workspace.bzl”文件,找到其中name为nsync的“tf_http_archive”定义,其中“sha256=”后面的数字填写步骤4得到的校验码,“urls=”后面的列表第二行,填写存放“nsync-1.22.0.tar.gz”的file://索引。

    tf_http_archive( name = "nsync", sha256 = "caf32e6b3d478b78cff6c2ba009c3400f8251f646804bcb65465666a9cea93c4", strip_prefix = "nsync-1.22.0", system_build_file = clean_dep("//third_party/systemlibs:nsync.BUILD"), urls = [ "https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/nsync/archive/1.22.0.tar.gz", "file:///tmp/nsync-1.22.0.tar.gz", "https://github.com/google/nsync/archive/1.22.0.tar.gz", ], )
  6. 继续参考官方文档(https://www.tensorflow.org/install/source)完成编译。

    [!NOTE]说明 ABI的配置在TensorFlow和FwkPlugin中需要保持一致(即配置为0),否则会导致导入TFA失败。

  7. 安装编译好的TensorFlow。

    以上步骤执行完后会打包TensorFlow到指定目录,进入指定目录后执行如下命令安装:

    如下命令如果使用非root用户安装,需要在安装命令后加上--user,例如:pip3 install tensorflow-1.15.0-*.whl --user

    pip3 install tensorflow-1.15.0-*.whl
  8. 执行如下命令验证安装效果。

    python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

    如果返回了张量则表示安装成功。

【免费下载链接】tensorflowAscend TensorFlow Adapter项目地址: https://gitcode.com/cann/tensorflow

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/5/9 13:50:55

CANN ops-tensor Blaze引擎

Blaze 【免费下载链接】ops-tensor ops-tensor 是 CANN &#xff08;Compute Architecture for Neural Networks&#xff09;算子库中提供张量类计算的基础算子库&#xff0c;采用模块化设计&#xff0c;支持灵活的算子开发和管理。 项目地址: https://gitcode.com/cann/ops-…

作者头像 李华
网站建设 2026/5/9 13:45:35

在多模型间切换时 Taotoken 的路由与容灾能力体验

&#x1f680; 告别海外账号与网络限制&#xff01;稳定直连全球优质大模型&#xff0c;限时半价接入中。 &#x1f449; 点击领取海量免费额度 在多模型间切换时 Taotoken 的路由与容灾能力体验 对于依赖大模型 API 进行开发的团队而言&#xff0c;服务的稳定性是保障业务连续…

作者头像 李华
网站建设 2026/5/9 13:45:35

CANN/cannbot-skills:A2三桥核在线Softmax尾部处理

Online Softmax Tail Handling on A2 Triple-Bridge Kernels 【免费下载链接】cannbot-skills CANNBot 是面向 CANN 开发的用于提升开发效率的系列智能体&#xff0c;本仓库为其提供可复用的 Skills 模块。 项目地址: https://gitcode.com/cann/cannbot-skills Read thi…

作者头像 李华
网站建设 2026/5/9 13:44:55

KrkrzExtract终极指南:新一代krkrz引擎资源解包工具完全解析

KrkrzExtract终极指南&#xff1a;新一代krkrz引擎资源解包工具完全解析 【免费下载链接】KrkrzExtract The next generation of KrkrExtract 项目地址: https://gitcode.com/gh_mirrors/kr/KrkrzExtract KrkrzExtract是专门为krkrz引擎设计的下一代资源处理工具&#x…

作者头像 李华
网站建设 2026/5/9 13:35:32

AI赋能无人机通信与导航:端到端智能优化与关键技术解析

1. 项目概述&#xff1a;当无人机遇上AI&#xff0c;通信与导航的范式革命最近几年&#xff0c;无人机&#xff08;UAV&#xff09;的应用场景正以前所未有的速度扩张&#xff0c;从最初的航拍娱乐&#xff0c;到如今的物流配送、农业植保、电力巡检、应急救援&#xff0c;甚至…

作者头像 李华