mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2026-04-23 00:17:25 +08:00
[BugFix] replace ftok with custom_ftok in get_output/save_output ops (#6822)
* [BugFix] replace ftok with custom_ftok in get_output/save_output ops * [Test] add unit test for custom_ftok * [Chore] create custom_ftok.h * [Chore] reorganize header file * [Fix] fix cache messager msg_queue_id+rank_id conflict
This commit is contained in:
@@ -0,0 +1,37 @@
|
|||||||
|
// Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
// Custom ftok that uses the low 20 bits of id instead of only 8 bits.
|
||||||
|
// This avoids dependency on filesystem paths while preserving queue separation.
|
||||||
|
inline key_t custom_ftok(const char* path, int id) {
|
||||||
|
struct stat st;
|
||||||
|
if (stat(path, &st) < 0) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"[custom_ftok] stat(\"%s\") failed (errno=%d), "
|
||||||
|
"msg queue key will be invalid!\n",
|
||||||
|
path,
|
||||||
|
errno);
|
||||||
|
return static_cast<key_t>(-1);
|
||||||
|
}
|
||||||
|
// low 4 bits of st_dev | low 8 bits of st_ino | low 20 bits of id
|
||||||
|
return static_cast<key_t>(((st.st_dev & 0x0f) << 28) |
|
||||||
|
((st.st_ino & 0xff) << 20) | (id & 0xfffff));
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include "custom_ftok.h"
|
||||||
#include "paddle/extension.h"
|
#include "paddle/extension.h"
|
||||||
|
|
||||||
#ifndef PD_BUILD_STATIC_OP
|
#ifndef PD_BUILD_STATIC_OP
|
||||||
@@ -25,6 +26,7 @@
|
|||||||
|
|
||||||
#define MAX_BSZ 512
|
#define MAX_BSZ 512
|
||||||
// #define GET_OUTPUT_DEBUG
|
// #define GET_OUTPUT_DEBUG
|
||||||
|
|
||||||
struct msgdata {
|
struct msgdata {
|
||||||
long mtype;
|
long mtype;
|
||||||
int mtext[MAX_BSZ + 2]; // stop_flag, bsz, tokens
|
int mtext[MAX_BSZ + 2]; // stop_flag, bsz, tokens
|
||||||
@@ -49,7 +51,7 @@ void GetOutput(const paddle::Tensor& x,
|
|||||||
#endif
|
#endif
|
||||||
msg_queue_id = inference_msg_queue_id_from_env;
|
msg_queue_id = inference_msg_queue_id_from_env;
|
||||||
}
|
}
|
||||||
static key_t key = ftok("/dev/shm", msg_queue_id);
|
static key_t key = custom_ftok("/dev/shm", msg_queue_id);
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
|
|
||||||
#ifdef GET_OUTPUT_DEBUG
|
#ifdef GET_OUTPUT_DEBUG
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include "custom_ftok.h"
|
||||||
#include "msg_utils.h"
|
#include "msg_utils.h"
|
||||||
#include "paddle/extension.h"
|
#include "paddle/extension.h"
|
||||||
|
|
||||||
@@ -33,9 +34,9 @@ void GetOutputKVSignal(const paddle::Tensor& x,
|
|||||||
std::string msg_que_str(msg_que_str_tmp);
|
std::string msg_que_str(msg_que_str_tmp);
|
||||||
msg_queue_id = std::stoi(msg_que_str);
|
msg_queue_id = std::stoi(msg_que_str);
|
||||||
}
|
}
|
||||||
msg_queue_id += rank_id;
|
msg_queue_id = msg_queue_id << 4 + rank_id;
|
||||||
static struct msgdatakv msg_rcv;
|
static struct msgdatakv msg_rcv;
|
||||||
static key_t key = ftok("/opt/", msg_queue_id);
|
static key_t key = custom_ftok("/opt/", msg_queue_id);
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
|
|
||||||
int* out_data = const_cast<int*>(x.data<int>());
|
int* out_data = const_cast<int*>(x.data<int>());
|
||||||
@@ -77,10 +78,7 @@ void GetOutputEp(const paddle::Tensor& x,
|
|||||||
#ifdef GET_OUTPUT_DEBUG
|
#ifdef GET_OUTPUT_DEBUG
|
||||||
std::cout << "msg_queue_id is: " << msg_queue_id << std::endl;
|
std::cout << "msg_queue_id is: " << msg_queue_id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
// static key_t key = ftok("/dev/shm", msg_queue_id);
|
key_t key = custom_ftok("/dev/shm", msg_queue_id);
|
||||||
// static int msgid = msgget(key, IPC_CREAT | 0666);
|
|
||||||
|
|
||||||
key_t key = ftok("/dev/shm", msg_queue_id);
|
|
||||||
int msgid = msgget(key, IPC_CREAT | 0666);
|
int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
|
|
||||||
#ifdef GET_OUTPUT_DEBUG
|
#ifdef GET_OUTPUT_DEBUG
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include "custom_ftok.h"
|
||||||
#include "paddle/extension.h"
|
#include "paddle/extension.h"
|
||||||
|
|
||||||
#ifndef PD_BUILD_STATIC_OP
|
#ifndef PD_BUILD_STATIC_OP
|
||||||
@@ -53,7 +54,7 @@ void GetOutputTopK(const paddle::Tensor& x,
|
|||||||
#endif
|
#endif
|
||||||
msg_queue_id = inference_msg_queue_id_from_env;
|
msg_queue_id = inference_msg_queue_id_from_env;
|
||||||
}
|
}
|
||||||
static key_t key = ftok("/dev/shm", msg_queue_id);
|
static key_t key = custom_ftok("/dev/shm", msg_queue_id);
|
||||||
|
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
#ifdef GET_OUTPUT_DEBUG
|
#ifdef GET_OUTPUT_DEBUG
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "custom_ftok.h"
|
||||||
#include "driver_types.h"
|
#include "driver_types.h"
|
||||||
#include "msg_utils.h"
|
#include "msg_utils.h"
|
||||||
#include "paddle/extension.h"
|
#include "paddle/extension.h"
|
||||||
@@ -79,8 +80,8 @@ struct RemoteCacheKvIpc {
|
|||||||
std::string msg_que_str(msg_que_str_tmp);
|
std::string msg_que_str(msg_que_str_tmp);
|
||||||
msg_queue_id = std::stoi(msg_que_str);
|
msg_queue_id = std::stoi(msg_que_str);
|
||||||
}
|
}
|
||||||
msg_queue_id += rank;
|
msg_queue_id = msg_queue_id << 4 + rank;
|
||||||
key_t key = ftok("/opt/", msg_queue_id);
|
key_t key = custom_ftok("/opt/", msg_queue_id);
|
||||||
msgid = msgget(key, IPC_CREAT | 0666);
|
msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
inited = true;
|
inited = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include "custom_ftok.h"
|
||||||
#include "paddle/extension.h"
|
#include "paddle/extension.h"
|
||||||
|
|
||||||
#ifndef PD_BUILD_STATIC_OP
|
#ifndef PD_BUILD_STATIC_OP
|
||||||
@@ -96,7 +97,7 @@ void SaveOutMmsgTopK(const paddle::Tensor& x,
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
static key_t key = ftok("/dev/shm", msg_queue_id);
|
static key_t key = custom_ftok("/dev/shm", msg_queue_id);
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
#ifdef SAVE_WITH_OUTPUT_DEBUG
|
#ifdef SAVE_WITH_OUTPUT_DEBUG
|
||||||
std::cout << "save_output_key: " << key << std::endl;
|
std::cout << "save_output_key: " << key << std::endl;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "save_with_output_msg.h"
|
#include "save_with_output_msg.h"
|
||||||
|
#include "custom_ftok.h"
|
||||||
|
|
||||||
void save_kernel(const paddle::Tensor& x,
|
void save_kernel(const paddle::Tensor& x,
|
||||||
const paddle::Tensor& not_need_stop,
|
const paddle::Tensor& not_need_stop,
|
||||||
@@ -68,7 +69,7 @@ void save_kernel(const paddle::Tensor& x,
|
|||||||
#ifdef SAVE_WITH_OUTPUT_DEBUG
|
#ifdef SAVE_WITH_OUTPUT_DEBUG
|
||||||
std::cout << "msg_queue_id is: " << msg_queue_id << std::endl;
|
std::cout << "msg_queue_id is: " << msg_queue_id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
static key_t key = ftok("/dev/shm", msg_queue_id);
|
static key_t key = custom_ftok("/dev/shm", msg_queue_id);
|
||||||
|
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
#ifdef SAVE_WITH_OUTPUT_DEBUG
|
#ifdef SAVE_WITH_OUTPUT_DEBUG
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "../speculate_msg.h"
|
#include "../speculate_msg.h"
|
||||||
|
#include "../../custom_ftok.h"
|
||||||
#include "paddle/extension.h"
|
#include "paddle/extension.h"
|
||||||
|
|
||||||
#ifndef PD_BUILD_STATIC_OP
|
#ifndef PD_BUILD_STATIC_OP
|
||||||
@@ -66,7 +67,7 @@ void MTPSaveFirstToken(const paddle::Tensor& x,
|
|||||||
msg_queue_id = inference_msg_queue_id_from_env;
|
msg_queue_id = inference_msg_queue_id_from_env;
|
||||||
}
|
}
|
||||||
|
|
||||||
static key_t key = ftok("./", msg_queue_id);
|
static key_t key = custom_ftok("./", msg_queue_id);
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
|
|
||||||
msg_sed.mtype = 1;
|
msg_sed.mtype = 1;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "paddle/extension.h"
|
#include "paddle/extension.h"
|
||||||
|
#include "../custom_ftok.h"
|
||||||
|
|
||||||
#ifndef PD_BUILD_STATIC_OP
|
#ifndef PD_BUILD_STATIC_OP
|
||||||
#define PD_BUILD_STATIC_OP(name) PD_BUILD_OP(static_op_##name)
|
#define PD_BUILD_STATIC_OP(name) PD_BUILD_OP(static_op_##name)
|
||||||
@@ -48,7 +49,7 @@ void SpeculateGetOutput(const paddle::Tensor& x,
|
|||||||
|
|
||||||
static struct speculate_msgdata msg_rcv;
|
static struct speculate_msgdata msg_rcv;
|
||||||
|
|
||||||
static key_t key = ftok("./", msg_queue_id);
|
static key_t key = custom_ftok("./", msg_queue_id);
|
||||||
|
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "paddle/extension.h"
|
#include "paddle/extension.h"
|
||||||
|
#include "../custom_ftok.h"
|
||||||
|
|
||||||
#ifndef PD_BUILD_STATIC_OP
|
#ifndef PD_BUILD_STATIC_OP
|
||||||
#define PD_BUILD_STATIC_OP(name) PD_BUILD_OP(static_op_##name)
|
#define PD_BUILD_STATIC_OP(name) PD_BUILD_OP(static_op_##name)
|
||||||
@@ -59,7 +60,7 @@ void SpeculateGetOutMmsgTopK(const paddle::Tensor& output_tokens,
|
|||||||
#endif
|
#endif
|
||||||
msg_queue_id = inference_msg_queue_id_from_env;
|
msg_queue_id = inference_msg_queue_id_from_env;
|
||||||
}
|
}
|
||||||
static key_t key = ftok("/dev/shm", msg_queue_id);
|
static key_t key = custom_ftok("/dev/shm", msg_queue_id);
|
||||||
|
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
#ifdef SPECULATE_GET_WITH_OUTPUT_DEBUG
|
#ifdef SPECULATE_GET_WITH_OUTPUT_DEBUG
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "paddle/extension.h"
|
#include "paddle/extension.h"
|
||||||
|
#include "../custom_ftok.h"
|
||||||
|
|
||||||
#ifndef PD_BUILD_STATIC_OP
|
#ifndef PD_BUILD_STATIC_OP
|
||||||
#define PD_BUILD_STATIC_OP(name) PD_BUILD_OP(static_op_##name)
|
#define PD_BUILD_STATIC_OP(name) PD_BUILD_OP(static_op_##name)
|
||||||
@@ -66,7 +67,7 @@ void SpeculateSaveWithOutputMsg(const paddle::Tensor& accept_tokens,
|
|||||||
msg_queue_id = inference_msg_queue_id_from_env;
|
msg_queue_id = inference_msg_queue_id_from_env;
|
||||||
}
|
}
|
||||||
static struct speculate_msgdata msg_sed;
|
static struct speculate_msgdata msg_sed;
|
||||||
static key_t key = ftok("./", msg_queue_id);
|
static key_t key = custom_ftok("./", msg_queue_id);
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
|
|
||||||
msg_sed.mtype = 1;
|
msg_sed.mtype = 1;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "paddle/extension.h"
|
#include "paddle/extension.h"
|
||||||
|
#include "../custom_ftok.h"
|
||||||
|
|
||||||
#ifndef PD_BUILD_STATIC_OP
|
#ifndef PD_BUILD_STATIC_OP
|
||||||
#define PD_BUILD_STATIC_OP(name) PD_BUILD_OP(static_op_##name)
|
#define PD_BUILD_STATIC_OP(name) PD_BUILD_OP(static_op_##name)
|
||||||
@@ -124,7 +125,7 @@ void SpeculateSaveOutMmsgTopK(const paddle::Tensor& sampled_token_ids,
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
static key_t key = ftok("/dev/shm", msg_queue_id);
|
static key_t key = custom_ftok("/dev/shm", msg_queue_id);
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
#ifdef SPECULATE_SAVE_WITH_OUTPUT_DEBUG
|
#ifdef SPECULATE_SAVE_WITH_OUTPUT_DEBUG
|
||||||
std::cout << "save_output_key: " << key << std::endl;
|
std::cout << "save_output_key: " << key << std::endl;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include "../custom_ftok.h"
|
||||||
#include "helper.h"
|
#include "helper.h"
|
||||||
#include "speculate_msg.h"
|
#include "speculate_msg.h"
|
||||||
#include "../cccl_compat.h" // CCCL 3.0 compatibility
|
#include "../cccl_compat.h" // CCCL 3.0 compatibility
|
||||||
@@ -314,8 +315,7 @@ void SpeculateStepSchedule(
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
// static key_t key = ftok("/dev/shm", msg_queue_id);
|
static key_t key = custom_ftok("./", msg_queue_id);
|
||||||
static key_t key = ftok("./", msg_queue_id);
|
|
||||||
|
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
msg_sed.mtype = 1;
|
msg_sed.mtype = 1;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include "custom_ftok.h"
|
||||||
#include "helper.h"
|
#include "helper.h"
|
||||||
#include "save_with_output_msg.h"
|
#include "save_with_output_msg.h"
|
||||||
#include "cccl_compat.h" // CCCL 3.0 compatibility
|
#include "cccl_compat.h" // CCCL 3.0 compatibility
|
||||||
@@ -300,7 +301,7 @@ void Schedule(const paddle::Tensor &stop_flags,
|
|||||||
"number.");
|
"number.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static key_t key = ftok("/dev/shm", msg_queue_id);
|
static key_t key = custom_ftok("/dev/shm", msg_queue_id);
|
||||||
|
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
msg_sed.mtype = 1;
|
msg_sed.mtype = 1;
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
// Custom ftok that uses the low 20 bits of id instead of only 8 bits.
|
||||||
|
// This avoids dependency on filesystem paths while preserving queue separation.
|
||||||
|
inline key_t custom_ftok(const char* path, int id) {
|
||||||
|
struct stat st;
|
||||||
|
if (stat(path, &st) < 0) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"[custom_ftok] stat(\"%s\") failed (errno=%d), "
|
||||||
|
"msg queue key will be invalid!\n",
|
||||||
|
path,
|
||||||
|
errno);
|
||||||
|
return static_cast<key_t>(-1);
|
||||||
|
}
|
||||||
|
// low 4 bits of st_dev | low 8 bits of st_ino | low 20 bits of id
|
||||||
|
return static_cast<key_t>(((st.st_dev & 0x0f) << 28) |
|
||||||
|
((st.st_ino & 0xff) << 20) | (id & 0xfffff));
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include "custom_ftok.h"
|
||||||
#include "msg_utils.h"
|
#include "msg_utils.h"
|
||||||
#include "paddle/extension.h"
|
#include "paddle/extension.h"
|
||||||
|
|
||||||
@@ -29,9 +30,9 @@ void GetOutputKVSignal(const paddle::Tensor& x,
|
|||||||
std::string msg_que_str(msg_que_str_tmp);
|
std::string msg_que_str(msg_que_str_tmp);
|
||||||
msg_queue_id = std::stoi(msg_que_str);
|
msg_queue_id = std::stoi(msg_que_str);
|
||||||
}
|
}
|
||||||
msg_queue_id += rank_id;
|
msg_queue_id = msg_queue_id << 4 + rank_id;
|
||||||
static struct msgdatakv msg_rcv;
|
static struct msgdatakv msg_rcv;
|
||||||
static key_t key = ftok("/opt/", msg_queue_id);
|
static key_t key = custom_ftok("/opt/", msg_queue_id);
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
|
|
||||||
int* out_data = const_cast<int*>(x.data<int>());
|
int* out_data = const_cast<int*>(x.data<int>());
|
||||||
@@ -70,7 +71,7 @@ void GetOutput(const paddle::Tensor& x,
|
|||||||
#endif
|
#endif
|
||||||
msg_queue_id = inference_msg_queue_id_from_env;
|
msg_queue_id = inference_msg_queue_id_from_env;
|
||||||
}
|
}
|
||||||
static key_t key = ftok("/dev/shm", msg_queue_id);
|
static key_t key = custom_ftok("/dev/shm", msg_queue_id);
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
|
|
||||||
#ifdef GET_OUTPUT_DEBUG
|
#ifdef GET_OUTPUT_DEBUG
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include "custom_ftok.h"
|
||||||
#include "paddle/extension.h"
|
#include "paddle/extension.h"
|
||||||
|
|
||||||
#ifndef PD_BUILD_STATIC_OP
|
#ifndef PD_BUILD_STATIC_OP
|
||||||
@@ -53,7 +54,7 @@ void GetOutputTopK(const paddle::Tensor& x,
|
|||||||
#endif
|
#endif
|
||||||
msg_queue_id = inference_msg_queue_id_from_env;
|
msg_queue_id = inference_msg_queue_id_from_env;
|
||||||
}
|
}
|
||||||
static key_t key = ftok("/dev/shm", msg_queue_id);
|
static key_t key = custom_ftok("/dev/shm", msg_queue_id);
|
||||||
|
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
#ifdef GET_OUTPUT_DEBUG
|
#ifdef GET_OUTPUT_DEBUG
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include "../custom_ftok.h"
|
||||||
#include "paddle/extension.h"
|
#include "paddle/extension.h"
|
||||||
#include "speculate_msg.h"
|
#include "speculate_msg.h"
|
||||||
|
|
||||||
@@ -60,7 +61,7 @@ void MTPSaveFirstToken(const paddle::Tensor& x,
|
|||||||
msg_queue_id = inference_msg_queue_id_from_env;
|
msg_queue_id = inference_msg_queue_id_from_env;
|
||||||
}
|
}
|
||||||
|
|
||||||
static key_t key = ftok("./", msg_queue_id);
|
static key_t key = custom_ftok("./", msg_queue_id);
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
|
|
||||||
msg_sed.mtype = 1;
|
msg_sed.mtype = 1;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include "../custom_ftok.h"
|
||||||
#include "paddle/extension.h"
|
#include "paddle/extension.h"
|
||||||
#include "speculate_msg.h"
|
#include "speculate_msg.h"
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@ void SpeculateGetOutput(const paddle::Tensor& x,
|
|||||||
|
|
||||||
static struct speculate_msgdata msg_rcv;
|
static struct speculate_msgdata msg_rcv;
|
||||||
|
|
||||||
static key_t key = ftok("./", msg_queue_id);
|
static key_t key = custom_ftok("./", msg_queue_id);
|
||||||
|
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include "../custom_ftok.h"
|
||||||
#include "paddle/extension.h"
|
#include "paddle/extension.h"
|
||||||
#include "speculate_msg.h"
|
#include "speculate_msg.h"
|
||||||
#include "xpu/plugin.h"
|
#include "xpu/plugin.h"
|
||||||
@@ -67,7 +68,7 @@ void SpeculateSaveWithOutputMsg(const paddle::Tensor& accept_tokens,
|
|||||||
msg_queue_id = inference_msg_queue_id_from_env;
|
msg_queue_id = inference_msg_queue_id_from_env;
|
||||||
}
|
}
|
||||||
static struct speculate_msgdata msg_sed;
|
static struct speculate_msgdata msg_sed;
|
||||||
static key_t key = ftok("./", msg_queue_id);
|
static key_t key = custom_ftok("./", msg_queue_id);
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
|
|
||||||
msg_sed.mtype = 1;
|
msg_sed.mtype = 1;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include <paddle/phi/backends/xpu/xpu_context.h>
|
#include <paddle/phi/backends/xpu/xpu_context.h>
|
||||||
|
#include "../custom_ftok.h"
|
||||||
#include "paddle/phi/core/enforce.h"
|
#include "paddle/phi/core/enforce.h"
|
||||||
#include "speculate_msg.h" // NOLINT
|
#include "speculate_msg.h" // NOLINT
|
||||||
#include "xpu/plugin.h"
|
#include "xpu/plugin.h"
|
||||||
@@ -138,8 +139,7 @@ void SpeculateStepSchedule(
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
// static key_t key = ftok("/dev/shm", msg_queue_id);
|
static key_t key = custom_ftok("./", msg_queue_id);
|
||||||
static key_t key = ftok("./", msg_queue_id);
|
|
||||||
|
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
msg_sed.mtype = 1;
|
msg_sed.mtype = 1;
|
||||||
|
|||||||
@@ -20,7 +20,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "msg_utils.h" // NOLINT
|
#include "custom_ftok.h" // NOLINT
|
||||||
|
#include "msg_utils.h" // NOLINT
|
||||||
|
|
||||||
struct RemoteCacheKvIpc {
|
struct RemoteCacheKvIpc {
|
||||||
struct save_cache_kv_complete_signal_layerwise_meta_data {
|
struct save_cache_kv_complete_signal_layerwise_meta_data {
|
||||||
@@ -70,8 +71,8 @@ struct RemoteCacheKvIpc {
|
|||||||
std::string msg_que_str(msg_que_str_tmp);
|
std::string msg_que_str(msg_que_str_tmp);
|
||||||
msg_queue_id = std::stoi(msg_que_str);
|
msg_queue_id = std::stoi(msg_que_str);
|
||||||
}
|
}
|
||||||
msg_queue_id += rank;
|
msg_queue_id = msg_queue_id << 4 + rank;
|
||||||
key_t key = ftok("/opt/", msg_queue_id);
|
key_t key = custom_ftok("/opt/", msg_queue_id);
|
||||||
msgid = msgget(key, IPC_CREAT | 0666);
|
msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
inited = true;
|
inited = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include "custom_ftok.h"
|
||||||
#include "paddle/extension.h"
|
#include "paddle/extension.h"
|
||||||
|
|
||||||
#ifndef PD_BUILD_STATIC_OP
|
#ifndef PD_BUILD_STATIC_OP
|
||||||
@@ -96,7 +97,7 @@ void SaveOutMmsgTopK(const paddle::Tensor& x,
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
static key_t key = ftok("/dev/shm", msg_queue_id);
|
static key_t key = custom_ftok("/dev/shm", msg_queue_id);
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
#ifdef SAVE_WITH_OUTPUT_DEBUG
|
#ifdef SAVE_WITH_OUTPUT_DEBUG
|
||||||
std::cout << "save_output_key: " << key << std::endl;
|
std::cout << "save_output_key: " << key << std::endl;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include "custom_ftok.h"
|
||||||
#include "msg_utils.h"
|
#include "msg_utils.h"
|
||||||
#include "paddle/extension.h"
|
#include "paddle/extension.h"
|
||||||
|
|
||||||
@@ -80,7 +81,7 @@ void SaveOutMmsg(const paddle::Tensor &x,
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
static key_t key = ftok("/dev/shm", msg_queue_id);
|
static key_t key = custom_ftok("/dev/shm", msg_queue_id);
|
||||||
|
|
||||||
static int msgid = msgget(key, IPC_CREAT | 0666);
|
static int msgid = msgget(key, IPC_CREAT | 0666);
|
||||||
#ifdef SAVE_WITH_OUTPUT_DEBUG
|
#ifdef SAVE_WITH_OUTPUT_DEBUG
|
||||||
|
|||||||
Reference in New Issue
Block a user