杰哥的{运维,编程,调板子}小笔记
在 HarmonyOS 5 上运行 Fortran 程序¶
背景¶
前段时间把 SPEC CPU 2017 移植到了鸿蒙 5 上:https://github.com/jiegec/SPECCPU2017Harmony,由于 SPEC CPU 2017 里有不少 Fortran 程序,所以就研究了一下怎么编译 Fortran 代码,最终搞成了,在这里记录一下。
过程¶
HarmonyOS 5 的工具链用的是 LLVM 15,自带的编译器是 clang,那个时候还没有 LLVM flang。但是,经过实际测试,使用新版本的 flang,也是可以的,只是需要做一些额外的操作。例如 flang 有自己的 runtime(类比 libgcc 和 LLVM 的 compiler-rt),需要交叉编译一个 arm64 的版本,下面是仓库中 build-flang.sh 的内容:
核心就是以 aarch64-linux-ohos 为 target,编译出三个
参考 [flang] fatal Fortran runtime error,就知道是编译器版本和 runtime 不兼容的问题了。
编译好了 fortran runtime 之后,就可以用 flang-new-20 编译 fortran 代码了。这里给出 CMake 的配置方式,主要涉及到需要用的编译选项:
这里的相对路径,其实就是要找到新编译出来的 flang runtime,以及 HarmonyOS command line tools 里面的一些库,具体路径需要根据实际情况来调整,这里只是一个样例。
到这里,就可以在 HarmonyOS 5 上运行 Fortran 程序了。其实还可以考虑研究一下 GFortran,或许也是能实现的,但目前还没有去做进一步的尝试。
source
在 HarmonyOS 5 上运行 Fortran 程序¶
背景¶
前段时间把 SPEC CPU 2017 移植到了鸿蒙 5 上:https://github.com/jiegec/SPECCPU2017Harmony,由于 SPEC CPU 2017 里有不少 Fortran 程序,所以就研究了一下怎么编译 Fortran 代码,最终搞成了,在这里记录一下。
过程¶
HarmonyOS 5 的工具链用的是 LLVM 15,自带的编译器是 clang,那个时候还没有 LLVM flang。但是,经过实际测试,使用新版本的 flang,也是可以的,只是需要做一些额外的操作。例如 flang 有自己的 runtime(类比 libgcc 和 LLVM 的 compiler-rt),需要交叉编译一个 arm64 的版本,下面是仓库中 build-flang.sh 的内容:
#!/bin/sh# build missing libraries for aarch64-linux-ohos target# assume llvm-project is cloned at $HOME/llvm-projectset -x -emkdir -p flangexport PATH=~/command-line-tools/sdk/default/openharmony/native/llvm/bin:$PATHDST=$PWD/flangcd $HOME/llvm-projectgit checkout main# match hash in flang-new-20 --versiongit reset 7cf14539b644 --hardcd libunwindrm -rf buildmkdir -p buildcd buildcmake .. -G Ninja \ -DCMAKE_C_FLAGS="-target aarch64-linux-ohos -fuse-ld=lld" \ -DCMAKE_C_COMPILER="clang" \ -DCMAKE_CXX_FLAGS="-target aarch64-linux-ohos -fuse-ld=lld" \ -DCMAKE_CXX_COMPILER="clang++"ninjacp lib/libunwind.a $DST/cd ../../cd flang/lib/Decimalrm -rf buildmkdir -p buildcd buildcmake .. -G Ninja \ -DCMAKE_C_FLAGS="-target aarch64-linux-ohos -fuse-ld=lld -fPIC" \ -DCMAKE_C_COMPILER="clang" \ -DCMAKE_CXX_FLAGS="-target aarch64-linux-ohos -fuse-ld=lld -fPIC" \ -DCMAKE_CXX_COMPILER="clang++"ninjacp libFortranDecimal.a $DST/cd ../../../../cd flang/runtimerm -rf buildmkdir -p buildcd buildcmake .. -G Ninja \ -DCMAKE_C_FLAGS="-target aarch64-linux-ohos -fuse-ld=lld -fPIC" \ -DCMAKE_C_COMPILER="clang" \ -DCMAKE_CXX_FLAGS="-target aarch64-linux-ohos -fuse-ld=lld -fPIC" \ -DCMAKE_CXX_COMPILER="clang++"ninjacp libFortranRuntime.a $DST/cd ../../../ls -al $DST核心就是以 aarch64-linux-ohos 为 target,编译出三个
.a 文件,之后再链接上就可以了。需要注意的是,runtime 版本和 flang 版本需要一致。为了偷懒,直接用的是 LLVM APT 提供的 flang-new-20 的 binary,那么它是会随着 apt upgrade 而更新的,这个时候就需要重新编译一次 flang runtime,然后链接到程序里。如果版本不对上,可能遇到一些问题:fatal Fortran runtime error(/home/jiegec/llvm-project/flang/runtime/descriptor.cpp:74): not yet implemented: type category(6)参考 [flang] fatal Fortran runtime error,就知道是编译器版本和 runtime 不兼容的问题了。
编译好了 fortran runtime 之后,就可以用 flang-new-20 编译 fortran 代码了。这里给出 CMake 的配置方式,主要涉及到需要用的编译选项:
set(CMAKE_Fortran_COMPILER_FORCED TRUE)set(CMAKE_Fortran_COMPILER "flang-new-20")set(CMAKE_Fortran_FLAGS "-target aarch64-linux-ohos -fuse-ld=lld -L ${CMAKE_CURRENT_SOURCE_DIR}/../../../../flang -nostdlib -L ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../command-line-tools/sdk/default/openharmony/native/sysroot/usr/lib/aarch64-linux-ohos -lc -lm -L ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../command-line-tools/sdk/default/openharmony/native/llvm/lib/clang/15.0.4/lib/aarch64-linux-ohos/ -lclang_rt.builtins -lFortranRuntime -lFortranDecimal")enable_language(Fortran)这里的相对路径,其实就是要找到新编译出来的 flang runtime,以及 HarmonyOS command line tools 里面的一些库,具体路径需要根据实际情况来调整,这里只是一个样例。
到这里,就可以在 HarmonyOS 5 上运行 Fortran 程序了。其实还可以考虑研究一下 GFortran,或许也是能实现的,但目前还没有去做进一步的尝试。
source
杰哥的{运维,编程,调板子}小笔记
鸿蒙电脑 MateBook Pro 开箱体验¶
购买¶
2025.6.6 号正式开卖,当华为线上商城显示没货的时候,果断去线下门店买了一台回来。购买的是 32GB 内存,1TB SSD 存储,加柔光屏的版本,型号 HAD-W32,原价 9999,国补后 7999。
开箱¶
由于用了国补,需要当面激活,就在店里直接激活了,所以没有体验到鸿蒙系统的扫码激活功能,有点可惜。激活前的第一次开机需要插电,直接按电源键是没有反应的。激活过程也很简单,联网,创建用户,登录华为账号,就可以了。包装盒里还有 140W 单口 Type-C 电源适配器,体积挺小的。此外附赠了一条 Type-C to Type-C 的线,还有一个 Type-C 有线耳机,外加一个 Type-A 母口加 Type-C 公口的线,可以用来接 Type-A 公口的外设。此外还有快速指南和一个超纤抛光布。
外形上,就是 MateBook X Pro 加了一个 HarmonyOS 的标识,上手很轻,不愧是不到一公斤的笔记本,对于习惯用 MacBookAir 轻薄本的我来说,是很大的一个亮点。
未完待续¶
source
鸿蒙电脑 MateBook Pro 开箱体验¶
购买¶
2025.6.6 号正式开卖,当华为线上商城显示没货的时候,果断去线下门店买了一台回来。购买的是 32GB 内存,1TB SSD 存储,加柔光屏的版本,型号 HAD-W32,原价 9999,国补后 7999。
开箱¶
由于用了国补,需要当面激活,就在店里直接激活了,所以没有体验到鸿蒙系统的扫码激活功能,有点可惜。激活前的第一次开机需要插电,直接按电源键是没有反应的。激活过程也很简单,联网,创建用户,登录华为账号,就可以了。包装盒里还有 140W 单口 Type-C 电源适配器,体积挺小的。此外附赠了一条 Type-C to Type-C 的线,还有一个 Type-C 有线耳机,外加一个 Type-A 母口加 Type-C 公口的线,可以用来接 Type-A 公口的外设。此外还有快速指南和一个超纤抛光布。
外形上,就是 MateBook X Pro 加了一个 HarmonyOS 的标识,上手很轻,不愧是不到一公斤的笔记本,对于习惯用 MacBookAir 轻薄本的我来说,是很大的一个亮点。
未完待续¶
source
#TIL
GhostScript
How to avoid AIGC Detection on your arts homework (assuming your teacher doesn't know what is OCR and have no time digging into what happened)
GhostScript
How to avoid AIGC Detection on your arts homework (assuming your teacher doesn't know what is OCR and have no time digging into what happened)
gs -o vector.pdf -sDEVICE=pdfwrite -dNoOutputFonts input.pdfHow Compiler Explorer Works in 2025 — Matt Godbolt’s blog
https://xania.org/202506/how-compiler-explorer-works
https://xania.org/202506/how-compiler-explorer-works
Chips and Cheese
Qualcomm's Centriq 2400 and the Falkor Architecture
#ChipAndCheese
Telegraph | source
(author: Chester Lam)
Qualcomm's Centriq 2400 and the Falkor Architecture
#ChipAndCheese
Telegraph | source
(author: Chester Lam)
Computex 2025: RX 9060 XT, Threadripper 9000, ROCm, and more
#ChipAndCheese
Hello you fine Internet folks,
Today we are covering the announcements that AMD had at Computex 2025 which were the RX 9060 XT, Threadripper 9000, the Radeon AI Pro R9700, and more ROCm commitments. Due to time constraints and the vastness of Computex, the transcript/article will be done after Computex.
iframe (www.youtube-nocookie.com)
Hope y'all enjoy!
source
(author: George Cozma)
Computex 2025: Nvidia's Keynote
#ChipAndCheese
Hello you fine Internet folks,
Today we are covering the announcements that Nvidia had at Computex 2025 which were the RTX PRO servers, NVLink Fusion, a new supercomputer being built in Taiwan, and the announcement of a new building in Taiwan. Due to time constraints and the vastness of Computex, the transcript/article will be done after Computex.
iframe (www.youtube-nocookie.com)
Hope y'all enjoy!
source
(author: George Cozma)
