feat(ray): 对齐 Ray 1.0.1,nax 作为 driver 跑通跨架构 MPC
用户要求先用 1.0.1 对齐两端再把 nax MPC 跑通。闭环达成:
x86_64 Ray node 73bfdc0a… nax site=b MPC 35
armv7 Ray node 235afb22… nax site=a MPC 35
同一进程既是 Ray driver 又是 MPC 参与方;node_id 由 raylet 握手分配,
两端不同即「真的挂在两个节点上」的证据。35 = (1·4+1)+(2·5+1)+(3·6+1)。
1.0.1 shim(ray/nax_ray_shim_101.cc)与 2.59 的六个接口差异:
CoreWorkerProcess 无独立头、TaskExecutionCallback 只有 8 参数、
GcsClientOptions 位置参数、无 GetNodeToConnectForDriver/GetNextJobID、
无 ray::core 命名空间、GcsNodeInfo 无 node_manager_port。
两个必踩的坑:
- options.num_workers 必须显式设 1(1.0.1 有 RAY_CHECK(>0),默认 0 abort)
- gcs_options 要指向 Redis(6400)而非 gcs_server(6402),指错报
Protocol error got "\x00",看着像协议问题其实是端口给错
同一版本两个架构的 string ABI 不同(关键):
x86_64 _raylet.so 是旧 ABI(0 个 cxx11),armv7 是新 ABI(423 个)。
搞错的表现是运行期 basic_string::_M_create 异常,错误信息不提 ABI。
编译补丁自动打在解出来的头上:client_call.h 的 vector<CompletionQueue> 换 deque
(grpc 1.51 删了移动构造)、影子 arrow/buffer.h、-Dgrpc_impl=grpc。
Python 符号 x86 缺 8 个 / armv7 缺 2 个,shim 零值占位(不执行 Python 代码)。
nax-cli 加可选 feature ray:设 NAX_RAY_RAYLET 即注册 driver,默认构建仍是
纯静态单二进制。rpath 放在 nax-cli 的 build.rs(link-arg-bins),放 nax-ray
里传不到依赖方的 bin。
新增 docs/RAY_CORE_101.md、ray/{nax_ray_shim_101.cc,build101.sh,
build101_armv7.sh,test101.py,test101_arm.c,verify101.sh}、ray/armv7/mpc_ray.sh;
nax-ray 重写为 1.0.1 签名;README 状态表更新。
This commit is contained in:
1 parent
00e4fc322b
commit
45bc626256
17 files changed
+1067
-52
No files matched your search
Generated
+1
@@ -64,6 +64,7 @@ dependencies = [
|
||||
"nax-node",
|
||||
"nax-orch",
|
||||
"nax-psi",
|
||||
"nax-ray",
|
||||
"nax-tee",
|
||||
]
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
| `nax-cli` | ✅ 单二进制 **499 KB**,`selftest` / `node` / `psi` / `lr` 四个子命令 |
|
||||
| `nax-orch` 编排 | ✅ 661 行纯 std,PLAN 协议 + 两阶段提交,7 单测;本机三进程跑通 |
|
||||
| `nax-ray` Ray C++ 内核 | ✅ 链接 `_raylet.so` 接入真实集群(拿到 raylet 分配的 node id),见 `docs/RAY_CORE.md` |
|
||||
| Ray 1.0.1 跨架构 | ✅ x86_64 原生 + armv7(qemu) 同集群,两端各自注册成 driver,跨架构 MPC 结果一致,见 `docs/RAY_CORE_101.md` |
|
||||
| armv7 交叉编译 | ✅ **真出二进制**:musl 静态 687 KB,`file` 显示 `ARM, EABI5, statically linked` |
|
||||
|
||||
```bash
|
||||
@@ -300,7 +301,8 @@ crates/
|
||||
├── nax-node/ 节点服务:一方一进程,承载明文域 + 分片
|
||||
│ TcpTransport(两方单连接)/ TcpMesh(n 方全网状)
|
||||
├── nax-orch/ 集群编排:PLAN 文本协议 + 两阶段提交(纯 std,零依赖)
|
||||
├── nax-ray/ Ray C++ core 绑定(可选,std-only;默认不链接,见 docs/RAY_CORE.md)
|
||||
├── nax-ray/ Ray C++ core 绑定(可选,std-only;默认不链接)
|
||||
│ 2.59 → docs/RAY_CORE.md;1.0.1(armv7 唯一可选)→ docs/RAY_CORE_101.md
|
||||
└── nax-cli/ 单二进制 CLI
|
||||
ray/ nax_ray_shim.cc + build.sh(复用 pip wheel 的 _raylet.so,不走 bazel)
|
||||
refs/nax/ 参考实现(独立仓库,仅作基线)
|
||||
|
||||
@@ -18,3 +18,10 @@ nax-node = { path = "../nax-node" }
|
||||
nax-orch = { path = "../nax-orch" }
|
||||
nax-psi = { path = "../nax-psi" }
|
||||
nax-ml = { path = "../nax-ml" }
|
||||
# 可选:接入 Ray 集群做成员目录。默认关闭——铁律是 nax 单二进制,
|
||||
# 开了这个 feature 会动态依赖 libnax_ray.so + libpython,产物不再自包含。
|
||||
nax-ray = { path = "../nax-ray", optional = true }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
ray = ["nax-ray/probe"]
|
||||
@@ -0,0 +1,44 @@
|
||||
//! 只在带 `ray` feature 编译时,把 libnax_ray.so 所在目录写进可执行文件的 RUNPATH。
|
||||
//!
|
||||
//! 为什么不能放在 nax-ray 的 build.rs 里:`cargo:rustc-link-arg-bins` 只作用于
|
||||
//! **本包**的 bin 目标。nax-ray 自己是个 lib,它的 build script 加的东西传不到
|
||||
//! 依赖它的 nax-cli 上——症状是链接期能找到 .so、运行期报
|
||||
//! `libnax_ray.so: cannot open shared object file`,还得手动 LD_LIBRARY_PATH。
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-env-changed=NAX_RAY_LIB_DIR");
|
||||
println!("cargo:rerun-if-env-changed=NAX_RAY_LIB_NAME");
|
||||
println!("cargo:rerun-if-env-changed=NAX_RAY_LIBPYTHON");
|
||||
|
||||
// 没开 ray feature 就别管——默认构建是纯静态单二进制,不碰任何 .so。
|
||||
if std::env::var("CARGO_FEATURE_RAY").is_err() {
|
||||
return;
|
||||
}
|
||||
|
||||
let lib = std::env::var("NAX_RAY_LIB_NAME").unwrap_or_else(|_| "nax_ray".to_string());
|
||||
let mut dirs: Vec<String> = Vec::new();
|
||||
if let Ok(d) = std::env::var("NAX_RAY_LIB_DIR") {
|
||||
dirs.push(d);
|
||||
}
|
||||
// 与 nax-ray/build.rs 保持同一套搜索顺序
|
||||
if let Ok(m) = std::env::var("CARGO_MANIFEST_DIR") {
|
||||
if let Some(root) = std::path::Path::new(&m).parent().and_then(|p| p.parent()) {
|
||||
dirs.push(root.join("target/ray").display().to_string());
|
||||
}
|
||||
}
|
||||
dirs.push("/usr/local/lib".into());
|
||||
|
||||
for d in &dirs {
|
||||
if std::path::Path::new(d).join(format!("lib{lib}.so")).exists() {
|
||||
println!("cargo:rustc-link-arg-bins=-Wl,-rpath,{d}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// _raylet.so 自己带 RUNPATH 指向 libpython,但交叉编译的场景不一定,多带一个不亏。
|
||||
if let Ok(p) = std::env::var("NAX_RAY_LIBPYTHON") {
|
||||
if let Some(dir) = std::path::Path::new(&p).parent() {
|
||||
println!("cargo:rustc-link-arg-bins=-Wl,-rpath,{}", dir.display());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,17 @@ nax node 参数:
|
||||
--fxp N 定点小数位(默认 18)
|
||||
--seed HEX 会话主种子,64 位十六进制(默认全 0,仅测试)
|
||||
|
||||
接 Ray 做成员目录(需 `cargo build --features ray`):
|
||||
设了 NAX_RAY_RAYLET 就会先把本进程注册成 Ray cluster 的一个 driver,
|
||||
拿到 raylet 分配的 node id,再跑下面的会话。Ray 只提供「我在哪台机、
|
||||
带什么标签」,计算仍走 nax 自己的 TCP 帧。
|
||||
NAX_RAY_GCS GCS 的 redis 地址,如 127.0.0.1:6400(1.0.1 用 redis,不是 gRPC 端口)
|
||||
NAX_RAY_RAYLET 本节点 raylet socket 路径(必填,设了它就启用)
|
||||
NAX_RAY_PLASMA 本节点 plasma socket 路径(必填)
|
||||
NAX_RAY_NM_PORT raylet 的 node_manager 端口(必填)
|
||||
NAX_RAY_NODE_IP 本机 IP,默认 127.0.0.1
|
||||
NAX_RAY_JOB job id 整数,默认 1
|
||||
|
||||
两进程示例:
|
||||
nax node --site bob --sites alice,bob --listen 127.0.0.1:9444 --data 4,5,6 &
|
||||
nax node --site alice --sites alice,bob --connect 127.0.0.1:9444 --data 1,2,3
|
||||
@@ -272,6 +283,42 @@ fn parse_flag<'a>(args: &'a [String], name: &str) -> Option<&'a str> {
|
||||
.map(String::as_str)
|
||||
}
|
||||
|
||||
/// 若环境里给了 raylet socket,就把本进程注册成 Ray 集群的一个 driver。
|
||||
///
|
||||
/// 为什么要这一步:nax 自己不做集群成员管理(谁在线、各带什么资源标签),
|
||||
/// 这活交给 Ray。注册完成后 nax 才「知道自己在哪个节点上」,后续按
|
||||
/// `sites` 与资源标签把各方钉到机器上。计算仍然走 nax 自己的 TCP 帧。
|
||||
#[cfg(feature = "ray")]
|
||||
fn attach_ray(site: &str) -> Result<Option<nax_ray::RayCluster>, String> {
|
||||
if std::env::var("NAX_RAY_RAYLET").is_err() {
|
||||
return Ok(None);
|
||||
}
|
||||
let cfg = nax_ray::config_from_env(&format!("nax_{site}"))?;
|
||||
println!(
|
||||
" 接入 Ray 集群: gcs={} raylet={} nm_port={}",
|
||||
cfg.gcs_addr, cfg.raylet_socket, cfg.node_manager_port
|
||||
);
|
||||
let c = nax_ray::RayCluster::connect(&cfg)?;
|
||||
if let Some(nid) = c.node_id() {
|
||||
println!(" Ray 节点已确认: node_id={nid}(由 raylet 分配)");
|
||||
}
|
||||
if let Some(wid) = c.worker_id() {
|
||||
println!(" Ray worker_id={wid}");
|
||||
}
|
||||
Ok(Some(c))
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "ray"))]
|
||||
fn attach_ray(_site: &str) -> Result<Option<()>, String> {
|
||||
if std::env::var("NAX_RAY_RAYLET").is_ok() {
|
||||
return Err(
|
||||
"这个 nax 构建没开 ray feature。要用 Ray 做成员目录,请 `cargo build --features ray`"
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn cmd_node(args: &[String]) -> Result<(), String> {
|
||||
let site = parse_flag(args, "--site").ok_or("缺少 --site")?.to_string();
|
||||
let sites_raw = parse_flag(args, "--sites").ok_or("缺少 --sites")?;
|
||||
@@ -291,6 +338,10 @@ fn cmd_node(args: &[String]) -> Result<(), String> {
|
||||
let connect = parse_flag(args, "--connect");
|
||||
let peers_raw = parse_flag(args, "--peers");
|
||||
|
||||
// Ray 只在部署期起作用:把本进程注册成集群里的一个 driver,拿到成员目录。
|
||||
// 计算不出这个进程——下面的 transport/MPC 完全是 nax 自己的帧。
|
||||
let _ray = attach_ray(&site)?;
|
||||
|
||||
// 三种连法:两方 --connect(主动)、两方 --listen(被动)、n 方 --listen + --peers
|
||||
let transport = match (listen, connect, peers_raw) {
|
||||
(Some(_), Some(_), _) => {
|
||||
|
||||
+23
-7
@@ -30,6 +30,15 @@ fn main() {
|
||||
|| std::path::Path::new(d).join("libnax_ray.dylib").exists()
|
||||
});
|
||||
|
||||
// 库名可覆盖:交叉编译 armv7 时同一台机器上可能存在两份 shim
|
||||
//(x86 旧 ABI / armv7 新 ABI,见 docs/RAY_CORE_101.md),用文件名区分。
|
||||
let lib_name = std::env::var("NAX_RAY_LIB_NAME").unwrap_or_else(|_| "nax_ray".to_string());
|
||||
let hdr = format!("lib{lib_name}.so");
|
||||
let found = dirs
|
||||
.iter()
|
||||
.find(|d| std::path::Path::new(d).join(&hdr).exists())
|
||||
.or(found);
|
||||
|
||||
let Some(dir) = found else {
|
||||
// 没编过 Ray core 时不报错:这个 crate 的 rlib 本身不需要它,
|
||||
// 只有可执行文件(rayprobe / 带 ray 特性的 nax-cli)才需要链接。
|
||||
@@ -40,12 +49,15 @@ fn main() {
|
||||
return;
|
||||
};
|
||||
|
||||
// rpath 用 link-arg-bins:普通 link-arg 只作用于库,可执行文件不会带上,
|
||||
// 结果就是运行时 libnax_ray.so 找不到(还得手动设 LD_LIBRARY_PATH)。
|
||||
// 注意 Linux 的 ld 既认 RUNPATH 也认 RPATH,这里给 RUNPATH 就够。
|
||||
println!("cargo:rustc-link-search=native={dir}");
|
||||
println!("cargo:rustc-link-lib=dylib=nax_ray");
|
||||
// 让运行时也能找到它,省得用户再设 LD_LIBRARY_PATH
|
||||
println!("cargo:rustc-link-arg=-Wl,-rpath,{dir}");
|
||||
println!("cargo:rustc-link-lib=dylib={lib_name}");
|
||||
println!("cargo:rustc-link-arg-bins=-Wl,-rpath,{dir}");
|
||||
println!("cargo:rerun-if-env-changed=NAX_RAY_LIB_DIR");
|
||||
println!("cargo:rerun-if-changed={dir}/libnax_ray.so");
|
||||
println!("cargo:rerun-if-env-changed=NAX_RAY_LIB_NAME");
|
||||
println!("cargo:rerun-if-changed={dir}/{hdr}");
|
||||
|
||||
// libpython:ray 的 `_raylet.so` 是 CPython 扩展,即使我们不碰 Python API,
|
||||
// 动态链接器在加载它时也要 `_Py_NoneStruct` 等 253 个符号。所以必须把它拉进来。
|
||||
@@ -55,15 +67,19 @@ fn main() {
|
||||
"/usr/local/lib/libpython3.12.so",
|
||||
"/usr/lib/x86_64-linux-gnu/libpython3.12.so.1.0",
|
||||
"/usr/lib/x86_64-linux-gnu/libpython3.11.so.1.0",
|
||||
"/usr/lib/aarch64-linux-gnu/libpython3.12.so.1.0"]
|
||||
"/usr/lib/aarch64-linux-gnu/libpython3.12.so.1.0",
|
||||
// armv7 交叉编译时用 armhf 的 libpython(ray 1.0.1 的 armv7 wheel 是 cp36,
|
||||
// 但 3.11 提供了它需要的 201 个 Py* 符号里的 199 个,剩下 2 个由 shim 兜底)
|
||||
"/usr/lib/arm-linux-gnueabihf/libpython3.11.so.1.0",
|
||||
"/usr/lib/arm-linux-gnueabihf/libpython3.9.so.1.0"]
|
||||
.iter()
|
||||
.find(|p| std::path::Path::new(p).exists())
|
||||
.map(|p| p.to_string())
|
||||
});
|
||||
match py {
|
||||
Some(p) => {
|
||||
println!("cargo:rustc-link-arg=-Wl,--no-as-needed");
|
||||
println!("cargo:rustc-link-arg={p}");
|
||||
println!("cargo:rustc-link-arg-bins=-Wl,--no-as-needed");
|
||||
println!("cargo:rustc-link-arg-bins={p}");
|
||||
println!("cargo:rerun-if-env-changed=NAX_RAY_LIBPYTHON");
|
||||
}
|
||||
None => println!(
|
||||
|
||||
@@ -1,24 +1,44 @@
|
||||
//! 命令行探针:验证 nax 能不能通过 Ray C++ core 接入集群。
|
||||
//! 命令行探针:验证 nax 能不能通过 Ray C++ core 接入 1.0.1 集群。
|
||||
//!
|
||||
//! 用法:
|
||||
//! rayprobe <gcs_ip:port> [node_ip]
|
||||
//! 用法(参数与 1.0.1 的初始化路径一致,socket 路径必须显式给):
|
||||
//! rayprobe <gcs_ip:port> <raylet_sock> <plasma_sock> <node_manager_port> [node_ip] [lang]
|
||||
//!
|
||||
//! 期望输出里 `node_id` 是 raylet 分配的——这就是「真的连上了」的证据。
|
||||
//! 期望输出里 `rpc_raylet` 是 raylet 分配的——这就是「真的连上了」的证据。
|
||||
|
||||
use nax_ray::RayCluster;
|
||||
use nax_ray::{Language, RayCluster, RayNodeConfig};
|
||||
|
||||
fn main() {
|
||||
let mut args = std::env::args().skip(1);
|
||||
let addr = args.next().unwrap_or_else(|| "127.0.0.1:6379".into());
|
||||
let gcs_addr = args.next().unwrap_or_else(|| "127.0.0.1:6400".into());
|
||||
let raylet_socket = args.next().unwrap_or_else(|| "/tmp/raylet.sock".into());
|
||||
let plasma_socket = args.next().unwrap_or_else(|| "/tmp/plasma.sock".into());
|
||||
let nm_port: u16 = args
|
||||
.next()
|
||||
.and_then(|v| v.parse().ok())
|
||||
.unwrap_or(6379);
|
||||
let node_ip = args.next().unwrap_or_else(|| "127.0.0.1".into());
|
||||
|
||||
let (ip, port) = match addr.rsplit_once(':') {
|
||||
Some((ip, p)) => (ip.to_string(), p.parse::<u16>().unwrap_or(6379)),
|
||||
None => (addr.clone(), 6379),
|
||||
let lang = match args.next().as_deref() {
|
||||
Some("python") => Language::Python,
|
||||
Some("java") => Language::Java,
|
||||
_ => Language::Cpp,
|
||||
};
|
||||
|
||||
println!("连接 Ray GCS: {ip}:{port}(node_ip={node_ip})");
|
||||
let c = match RayCluster::connect(&ip, port, &node_ip) {
|
||||
let cfg = RayNodeConfig {
|
||||
gcs_addr: gcs_addr.clone(),
|
||||
node_ip,
|
||||
raylet_socket,
|
||||
plasma_socket,
|
||||
node_manager_port: nm_port,
|
||||
job_id: 1,
|
||||
language: lang,
|
||||
driver_name: "nax_probe".into(),
|
||||
};
|
||||
|
||||
println!(
|
||||
"接入 Ray 1.0.1:gcs={gcs_addr} raylet={} nm_port={nm_port} lang={lang:?}",
|
||||
cfg.raylet_socket
|
||||
);
|
||||
let c = match RayCluster::connect(&cfg) {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
eprintln!("失败: {e}");
|
||||
@@ -44,7 +64,7 @@ fn main() {
|
||||
}
|
||||
|
||||
println!(
|
||||
"结论: nax 已作为 driver 接入 Ray 集群,node_id={}",
|
||||
"结论: nax 已作为 driver 接入 Ray 集群,raylet 分配的 node_id={}",
|
||||
c.node_id().unwrap_or("<无>")
|
||||
);
|
||||
}
|
||||
+124
-30
@@ -1,27 +1,86 @@
|
||||
//! Ray C++ core 的最小安全封装。
|
||||
//! Ray 1.0.1 的 C++ core(core_worker)最小安全封装。
|
||||
//!
|
||||
//! 只做三件事:连集群、拿本节点身份、探活。任务提交(actor/task)暂不封装——
|
||||
//! nax 的 MPC 走自己的长连接 TCP,不需要 Ray 派任务。
|
||||
//! 只做三件事:连集群、拿本节点身份、探活。任务提交(actor/task)不封装——
|
||||
//! nax 的 MPC 走自己的长连接 TCP,不需要 Ray 派任务,Ray 只在部署期提供
|
||||
//! 「有哪几台、各带什么标签」这份成员目录。
|
||||
//!
|
||||
//! 为什么是 1.0.1 而不是 2.x:只有 1.0.1/1.2.0 有社区编的 armv7 wheel,
|
||||
//! 而 nax 的边缘目标(Zynq-7015 / Cortex-A9)是 32 位 ARM。2.x 的 GCS 从 Redis
|
||||
//! 换成 gRPC,与 1.x 双向不兼容,所以整个集群必须同版本。
|
||||
//!
|
||||
//! 两个必须记住的 ABI 事实(实测,见 docs/RAY_CORE_101.md):
|
||||
//! - x86_64 的 `_raylet.so` 是**旧 ABI**(`_GLIBCXX_USE_CXX11_ABI=0`)
|
||||
//! - armv7 的 `_raylet.so` 是**新 ABI**(默认,423 个 cxx11 符号)
|
||||
//! 同一个 ray 版本、不同架构的 wheel 用了不同编译环境,shim 必须分别编。
|
||||
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::os::raw::{c_char, c_int};
|
||||
|
||||
const BUF: usize = 8192;
|
||||
|
||||
/// 与 `ray/nax_ray_shim_101.cc` 里的 `NaxRayConfig` 逐字段对应(顺序即 ABI)。
|
||||
#[repr(C)]
|
||||
struct RawConfig {
|
||||
gcs_addr: *const c_char,
|
||||
node_ip: *const c_char,
|
||||
raylet_socket: *const c_char,
|
||||
plasma_socket: *const c_char,
|
||||
node_manager_port: c_int,
|
||||
job_id_int: c_int,
|
||||
language: c_int,
|
||||
driver_name: *const c_char,
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
fn nax_ray_init(
|
||||
gcs_ip: *const c_char,
|
||||
gcs_port: c_int,
|
||||
node_ip: *const c_char,
|
||||
out: *mut c_char,
|
||||
out_len: c_int,
|
||||
) -> c_int;
|
||||
fn nax_ray_init(cfg: *const RawConfig, out: *mut c_char, out_len: c_int) -> c_int;
|
||||
fn nax_ray_probe(out: *mut c_char, out_len: c_int) -> c_int;
|
||||
fn nax_ray_shutdown();
|
||||
fn nax_ray_is_initialized() -> c_int;
|
||||
fn nax_ray_last_error() -> *const c_char;
|
||||
}
|
||||
|
||||
/// raylet 只给注册上来的语言开 worker pool。1.0.1 的 raylet 用
|
||||
/// `--cpp_worker_command` 声明支持 CPP,nax 以 CPP 身份注册。
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Language {
|
||||
Python = 0,
|
||||
Java = 1,
|
||||
Cpp = 2,
|
||||
}
|
||||
|
||||
/// 接入一个 1.0.1 节点需要的全部参数。
|
||||
///
|
||||
/// 1.0.1 的 C++ core **不会**自己从 GCS 发现本地 raylet——Python 侧是在
|
||||
/// `services.py` 里把这些 socket 路径算好后传进来的,我们照做。
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RayNodeConfig {
|
||||
/// GCS 地址 `ip:port`。注意 1.0.1 的 CoreWorker 要连的是 **Redis**(默认 6379,
|
||||
/// 我们手工起的集群用 6400),不是 gcs_server 的 gRPC 端口。
|
||||
pub gcs_addr: String,
|
||||
pub node_ip: String,
|
||||
pub raylet_socket: String,
|
||||
pub plasma_socket: String,
|
||||
pub node_manager_port: u16,
|
||||
pub job_id: u32,
|
||||
pub language: Language,
|
||||
pub driver_name: String,
|
||||
}
|
||||
|
||||
impl Default for RayNodeConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
gcs_addr: "127.0.0.1:6400".into(),
|
||||
node_ip: "127.0.0.1".into(),
|
||||
raylet_socket: "/tmp/raylet.sock".into(),
|
||||
plasma_socket: "/tmp/plasma.sock".into(),
|
||||
node_manager_port: 6379,
|
||||
job_id: 1,
|
||||
language: Language::Cpp,
|
||||
driver_name: "nax_driver".into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 把 shim 返回的 `key=value\n` 解析成表。
|
||||
fn parse_kv(s: &str) -> Vec<(String, String)> {
|
||||
s.lines()
|
||||
@@ -32,7 +91,6 @@ fn parse_kv(s: &str) -> Vec<(String, String)> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// 取 shim 侧最近一次错误(线程不安全,只在失败路径用)。
|
||||
fn last_error() -> String {
|
||||
unsafe {
|
||||
let p = nax_ray_last_error();
|
||||
@@ -43,29 +101,37 @@ fn last_error() -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// 一个已接入 Ray 集群的 driver 会话。
|
||||
///
|
||||
/// 语义上等价于 `ray.init()`:进程会在 GCS 注册,并向 raylet 完成握手,
|
||||
/// 从而拿到 raylet 分配的 node id。Drop 时自动 `ray::Shutdown()`。
|
||||
/// 一个已接入 Ray 1.0.1 集群的 driver 会话。Drop 时自动 shutdown。
|
||||
pub struct RayCluster {
|
||||
kv: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
impl RayCluster {
|
||||
/// 接入集群。`gcs_ip:gcs_port` 是 head 节点的 GCS 地址(默认 6379)。
|
||||
pub fn connect(gcs_ip: &str, gcs_port: u16, node_ip: &str) -> Result<Self, String> {
|
||||
let ip = CString::new(gcs_ip).map_err(|e| format!("gcs ip 非法: {e}"))?;
|
||||
let nip = CString::new(node_ip).map_err(|e| format!("node ip 非法: {e}"))?;
|
||||
let mut buf = vec![0u8; BUF];
|
||||
let rc = unsafe {
|
||||
nax_ray_init(
|
||||
ip.as_ptr(),
|
||||
gcs_port as c_int,
|
||||
nip.as_ptr(),
|
||||
buf.as_mut_ptr() as *mut c_char,
|
||||
BUF as c_int,
|
||||
)
|
||||
/// 接入集群。等价于 Python 的 `ray.init(address=...)`。
|
||||
pub fn connect(cfg: &RayNodeConfig) -> Result<Self, String> {
|
||||
// CString 必须在整个调用期间存活,先把它们都建好再取指针。
|
||||
let gcs = CString::new(cfg.gcs_addr.as_str()).map_err(|e| format!("gcs_addr 非法: {e}"))?;
|
||||
let nip = CString::new(cfg.node_ip.as_str()).map_err(|e| format!("node_ip 非法: {e}"))?;
|
||||
let raylet =
|
||||
CString::new(cfg.raylet_socket.as_str()).map_err(|e| format!("raylet socket 非法: {e}"))?;
|
||||
let plasma =
|
||||
CString::new(cfg.plasma_socket.as_str()).map_err(|e| format!("plasma socket 非法: {e}"))?;
|
||||
let name =
|
||||
CString::new(cfg.driver_name.as_str()).map_err(|e| format!("driver_name 非法: {e}"))?;
|
||||
|
||||
let raw = RawConfig {
|
||||
gcs_addr: gcs.as_ptr(),
|
||||
node_ip: nip.as_ptr(),
|
||||
raylet_socket: raylet.as_ptr(),
|
||||
plasma_socket: plasma.as_ptr(),
|
||||
node_manager_port: cfg.node_manager_port as c_int,
|
||||
job_id_int: cfg.job_id as c_int,
|
||||
language: cfg.language as c_int,
|
||||
driver_name: name.as_ptr(),
|
||||
};
|
||||
|
||||
let mut buf = vec![0u8; BUF];
|
||||
let rc = unsafe { nax_ray_init(&raw, buf.as_mut_ptr() as *mut c_char, BUF as c_int) };
|
||||
if rc != 0 {
|
||||
return Err(format!("接入 Ray 失败(rc={rc}): {}", last_error()));
|
||||
}
|
||||
@@ -95,9 +161,10 @@ impl RayCluster {
|
||||
.map(|(_, v)| v.as_str())
|
||||
}
|
||||
|
||||
/// raylet 分配的节点 id(证明握手真的完成了)。
|
||||
/// raylet 分配的节点 id——这是「握手真的完成了」的硬证据,
|
||||
/// 不是本地算出来的。1.0.1 的 shim 从 `CoreWorker::GetRpcAddress()` 取。
|
||||
pub fn node_id(&self) -> Option<&str> {
|
||||
self.get("raylet_assigned_node_id").or_else(|| self.get("node_id"))
|
||||
self.get("rpc_raylet").or_else(|| self.get("node_id"))
|
||||
}
|
||||
pub fn job_id(&self) -> Option<&str> {
|
||||
self.get("job_id")
|
||||
@@ -125,3 +192,30 @@ impl Drop for RayCluster {
|
||||
unsafe { nax_ray_shutdown() }
|
||||
}
|
||||
}
|
||||
|
||||
/// 从环境变量读配置。Ray 部署 nax 时会把这些注入进来,命令行不必带一长串参数。
|
||||
///
|
||||
/// `NAX_RAY_GCS` GCS 的 redis 地址,如 `127.0.0.1:6400`
|
||||
/// `NAX_RAY_NODE_IP` 本机 IP
|
||||
/// `NAX_RAY_RAYLET` 本节点 raylet socket 路径(必填)
|
||||
/// `NAX_RAY_PLASMA` 本节点 plasma socket 路径(必填)
|
||||
/// `NAX_RAY_NM_PORT` raylet 的 node_manager 端口(必填)
|
||||
/// `NAX_RAY_JOB` job id 整数,默认 1
|
||||
pub fn config_from_env(driver_name: &str) -> Result<RayNodeConfig, String> {
|
||||
let need = |k: &str| std::env::var(k).map_err(|_| format!("缺少环境变量 {k}"));
|
||||
Ok(RayNodeConfig {
|
||||
gcs_addr: std::env::var("NAX_RAY_GCS").unwrap_or_else(|_| "127.0.0.1:6400".into()),
|
||||
node_ip: std::env::var("NAX_RAY_NODE_IP").unwrap_or_else(|_| "127.0.0.1".into()),
|
||||
raylet_socket: need("NAX_RAY_RAYLET")?,
|
||||
plasma_socket: need("NAX_RAY_PLASMA")?,
|
||||
node_manager_port: need("NAX_RAY_NM_PORT")?
|
||||
.parse()
|
||||
.map_err(|e| format!("NAX_RAY_NM_PORT 不是数字: {e}"))?,
|
||||
job_id: std::env::var("NAX_RAY_JOB")
|
||||
.ok()
|
||||
.and_then(|v| v.parse().ok())
|
||||
.unwrap_or(1),
|
||||
language: Language::Cpp,
|
||||
driver_name: driver_name.to_string(),
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
# Ray 1.0.1 × nax:跨架构集群 + 跨架构 MPC
|
||||
|
||||
这是 `docs/RAY_CORE.md` 的 1.0.1 姊妹篇。那篇讲的是怎么把 Ray **2.59** 的 C++ core
|
||||
接进 Rust;这篇讲的是**为什么最终用 1.0.1**,以及接进去之后 nax 的 MPC 真的跑起来了。
|
||||
|
||||
结论先放这里:
|
||||
|
||||
```
|
||||
x86_64 侧 Ray node 73bfdc0a… nax site=b MPC 结果 35 ✅
|
||||
armv7 侧 Ray node 235afb22… nax site=a MPC 结果 35 ✅
|
||||
(同一进程既是 Ray driver,又是 MPC 参与方;Ray 只提供成员目录,不进计算路径)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 1. 为什么是 1.0.1
|
||||
|
||||
| | 2.59 | 1.0.1 |
|
||||
|---|---|---|
|
||||
| x86_64 wheel | 有 | 有 |
|
||||
| aarch64 wheel | 有(2.2.0 起) | 无 |
|
||||
| **armv7 wheel** | **无** | **社区编过**(1.0.1 cp36 / 1.2.0 cp38) |
|
||||
| GCS 后端 | gRPC | Redis |
|
||||
| 与另一版本互通 | ✗ | ✗ |
|
||||
|
||||
Zynq-7015 是 Cortex-A9(ARMv7-A,32 位),只有 1.0.1/1.2.0 有可用二进制。
|
||||
而 1.0.1 与 2.59 **双向不通**(实测:1.0.1 raylet 连 2.59 的 6379 报
|
||||
`Protocol error, got "\x00"`,因为 2.0 起 6379 从 RESP 换成了 gRPC/HTTP2)。
|
||||
|
||||
所以要么整集群 2.x(armv7 进不来),要么整集群 1.0.1。选了后者。
|
||||
|
||||
---
|
||||
|
||||
## 2. 和 2.59 版的六个接口差异
|
||||
|
||||
`ray/nax_ray_shim_101.cc` 是 1.0.1 版,对比 2.59 版(`ray/nax_ray_shim.cc`):
|
||||
|
||||
| 项 | 2.59 | 1.0.1 |
|
||||
|---|---|---|
|
||||
| `CoreWorkerProcess` 头文件 | `core_worker/core_worker_process.h` | 就在 `core_worker/core_worker.h` 里 |
|
||||
| `TaskExecutionCallback` | 22 个参数 | **8 个参数** |
|
||||
| `GcsClientOptions` | `(ip, port, ClusterID, allow_nil, fetch)` | `(ip, port, password, is_test)` 位置参数 |
|
||||
| 取 raylet socket | `GlobalStateAccessor::GetNodeToConnectForDriver()` | **没有**,必须调用方给(Python 侧也是在 `_raylet.pyx` 里算好传进来的) |
|
||||
| 取 job id | `GetNextJobID()` | **没有**,`JobID::FromInt(n)` 自己给 |
|
||||
| 命名空间 | `ray::core::CoreWorker` | `ray::CoreWorker`(没有 `core` 这一层) |
|
||||
| `GcsNodeInfo` 字段 | 1..5 含 node_manager_port | 1..4 + `state=7`,**无 port** |
|
||||
|
||||
两个直接踩到的坑:
|
||||
|
||||
1. **`options.num_workers = 1` 必须显式设**。1.0.1 的 `CoreWorker` 构造函数里有
|
||||
`RAY_CHECK(options_.num_workers > 0)`,默认 0 会直接 abort。
|
||||
2. **`gcs_options` 要指向 Redis,不是 gcs_server 的 gRPC 端口**。1.0.1 的
|
||||
CoreWorker 内部建的是 `ServiceBasedGcsClient`,但它同时要连 Redis 拿表。
|
||||
指向 6402 会得到 `redis_client.cc:114 Check failed: Protocol error, got "\x00"`。
|
||||
正确值是 Redis 主节点(本仓库的混合集群是 6400)。
|
||||
|
||||
---
|
||||
|
||||
## 3. 两个 ABI 事实(最容易翻车的地方)
|
||||
|
||||
同一个 ray 1.0.1,两个架构的 wheel 用了**不同的 std::string ABI**:
|
||||
|
||||
```
|
||||
x86_64 ray-1.0.1-...-manylinux1_x86_64.whl → nm -D | grep -c cxx11 = 0 (旧 ABI)
|
||||
armv7 ray-1.0.1-...-linux_armv7l.whl → nm -D | grep -c cxx11 = 423 (新 ABI)
|
||||
```
|
||||
|
||||
所以 shim 必须分别编译:
|
||||
|
||||
```bash
|
||||
# x86_64
|
||||
g++ ... -D_GLIBCXX_USE_CXX11_ABI=0 ray/build101.sh
|
||||
# armv7
|
||||
arm-linux-gnueabihf-g++ ... ray/build101_armv7.sh # 不加那个宏
|
||||
```
|
||||
|
||||
搞错的表现不是链接错误,而是**运行期 `basic_string::_M_create` 异常**——
|
||||
`CoreWorkerOptions.gcs_options.server_ip_` 传过去后长度字段错位,`std::string`
|
||||
认为长度是个天文数字。这个错误信息完全不提 ABI,很容易往内存越界上查。
|
||||
|
||||
---
|
||||
|
||||
## 4. Python 符号:8 个 stub + 一份 libpython
|
||||
|
||||
`_raylet.so` 本质是 CPython 扩展。x86 版引用 203 个 `Py*` 未定义符号,
|
||||
armv7 版 201 个。解法是链上 libpython(`--no-as-needed`,否则被 as-needed 丢掉),
|
||||
剩下的差集由 shim 自己定义占位:
|
||||
|
||||
| 符号 | 为什么缺 |
|
||||
|---|---|
|
||||
| `_Py_CheckRecursionLimit` | 3.12 移除的内部变量 |
|
||||
| `_Py_tracemalloc_config` | 同上 |
|
||||
| `_PyTraceMalloc_NewReference` | 同上 |
|
||||
| `PyCode_New` | 3.12 换成 `PyCode_NewWithPosOnlyArgs` |
|
||||
| `PyUnicode_AsUnicode` / `PyUnicode_FromUnicode` | 3.3 起弃用,3.12 删除 |
|
||||
| `_PyUnicode_Ready` | 同上 |
|
||||
| `_PyGen_Send` | 3.11 起不再导出 |
|
||||
|
||||
armv7 侧只要前两个(`_PyGen_Send` 和 `_Py_CheckRecursionLimit`),
|
||||
因为 armhf 的 libpython3.11 把其余的都提供了。
|
||||
|
||||
**安全性**:这些符号只在「真的执行 Python 代码」时才被调用,而 nax 只把 Ray
|
||||
当成员目录,从不调用 Ray 的 Python 路径,所以零值占位不会被执行。
|
||||
|
||||
---
|
||||
|
||||
## 5. 编译
|
||||
|
||||
依赖(Debian 12,apt 源换 USTC 后可用):
|
||||
|
||||
```bash
|
||||
apt install g++ protobuf-compiler libprotobuf-dev libgrpc++-dev \
|
||||
protobuf-compiler-grpc libabsl-dev libboost-dev libssl-dev \
|
||||
libflatbuffers-dev flatbuffers-compiler
|
||||
# armv7 交叉
|
||||
apt install g++-arm-linux-gnueabihf libatomic1:armhf libpython3.11:armhf
|
||||
```
|
||||
|
||||
```bash
|
||||
# 1) x86_64 shim(链 manylinux1_x86_64 wheel 里的 _raylet.so)
|
||||
RAYSO=/path/r17x/ray-1.0.1.data/purelib/ray/_raylet.so bash ray/build101.sh
|
||||
# 2) armv7 shim(链 armv7l wheel 里的 _raylet.so)
|
||||
bash ray/build101_armv7.sh
|
||||
|
||||
# 3) nax 带 Ray(可选 feature,默认构建仍是纯静态单二进制)
|
||||
cargo build --release -p nax-cli --features ray # x86
|
||||
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \
|
||||
NAX_RAY_LIB_NAME=nax_ray_armv7 \
|
||||
NAX_RAY_LIBPYTHON=/usr/lib/arm-linux-gnueabihf/libpython3.11.so.1.0 \
|
||||
cargo build --release -p nax-cli --features ray \
|
||||
--target armv7-unknown-linux-gnueabihf
|
||||
```
|
||||
|
||||
`build101.sh` 会自动打两个补丁(都打在解出来的头文件上,不动 ray 源码):
|
||||
|
||||
- `rpc/client_call.h`:`std::vector<grpc::CompletionQueue>` → `std::deque`。
|
||||
grpc 1.51 删掉了 CompletionQueue 的移动构造,`reserve` + `emplace_back` 编不过。
|
||||
- 影子头 `arrow/buffer.h`:1.0.1 只有 `PlasmaBuffer` 用 `shared_ptr<arrow::Buffer>`,
|
||||
nax 不实例化它,给个最小声明即可(省掉整个 Arrow 依赖)。
|
||||
- 宏 `-Dgrpc_impl=grpc`:1.0.1 用的是旧 grpc 命名空间,1.51 已并入 `grpc`。
|
||||
|
||||
---
|
||||
|
||||
## 6. 运行:nax 自己接入 Ray
|
||||
|
||||
不需要额外进程。`nax node` 看到 `NAX_RAY_RAYLET` 就会先注册成 Ray driver:
|
||||
|
||||
```bash
|
||||
export NAX_RAY_GCS=127.0.0.1:6400 # Redis 主节点,不是 gcs_server
|
||||
export NAX_RAY_RAYLET=/tmp/raylet_a.sock
|
||||
export NAX_RAY_PLASMA=/tmp/plasma_a.sock
|
||||
export NAX_RAY_NM_PORT=6413
|
||||
nax node --site a --sites a,b --connect 127.0.0.1:9103 --data 1,2,3
|
||||
```
|
||||
|
||||
输出(armv7 侧,qemu 承载):
|
||||
|
||||
```
|
||||
接入 Ray 集群: gcs=127.0.0.1:6400 raylet=/tmp/raylet_a.sock nm_port=6413
|
||||
Ray 节点已确认: node_id=235afb22db57c7249f4862ce9de95f92cffdd16c(由 raylet 分配)
|
||||
Ray worker_id=01000000ffffffffffffffffffffffffffffffff
|
||||
连接对端...
|
||||
nax node · site=a · 2 方 · 3 个元素 · fxp=18
|
||||
分片交换完成(2 方)
|
||||
密文乘法完成(1 次)
|
||||
还原完成: [9175040]
|
||||
|
||||
会话结果: 35
|
||||
```
|
||||
|
||||
那个 node_id 是 raylet 在握手时分配的(`CoreWorker::GetRpcAddress().raylet_id()`),
|
||||
两端拿到的是**不同**的值——这正是「两个进程真的挂在两个不同节点上」的证据。
|
||||
|
||||
`(1·4+1)+(2·5+1)+(3·6+1) = 35`,与 `nax-node::run_session` 的语义
|
||||
`z = (x₁·x₂·…·xₙ + 1).sum()` 一致。
|
||||
|
||||
---
|
||||
|
||||
## 7. 已知限制
|
||||
|
||||
| 限制 | 说明 |
|
||||
|---|---|
|
||||
| 拿不到节点列表 | 1.0.1 的 `_raylet.so` 只导出了 `GlobalStateAccessor` 的 3 个方法(`GetActorInfo` / `GetActorCheckpointId` / `GetObjectInfo`),**没有 `GetAllNodeInfo`**。要列节点用 `ray/armv7/decode_gcs.py` 直读 Redis 分片,或改走 gRPC 直连 gcs_server。 |
|
||||
| 成员变更只能看日志 | driver 内部订阅了节点表(日志里 `Received notification for node id = …, IsAlive = 1`),但没暴露回调给 C ABI。要结构化输出得改 shim 另开一条通道。 |
|
||||
| 二进制不再自包含 | 开 `--features ray` 后动态依赖 `libnax_ray.so` + `libpython`。**默认构建不受影响**,仍是 700KB 级静态单二进制。 |
|
||||
| 两端 worker_id 相同 | 两个进程都声明 `job_id=1`,driver worker id 由 job 派生,所以都是 `01000000ffff…`。要区分就设 `NAX_RAY_JOB`。 |
|
||||
|
||||
---
|
||||
|
||||
## 8. 复现
|
||||
|
||||
```bash
|
||||
# 起 x86_64 原生 + armv7(qemu) 混合 1.0.1 集群(redis/gcs/plasma/raylet ×2)
|
||||
bash ray/armv7/mixed_cluster.sh
|
||||
|
||||
# 闭环:两端各自注册成 Ray driver,然后跑跨架构 MPC
|
||||
bash ray/armv7/mpc_ray.sh
|
||||
```
|
||||
|
||||
`mixed_cluster.sh` 会清理上一轮的全套进程(redis 和 gcs_server 会占着 6400/6402,
|
||||
只杀 raylet 会导致「新进程起不来但端口探测仍通过」的假成功)。
|
||||
|
||||
## 9. 与 2.59 的关系
|
||||
|
||||
`ray/build.sh` + `ray/nax_ray_shim.cc` 那一套仍然可用,用来在纯 x86 集群上验证
|
||||
「nax 能接 Ray 的 C++ core」。但**边缘目标只能用 1.0.1**,而两版本不能混布,
|
||||
所以生产形态是:整集群 1.0.1。2.59 那条线留作对照与未来 2.x 支持 32 位 ARM 时的参考。
|
||||
@@ -8,7 +8,17 @@ AD=$A/core/src/ray
|
||||
MODX=$XD/gcs/redis_module/libray_redis_module.so
|
||||
MODA=$AD/gcs/redis_module/libray_redis_module.so
|
||||
|
||||
pkill -f qemu-arm-static 2>/dev/null; pkill -f 'r17x.*raylet' 2>/dev/null; sleep 1
|
||||
# 清理上一轮的全部进程(redis / gcs / plasma / raylet,含 qemu 包着的 armv7 侧)。
|
||||
# 只杀 raylet 不够:redis 和 gcs_server 会占着 6400/6402,新进程起不来但 socket 探测仍通过。
|
||||
pkill -f '/tmp/r17' 2>/dev/null
|
||||
pkill -f qemu-arm-static 2>/dev/null
|
||||
sleep 2
|
||||
for p in 6400 6401 6402 6403 6413; do
|
||||
for _ in $(seq 1 20); do
|
||||
timeout 1 bash -c "echo > /dev/tcp/127.0.0.1/$p" 2>/dev/null || break
|
||||
sleep 0.3
|
||||
done
|
||||
done
|
||||
rm -rf /tmp/plasmadir_x /tmp/plasmadir_a /tmp/plasma_x.sock /tmp/plasma_a.sock \
|
||||
/tmp/raylet_x.sock /tmp/raylet_a.sock /tmp/mc_sess_x /tmp/mc_sess_a
|
||||
mkdir -p /tmp/plasmadir_x /tmp/plasmadir_a /tmp/mc_sess_x /tmp/mc_sess_a
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
# 完整闭环:跨架构 Ray 1.0.1 集群 + 两端 nax 各自注册成 driver + 跨架构 MPC
|
||||
# x86_64 侧:site=b,Ray 节点 73bfdc0a(raylet_x)
|
||||
# armv7 侧:site=a,Ray 节点 235afb22(raylet_a,qemu 承载)
|
||||
# 期望结果:(1*4+1)+(2*5+1)+(3*6+1) = 35
|
||||
set -u
|
||||
PORT=${PORT:-9103}
|
||||
SEED=0000000000000001000000000000000000000000000000000000000000000000
|
||||
XNAX=/root/.cache/cargo-target/release/nax
|
||||
ANAX=/root/.cache/cargo-target/armv7-unknown-linux-gnueabihf/release/nax
|
||||
|
||||
echo "=== 1) x86_64 侧:Ray driver + 等对端"
|
||||
NAX_RAY_GCS=127.0.0.1:6400 NAX_RAY_NODE_IP=127.0.0.1 \
|
||||
NAX_RAY_RAYLET=/tmp/raylet_x.sock NAX_RAY_PLASMA=/tmp/plasma_x.sock NAX_RAY_NM_PORT=6403 \
|
||||
$XNAX node --site b --sites a,b --listen 127.0.0.1:$PORT \
|
||||
--data 4,5,6 --seed $SEED > /tmp/ray_mpc_b.log 2>&1 &
|
||||
BPID=$!
|
||||
sleep 2
|
||||
|
||||
echo "=== 2) armv7 侧:Ray driver + 连对端(qemu)"
|
||||
NAX_RAY_GCS=127.0.0.1:6400 NAX_RAY_NODE_IP=127.0.0.1 \
|
||||
NAX_RAY_RAYLET=/tmp/raylet_a.sock NAX_RAY_PLASMA=/tmp/plasma_a.sock NAX_RAY_NM_PORT=6413 \
|
||||
timeout 180 qemu-arm-static $ANAX node --site a --sites a,b \
|
||||
--connect 127.0.0.1:$PORT --data 1,2,3 --seed $SEED > /tmp/ray_mpc_a.log 2>&1
|
||||
ARC=$?
|
||||
wait $BPID 2>/dev/null
|
||||
BRC=$?
|
||||
|
||||
# 过滤 ray 的 INFO 噪音,只留 nax 自己的输出
|
||||
clean() { grep -vE 'WARN NetworkGuard|WARN FileGuard|UserWarning|service_based_accessor|core_worker.cc|grpc_server.cc|io_service_pool|redis_client' "$1"; }
|
||||
|
||||
echo
|
||||
echo "--- armv7 侧 nax(rc=$ARC)"
|
||||
clean /tmp/ray_mpc_a.log
|
||||
echo "--- x86_64 侧 nax(rc=$BRC)"
|
||||
clean /tmp/ray_mpc_b.log
|
||||
@@ -0,0 +1,91 @@
|
||||
#!/bin/bash
|
||||
# 把 Ray 1.0.1 的 C++ core 编成 libnax_ray.so(x86_64 原生版)。
|
||||
# 与 2.59 版(ray/build.sh)同一思路:不碰 bazel,直接链 wheel 里的 _raylet.so。
|
||||
set -o pipefail
|
||||
set -u
|
||||
|
||||
CACHE=/tmp
|
||||
OUT_DIR=${OUT_DIR:-/tmp}
|
||||
RAYSO=${RAYSO:-/tmp/r17x/ray-1.0.1.data/purelib/ray/_raylet.so}
|
||||
HDR=/tmp/r101hdr
|
||||
GEN=/tmp/gen101
|
||||
SHIM=/tmp/shiminc101
|
||||
|
||||
echo "== ray 1.0.1 -> $OUT_DIR/libnax_ray.so"
|
||||
echo " _raylet.so: $RAYSO"
|
||||
[ -f "$RAYSO" ] || { echo "缺 _raylet.so"; exit 1; }
|
||||
|
||||
rm -rf "$HDR" "$GEN" "$SHIM"
|
||||
mkdir -p "$HDR" "$GEN" "$SHIM"
|
||||
tar xzf /tmp/r101hdr.tgz -C "$HDR"
|
||||
echo " 头文件: $(find "$HDR" -name '*.h' | wc -l) 个"
|
||||
|
||||
cd "$HDR"
|
||||
# reporter.proto 依赖 opencensus-proto(bazel 里才有),nax 用不到
|
||||
PROTOS=$(find src/ray/protobuf -name '*.proto' | grep -v reporter.proto)
|
||||
protoc -I. --cpp_out="$GEN" --grpc_out="$GEN" \
|
||||
--plugin=protoc-gen-grpc="$(which grpc_cpp_plugin)" $PROTOS 2>&1 | grep -v "unused" | tail -3
|
||||
echo " pb.h: $(ls "$GEN"/src/ray/protobuf/*.pb.h 2>/dev/null | wc -l) 个"
|
||||
|
||||
for f in $(find src -name '*.fbs'); do
|
||||
flatc --cpp --scoped-enums -o "$(dirname "$f")" "$f" || exit 1
|
||||
done
|
||||
echo " flatbuffers: $(find src -name '*_generated.h' | wc -l) 个"
|
||||
|
||||
|
||||
# --- 补丁:grpc 1.51 把 CompletionQueue 的移动构造删了,ray 1.0.1 用
|
||||
# std::vector<CompletionQueue>+reserve 才能 emplace_back。换成 deque 即可原地构造。
|
||||
python3 - <<'PYEOF'
|
||||
import re
|
||||
p = "/tmp/r101hdr/src/ray/rpc/client_call.h"
|
||||
s = open(p).read()
|
||||
s = s.replace(" cqs_.reserve(num_threads_);\n", "")
|
||||
s = s.replace("std::vector<grpc::CompletionQueue> cqs_;",
|
||||
"std::deque<grpc::CompletionQueue> cqs_;")
|
||||
if "#include <deque>" not in s:
|
||||
s = s.replace("#include <vector>", "#include <deque>\n#include <vector>", 1)
|
||||
open(p, "w").write(s)
|
||||
print(" patched client_call.h:", "std::deque<grpc::CompletionQueue> cqs_;" in s)
|
||||
PYEOF
|
||||
|
||||
# 影子头 (a):arrow/buffer.h —— 1.0.1 里只有 PlasmaBuffer 用 std::shared_ptr<arrow::Buffer>,
|
||||
# nax 不实例化 PlasmaBuffer(任务体不在 Ray 里跑),给个最小声明即可。
|
||||
mkdir -p "$SHIM/arrow"
|
||||
cat > "$SHIM/arrow/buffer.h" <<'EOF'
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
namespace arrow {
|
||||
class Buffer {
|
||||
public:
|
||||
Buffer() = default;
|
||||
virtual ~Buffer() = default;
|
||||
virtual const uint8_t *data() const { return nullptr; }
|
||||
virtual int64_t size() const { return 0; }
|
||||
virtual bool is_mutable() const { return false; }
|
||||
};
|
||||
}
|
||||
EOF
|
||||
|
||||
|
||||
# 关键宏:
|
||||
# _GLIBCXX_USE_CXX11_ABI=0 ray 1.0.1 也是旧 ABI(符号里没有 B5cxx11)
|
||||
# ABSL_* absl::optional 走 std::optional
|
||||
rm -f "$OUT_DIR/libnax_ray.so"
|
||||
g++ -std=c++17 -O2 -fPIC -shared \
|
||||
-D_GLIBCXX_USE_CXX11_ABI=0 \
|
||||
-DABSL_USES_STD_OPTIONAL=1 -DABSL_OPTION_USE_STD_OPTIONAL=1 \
|
||||
-Dgrpc_impl=grpc \
|
||||
-o "$OUT_DIR/libnax_ray.so" /tmp/naxray/nax_ray_shim_101.cc \
|
||||
-I"$SHIM" -I"$HDR" -I"$HDR/src" -I"$GEN" \
|
||||
"$RAYSO" \
|
||||
-labsl_synchronization -labsl_time -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal \
|
||||
-Wl,--no-as-needed -L/usr/local/lib -lpython3.12 -Wl,-rpath,/usr/local/lib \
|
||||
2>/tmp/b101.log
|
||||
|
||||
echo " errors: $(grep -c 'error:' /tmp/b101.log)"
|
||||
if [ -f "$OUT_DIR/libnax_ray.so" ]; then
|
||||
echo "== 成功: $OUT_DIR/libnax_ray.so ($(du -h "$OUT_DIR/libnax_ray.so" | cut -f1))"
|
||||
else
|
||||
echo "== 失败"; exit 1
|
||||
fi
|
||||
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
# 交叉编译 1.0.1 shim 到 armv7(链接 armv7 版 _raylet.so)。
|
||||
# 头文件与 proto 生成代码与架构无关,直接复用 x86 那套。
|
||||
set -o pipefail
|
||||
set -u
|
||||
|
||||
CXX=arm-linux-gnueabihf-g++
|
||||
HDR=/tmp/r101hdr
|
||||
GEN=/tmp/gen101
|
||||
SHIM=/tmp/shiminc101
|
||||
# armv7 版的 _raylet.so(社区 armv7l wheel 里带的那份)
|
||||
RAYSO=/tmp/r17/ray-1.0.1.data/purelib/ray/_raylet.so
|
||||
OUT=/tmp/libnax_ray_armv7.so
|
||||
|
||||
echo "== armv7 shim"
|
||||
echo " _raylet.so: $(file -b $RAYSO | cut -c1-60)"
|
||||
[ -f "$RAYSO" ] || { echo "缺 armv7 _raylet.so"; exit 1; }
|
||||
|
||||
rm -f "$OUT"
|
||||
# 注意:armv7 版 _raylet.so 是**新 ABI**(423 个 cxx11 符号),x86 版是旧 ABI(0 个)。
|
||||
# 同一个 ray 版本,两个架构的 wheel 用不同编译环境,必须分别对齐。
|
||||
$CXX -std=c++17 -O2 -fPIC -shared \
|
||||
-DABSL_USES_STD_OPTIONAL=1 -DABSL_OPTION_USE_STD_OPTIONAL=1 \
|
||||
-Dgrpc_impl=grpc \
|
||||
-o "$OUT" /tmp/naxray/nax_ray_shim_101.cc \
|
||||
-I"$SHIM" -I"$HDR" -I"$HDR/src" -I"$GEN" \
|
||||
"$RAYSO" -latomic \
|
||||
-Wl,--no-as-needed /usr/lib/arm-linux-gnueabihf/libpython3.11.so.1.0 \
|
||||
-Wl,-rpath,/usr/lib/arm-linux-gnueabihf \
|
||||
2>/tmp/b101arm.log
|
||||
|
||||
echo " errors: $(grep -c 'error:' /tmp/b101arm.log 2>/dev/null || echo 0)"
|
||||
if [ -f "$OUT" ]; then
|
||||
echo "== shim ok: $(file -b $OUT | cut -c1-70) $(du -h $OUT | cut -f1)"
|
||||
else
|
||||
echo "== shim 失败"; grep -E 'error:|undefined reference' /tmp/b101arm.log | head -10; exit 1
|
||||
fi
|
||||
|
||||
# 测试程序
|
||||
# 测试程序是 C,用 gcc 编(用 g++ 会把符号按 C++ 名字修饰,链不上)
|
||||
arm-linux-gnueabihf-gcc -O1 -o /tmp/naxray_arm7 /tmp/naxray/test101_arm.c \
|
||||
-L/tmp -lnax_ray_armv7 -Wl,-rpath,/tmp -lstdc++ -Wl,--allow-shlib-undefined \
|
||||
2>/tmp/testarm.log
|
||||
if [ -f /tmp/naxray_arm7 ]; then
|
||||
echo "== tester ok: $(file -b /tmp/naxray_arm7 | cut -c1-70)"
|
||||
else
|
||||
echo "== tester 失败"; grep -E 'error:|undefined' /tmp/testarm.log | head -10; exit 1
|
||||
fi
|
||||
@@ -0,0 +1,264 @@
|
||||
// nax_ray_shim_101.cc —— Ray 1.0.1 的 C++ core(core_worker)C ABI 封装,给 nax 的 Rust 侧用。
|
||||
//
|
||||
// 与 2.59 版的差别(都是实测出来的,不是猜的):
|
||||
// - CoreWorkerOptions 字段少:无 interactive / job_config / task_execution_callback
|
||||
// 的 22 参数版本,1.0.1 的回调只有 8 个参数
|
||||
// - 没有 CoreWorkerProcess 独立头文件,CoreWorkerProcess 就在 core_worker.h 里
|
||||
// - GcsClientOptions(ip, port, password, is_test) 是位置参数
|
||||
// - 没有 GetNodeToConnectForDriver / GetNextJobID,driver 的 socket 与 job_id
|
||||
// 必须由调用方给(Python 侧也是这么做的,见 python/ray/_raylet.pyx:723-741)
|
||||
// - GcsNodeInfo 没有 node_manager_port,多一个 state(7)
|
||||
//
|
||||
// 为什么 1.0.1:armv7 只有 1.0.1/1.2.0 的社区 wheel,2.59 在 32 位 ARM 上不存在。
|
||||
// 两端对齐到 1.0.1,x86 与 armv7 才能进同一个集群。
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "ray/common/id.h"
|
||||
#include "ray/common/ray_object.h"
|
||||
#include "ray/common/status.h"
|
||||
#include "ray/core_worker/common.h"
|
||||
#include "ray/core_worker/core_worker.h"
|
||||
#include "ray/gcs/gcs_client.h"
|
||||
|
||||
using namespace ray; // 1.0.1 没有 ray::core 命名空间,CoreWorker 直接在 ray 下
|
||||
|
||||
namespace {
|
||||
|
||||
std::string g_err;
|
||||
bool g_inited = false;
|
||||
|
||||
std::string HexOf(const std::string &raw) {
|
||||
static const char *d = "0123456789abcdef";
|
||||
std::string out;
|
||||
out.reserve(raw.size() * 2);
|
||||
for (unsigned char c : raw) {
|
||||
out.push_back(d[c >> 4]);
|
||||
out.push_back(d[c & 0xf]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// GcsNodeInfo 的手工解析(1.0.1 字段编号:1=node_id 2=addr 3=raylet 4=plasma 7=state)。
|
||||
// 不用 protobuf 的原因同 2.59 版:ray 用旧 ABI(_GLIBCXX_USE_CXX11_ABI=0),
|
||||
// 系统 libprotobuf 是 cxx11 ABI,同一个 TU 里混不了。
|
||||
namespace wire {
|
||||
|
||||
bool ReadVarint(const std::string &b, size_t *i, uint64_t *out) {
|
||||
uint64_t v = 0;
|
||||
int shift = 0;
|
||||
while (*i < b.size() && shift < 64) {
|
||||
unsigned char c = static_cast<unsigned char>(b[(*i)++]);
|
||||
v |= static_cast<uint64_t>(c & 0x7f) << shift;
|
||||
if (!(c & 0x80)) {
|
||||
*out = v;
|
||||
return true;
|
||||
}
|
||||
shift += 7;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
struct NodeInfo {
|
||||
std::string node_id;
|
||||
std::string node_manager_address;
|
||||
std::string raylet_socket_name;
|
||||
std::string object_store_socket_name;
|
||||
int32_t state = 0;
|
||||
};
|
||||
|
||||
NodeInfo ParseGcsNodeInfo(const std::string &b) {
|
||||
NodeInfo out;
|
||||
size_t i = 0;
|
||||
while (i < b.size()) {
|
||||
uint64_t key = 0;
|
||||
if (!ReadVarint(b, &i, &key)) break;
|
||||
const int field = static_cast<int>(key >> 3);
|
||||
const int wt = static_cast<int>(key & 7);
|
||||
if (wt == 0) {
|
||||
uint64_t v = 0;
|
||||
if (!ReadVarint(b, &i, &v)) break;
|
||||
if (field == 7) out.state = static_cast<int32_t>(v);
|
||||
} else if (wt == 2) {
|
||||
uint64_t len = 0;
|
||||
if (!ReadVarint(b, &i, &len)) break;
|
||||
if (i + len > b.size()) break;
|
||||
std::string v = b.substr(i, static_cast<size_t>(len));
|
||||
i += static_cast<size_t>(len);
|
||||
switch (field) {
|
||||
case 1: out.node_id = v; break;
|
||||
case 2: out.node_manager_address = v; break;
|
||||
case 3: out.raylet_socket_name = v; break;
|
||||
case 4: out.object_store_socket_name = v; break;
|
||||
default: break;
|
||||
}
|
||||
} else if (wt == 5) {
|
||||
i += 4;
|
||||
} else if (wt == 1) {
|
||||
i += 8;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace wire
|
||||
|
||||
// 1.0.1 的回调只有 8 个参数(2.59 是 22 个)。
|
||||
CoreWorkerOptions::TaskExecutionCallback MakeNoopCallback() {
|
||||
return [](TaskType,
|
||||
const std::string,
|
||||
const RayFunction &,
|
||||
const std::unordered_map<std::string, double> &,
|
||||
const std::vector<std::shared_ptr<RayObject>> &,
|
||||
const std::vector<ObjectID> &,
|
||||
const std::vector<ObjectID> &,
|
||||
std::vector<std::shared_ptr<RayObject>> *) {
|
||||
// nax 只借 Ray 做成员目录与放置,任务体在 nax 自己的帧里跑。
|
||||
return Status::OK();
|
||||
};
|
||||
}
|
||||
|
||||
void WriteOut(char *out, int out_len, const std::string &s) {
|
||||
if (!out || out_len <= 0) return;
|
||||
std::snprintf(out, static_cast<size_t>(out_len), "%s", s.c_str());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// 配置结构体,避免 C ABI 上传 8 个裸参数。字段顺序即 ABI,Rust 侧必须一一对应。
|
||||
struct NaxRayConfig {
|
||||
const char *gcs_addr; // "127.0.0.1:6402"
|
||||
const char *node_ip; // 本节点 IP
|
||||
const char *raylet_socket; // 本节点 raylet socket 路径
|
||||
const char *plasma_socket; // 本节点 plasma socket 路径
|
||||
int node_manager_port; // 本节点 raylet 的 node_manager 端口
|
||||
int job_id_int; // JobID::FromInt 的值
|
||||
int language; // 0=PYTHON 1=JAVA 2=CPP
|
||||
const char *driver_name;
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
|
||||
// ray 1.0.1 的 _raylet.so 是 cp38 的 CPython 扩展,引用了 8 个 3.8 时代、3.12 已移除的符号。
|
||||
// nax 不执行任何 Python 代码(Ray 只用成员目录与放置),这些符号只服务于加载期重定位,
|
||||
// 给零值占位即可。清单由 nm 差集算出:203 个 Py* 未定义符号 − libpython3.12 的 1734 个导出。
|
||||
int _Py_CheckRecursionLimit = 1500; // 递归深度阈值,给个正常值防止除零
|
||||
void *PyCode_New;
|
||||
void *PyUnicode_AsUnicode;
|
||||
void *PyUnicode_FromUnicode;
|
||||
void *_PyGen_Send;
|
||||
void *_PyTraceMalloc_NewReference;
|
||||
void *_PyUnicode_Ready;
|
||||
void *_Py_tracemalloc_config;
|
||||
|
||||
// 初始化 core worker。返回 0 成功。
|
||||
int nax_ray_init(const NaxRayConfig *cfg, char *out, int out_len) {
|
||||
try {
|
||||
if (!cfg || !cfg->gcs_addr) {
|
||||
g_err = "cfg 为空";
|
||||
return -1;
|
||||
}
|
||||
if (CoreWorkerProcess::IsInitialized()) {
|
||||
WriteOut(out, out_len, "already=1\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// gcs_addr 拆成 ip / port。1.0.1 的 GcsClientOptions 要分开传。
|
||||
const std::string addr = cfg->gcs_addr;
|
||||
const auto pos = addr.rfind(':');
|
||||
if (pos == std::string::npos) {
|
||||
g_err = "gcs_addr 需要 ip:port 形式,收到: " + addr;
|
||||
return -1;
|
||||
}
|
||||
const std::string gcs_ip = addr.substr(0, pos);
|
||||
const int gcs_port = std::atoi(addr.c_str() + pos + 1);
|
||||
|
||||
const std::string nip = cfg->node_ip ? cfg->node_ip : "";
|
||||
|
||||
CoreWorkerOptions options;
|
||||
options.worker_type = WorkerType::DRIVER;
|
||||
options.language = static_cast<Language>(cfg->language);
|
||||
options.store_socket = cfg->plasma_socket ? cfg->plasma_socket : "";
|
||||
options.raylet_socket = cfg->raylet_socket ? cfg->raylet_socket : "";
|
||||
options.job_id = JobID::FromInt(static_cast<uint32_t>(cfg->job_id_int));
|
||||
options.gcs_options = gcs::GcsClientOptions(gcs_ip, gcs_port, "", false);
|
||||
options.enable_logging = false;
|
||||
options.install_failure_signal_handler = false;
|
||||
options.node_ip_address = nip;
|
||||
options.node_manager_port = cfg->node_manager_port;
|
||||
options.raylet_ip_address = nip;
|
||||
options.driver_name = cfg->driver_name ? cfg->driver_name : "nax_driver";
|
||||
// 1.0.1 的 CoreWorker 构造里 RAY_CHECK(options_.num_workers > 0),默认 0 会 abort。
|
||||
// driver 只跑一个 core worker(Python driver 也是 1)。
|
||||
options.num_workers = 1;
|
||||
options.task_execution_callback = MakeNoopCallback();
|
||||
|
||||
CoreWorkerProcess::Initialize(options);
|
||||
g_inited = true;
|
||||
|
||||
char buf[256];
|
||||
std::string kv;
|
||||
kv += "job_id=" + options.job_id.Hex() + "\n";
|
||||
kv += "raylet_socket=" + options.raylet_socket + "\n";
|
||||
kv += "plasma_socket=" + options.store_socket + "\n";
|
||||
std::snprintf(buf, sizeof buf, "node_manager_port=%d\n", options.node_manager_port);
|
||||
kv += buf;
|
||||
// 下面两个只有真跟 raylet 握手成功才拿得到,是「连上了」的硬证据。
|
||||
auto &worker = CoreWorkerProcess::GetCoreWorker();
|
||||
kv += "worker_id=" + worker.GetWorkerID().Hex() + "\n";
|
||||
// 这三行是布局探针:Ray 用 protobuf 3.8 生成的头,我们用 protoc 3.21 生成的,
|
||||
// 若 rpc::Address 的内存布局有差异,读出来就会错位。
|
||||
const auto &rpc_addr = worker.GetRpcAddress();
|
||||
kv += "rpc_ip=" + rpc_addr.ip_address() + "\n";
|
||||
kv += "rpc_port=" + std::to_string(rpc_addr.port()) + "\n";
|
||||
kv += "rpc_raylet=" + HexOf(rpc_addr.raylet_id()) + "\n";
|
||||
WriteOut(out, out_len, kv);
|
||||
return 0;
|
||||
} catch (const std::exception &e) {
|
||||
g_err = std::string("异常: ") + e.what();
|
||||
return -9;
|
||||
} catch (...) {
|
||||
g_err = "未知异常";
|
||||
return -9;
|
||||
}
|
||||
}
|
||||
|
||||
const char *nax_ray_last_error(void) { return g_err.c_str(); }
|
||||
|
||||
int nax_ray_is_initialized(void) {
|
||||
return (g_inited || CoreWorkerProcess::IsInitialized()) ? 1 : 0;
|
||||
}
|
||||
|
||||
// 再问一次本进程的身份,证明与 raylet 的会话还活着。
|
||||
int nax_ray_probe(char *out, int out_len) {
|
||||
try {
|
||||
if (!CoreWorkerProcess::IsInitialized()) {
|
||||
g_err = "core worker 未初始化";
|
||||
return -1;
|
||||
}
|
||||
auto &worker = CoreWorkerProcess::GetCoreWorker();
|
||||
std::string kv = "probe=ok\n";
|
||||
kv += "worker_id=" + worker.GetWorkerID().Hex() + "\n";
|
||||
kv += "rpc_raylet=" + HexOf(worker.GetRpcAddress().raylet_id()) + "\n";
|
||||
WriteOut(out, out_len, kv);
|
||||
return 0;
|
||||
} catch (const std::exception &e) {
|
||||
g_err = std::string("probe 异常: ") + e.what();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void nax_ray_shutdown(void) {
|
||||
if (CoreWorkerProcess::IsInitialized()) {
|
||||
CoreWorkerProcess::Shutdown();
|
||||
}
|
||||
g_inited = false;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
@@ -0,0 +1,45 @@
|
||||
import ctypes, sys
|
||||
|
||||
|
||||
class Cfg(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("gcs_addr", ctypes.c_char_p),
|
||||
("node_ip", ctypes.c_char_p),
|
||||
("raylet_socket", ctypes.c_char_p),
|
||||
("plasma_socket", ctypes.c_char_p),
|
||||
("node_manager_port", ctypes.c_int),
|
||||
("job_id_int", ctypes.c_int),
|
||||
("language", ctypes.c_int),
|
||||
("driver_name", ctypes.c_char_p),
|
||||
]
|
||||
|
||||
|
||||
lib = ctypes.CDLL(sys.argv[1] if len(sys.argv) > 1 else "/tmp/libnax_ray.so")
|
||||
lib.nax_ray_last_error.restype = ctypes.c_char_p
|
||||
|
||||
gcs = sys.argv[2] if len(sys.argv) > 2 else "127.0.0.1:6402"
|
||||
rsock = sys.argv[3] if len(sys.argv) > 3 else "/tmp/raylet_x.sock"
|
||||
psock = sys.argv[4] if len(sys.argv) > 4 else "/tmp/plasma_x.sock"
|
||||
port = int(sys.argv[5]) if len(sys.argv) > 5 else 6403
|
||||
lang = int(sys.argv[6]) if len(sys.argv) > 6 else 2 # 2 = CPP
|
||||
|
||||
cfg = Cfg(gcs.encode(), b"127.0.0.1", rsock.encode(), psock.encode(), port, 1, lang, b"nax_driver")
|
||||
buf = ctypes.create_string_buffer(16384)
|
||||
|
||||
print(f"--- init gcs={gcs} raylet={rsock} port={port} lang={lang}")
|
||||
rc = lib.nax_ray_init(ctypes.byref(cfg), buf, 16384)
|
||||
print("init rc =", rc)
|
||||
if rc != 0:
|
||||
print("err:", lib.nax_ray_last_error().decode())
|
||||
sys.exit(1)
|
||||
print(buf.value.decode())
|
||||
|
||||
import time
|
||||
hold = int(sys.argv[7]) if len(sys.argv) > 7 else 0
|
||||
rc2 = lib.nax_ray_probe(buf, 16384)
|
||||
print("probe rc =", rc2, buf.value.decode() if rc2 == 0 else lib.nax_ray_last_error().decode())
|
||||
if hold:
|
||||
print(f"holding {hold}s ...", flush=True)
|
||||
time.sleep(hold)
|
||||
lib.nax_ray_shutdown()
|
||||
print("shutdown done")
|
||||
@@ -0,0 +1,63 @@
|
||||
// 纯 C 测试程序:在 armv7 上验证 nax driver 能注册进 1.0.1 集群。
|
||||
// 用 C 写是为了不引入 libstdc++ 的 main 依赖,链接时更容易看清问题。
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// 与 shim 里的 NaxRayConfig 一一对应(字段顺序即 ABI)
|
||||
struct NaxRayConfig {
|
||||
const char *gcs_addr;
|
||||
const char *node_ip;
|
||||
const char *raylet_socket;
|
||||
const char *plasma_socket;
|
||||
int node_manager_port;
|
||||
int job_id_int;
|
||||
int language;
|
||||
const char *driver_name;
|
||||
};
|
||||
|
||||
extern int nax_ray_init(const struct NaxRayConfig *cfg, char *out, int out_len);
|
||||
extern const char *nax_ray_last_error(void);
|
||||
extern int nax_ray_probe(char *out, int out_len);
|
||||
extern void nax_ray_shutdown(void);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
struct NaxRayConfig cfg;
|
||||
cfg.gcs_addr = argc > 1 ? argv[1] : "127.0.0.1:6400";
|
||||
cfg.node_ip = "127.0.0.1";
|
||||
cfg.raylet_socket = argc > 2 ? argv[2] : "/tmp/raylet_a.sock";
|
||||
cfg.plasma_socket = argc > 3 ? argv[3] : "/tmp/plasma_a.sock";
|
||||
cfg.node_manager_port = argc > 4 ? atoi(argv[4]) : 6413;
|
||||
cfg.job_id_int = 2;
|
||||
cfg.language = 2; // CPP
|
||||
cfg.driver_name = "nax_driver_armv7";
|
||||
|
||||
char buf[16384];
|
||||
printf("--- init gcs=%s raylet=%s port=%d\n", cfg.gcs_addr, cfg.raylet_socket,
|
||||
cfg.node_manager_port);
|
||||
fflush(stdout);
|
||||
|
||||
int rc = nax_ray_init(&cfg, buf, sizeof buf);
|
||||
printf("init rc = %d\n", rc);
|
||||
if (rc != 0) {
|
||||
printf("err: %s\n", nax_ray_last_error());
|
||||
return 1;
|
||||
}
|
||||
printf("%s", buf);
|
||||
fflush(stdout);
|
||||
|
||||
rc = nax_ray_probe(buf, sizeof buf);
|
||||
printf("probe rc = %d\n%s", rc, rc == 0 ? buf : nax_ray_last_error());
|
||||
fflush(stdout);
|
||||
|
||||
int hold = argc > 5 ? atoi(argv[5]) : 0;
|
||||
if (hold) {
|
||||
printf("holding %ds\n", hold);
|
||||
fflush(stdout);
|
||||
sleep(hold);
|
||||
nax_ray_shutdown();
|
||||
printf("shutdown done\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
# 验证 nax driver 是否真的在 GCS 里注册(1.0.1 的 WorkerTable 由 RegisterToGcs 写入)
|
||||
set -u
|
||||
python3 /tmp/naxray/test101.py /tmp/libnax_ray.so 127.0.0.1:6400 /tmp/raylet_x.sock /tmp/plasma_x.sock 6403 2 40 > /tmp/driver101.log 2>&1 &
|
||||
DPID=$!
|
||||
sleep 10
|
||||
echo "=== driver 进程"; ps -o pid,stat,cmd -p $DPID 2>/dev/null | tail -2
|
||||
echo "=== driver 输出"; grep -vE 'WARN|UserWarning' /tmp/driver101.log | tail -14
|
||||
echo "=== redis 6401 全部 key"; redis-cli -p 6401 --scan 2>/dev/null | head -20
|
||||
echo "=== 找 nax_driver"
|
||||
for k in $(redis-cli -p 6401 --scan 2>/dev/null | grep -i 'WORKER' | head -10); do
|
||||
echo "--- $k"
|
||||
redis-cli -p 6401 hgetall "$k" 2>/dev/null | tr '\n' ' ' | head -c 400; echo
|
||||
done
|
||||
wait $DPID 2>/dev/null
|
||||
echo "=== 结束"
|
||||
Reference in new issue
Block a user