Skip to content

Commit

Permalink
chore: sync 10.0 updates
Browse files Browse the repository at this point in the history
- cyber:
	 - 45d620d88d fix: issue of reading and writing files in relative path
	 - 4f023e7f9c feat: checking eplite env
	 - bc76ae23e5 add shared arena buffer for point
	 - 7289a4bb1b fix(model-download): fix perception model url
	 - da937026b0 fix: switch default tag of image and fix model download script
- drivers:
	 - bc76ae23e5 add shared arena buffer for point

Signed-off-by: liangjinping <[email protected]>
Change-Id: Ifb816dd40202840a2b8501bce1db2f99b2404bd3
  • Loading branch information
lykling committed Nov 19, 2024
1 parent 74d9ebd commit 7bc54b8
Show file tree
Hide file tree
Showing 23 changed files with 846 additions and 361 deletions.
4 changes: 2 additions & 2 deletions aem/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export APOLLO_ENV_BACKEND="${APOLLO_ENV_BACKEND:-docker}"
export APOLLO_ENV_CONTAINER_PREFIX=${APOLLO_ENV_CONTAINER_PREFIX:-apollo_neo_dev_}
export APOLLO_ENV_CONTAINER_REPO_X86='registry.baidubce.com/apollo/apollo-env-gpu'
export APOLLO_ENV_CONTAINER_REPO_ARM='registry.baidubce.com/apollo/apollo-env-arm'
export APOLLO_ENV_CONTAINER_TAG_X86='9.0-u22-preview'
export APOLLO_ENV_CONTAINER_TAG_ARM='9.0-preview'
export APOLLO_ENV_CONTAINER_TAG_X86='10.0-u22'
export APOLLO_ENV_CONTAINER_TAG_ARM='10.0-u20'
export APOLLO_ENV_CONTAINER_NAME="${APOLLO_ENV_CONTAINER_NAME:-${APOLLO_ENV_CONTAINER_PREFIX}${APOLLO_ENV_NAME}}"
export APOLLO_ENV_CONTAINER_USER="${APOLLO_ENV_CONTAINER_USER:-${USER}}"
export APOLLO_ENV_CONTAINER_GROUP="${APOLLO_ENV_CONTAINER_GROUP:-$(id -gn)}"
Expand Down
4 changes: 4 additions & 0 deletions aem/funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,10 @@ apollo_create_container_env_options() {
# shell history
env_opts+=('-e' "HISTFILE=${APOLLO_ENV_WORKROOT}/.cache/.bash_history")
# eplite
cat /etc/bash.bashrc | grep AIPE_WITH_UNIX_DOMAIN_SOCKET >/dev/null 2>&1
[[ $? == 0 ]] && env_opts+=('-e' "AIPE_WITH_UNIX_DOMAIN_SOCKET=ON")
echo "${env_opts[*]}"
}
export -f apollo_create_container_env_options
Expand Down
2 changes: 1 addition & 1 deletion cyber/base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package(default_visibility = ["//visibility:public"])
apollo_cc_library(
name = "cyber_base",
hdrs = [
# "arena_queue.h",
"arena_queue.h",
"atomic_hash_map.h",
"atomic_rw_lock.h",
"bounded_queue.h",
Expand Down
262 changes: 262 additions & 0 deletions cyber/base/arena_queue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
/******************************************************************************
* Copyright 2024 The Apollo 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.
*****************************************************************************/

#ifndef CYBER_BASE_ARENA_QUEUE_H_
#define CYBER_BASE_ARENA_QUEUE_H_

#include <unistd.h>

#include <algorithm>
#include <atomic>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <memory>
#include <utility>
#include <vector>

#include <google/protobuf/arena.h>

#include "cyber/base/macros.h"
#include "cyber/base/wait_strategy.h"

namespace apollo {
namespace cyber {
namespace base {

template <typename T>
class ArenaQueue {
public:
using value_type = T;
using size_type = uint64_t;

public:
ArenaQueue() {}
ArenaQueue& operator=(const ArenaQueue& other) = delete;
ArenaQueue(const ArenaQueue& other) = delete;
~ArenaQueue();
bool Init(uint64_t size);
bool Init(uint64_t size, google::protobuf::Arena* arena);

T* AddBack();
T* PopFront();
T* GetBack();
T* GetFront();

uint64_t Size();
bool Empty();
uint64_t Head() { return head_.load(); }
uint64_t Tail() { return tail_.load(); }
uint64_t Commit() { return commit_.load(); }
bool NextIndex(uint64_t& index) {
if (Empty()) {
return false;
}
if (arena_) {
if (GetIndex(index) < Tail() - 1) {
index = GetIndex(index + 1);
return true;
}
return false;
} else {
if (index < Size() - 1) {
index = index + 1;
return true;
}
return false;
}
}
bool GetHeadIndex(uint64_t& index) {
if (Empty()) {
return false;
}
if (arena_) {
index = GetIndex(head_ + 1);
return true;
} else {
index = 0;
return true;
}
}
bool GetTailIndex(uint64_t& index) {
if (Empty()) {
return false;
}
if (arena_) {
index = GetIndex(tail_ - 1);
return true;
} else {
index = Size() - 1;
return true;
}
}
bool GetEleByIndex(uint64_t i, T*& ptr) {
if (Empty()) {
return false;
}
if (arena_) {
ptr = pool_[GetIndex(i)];
return true;
} else {
if (i > Size() - 1) {
return false;
}
ptr = &normal_queue[i];
return true;
}
}
bool IsArenaEnable() { return arena_; }

private:
uint64_t GetIndex(uint64_t num);

alignas(CACHELINE_SIZE) std::atomic<uint64_t> head_ = {0};
alignas(CACHELINE_SIZE) std::atomic<uint64_t> tail_ = {1};
alignas(CACHELINE_SIZE) std::atomic<uint64_t> commit_ = {1};

uint64_t pool_size_ = 0;
std::vector<T*> pool_;
bool arena_;
std::deque<T> normal_queue;
};

template <typename T>
ArenaQueue<T>::~ArenaQueue() {}

template <typename T>
inline bool ArenaQueue<T>::Init(uint64_t size) {
arena_ = false;
return true;
}

template <typename T>
inline bool ArenaQueue<T>::Init(uint64_t size, google::protobuf::Arena* arena) {
pool_size_ = size + 2;
if (pool_.size() == pool_size_) {
return true;
}
pool_.clear();
for (uint64_t i = 0; i < pool_size_; ++i) {
pool_.push_back(google::protobuf::Arena::CreateMessage<T>(arena));
}
arena_ = true;
return true;
}

template <typename T>
T* ArenaQueue<T>::GetBack() {
if (Empty()) {
return nullptr;
}
if (arena_) {
return pool_[GetIndex(tail_ - 1)];
} else {
return &normal_queue.back();
}
}

template <typename T>
T* ArenaQueue<T>::GetFront() {
if (Empty()) {
return nullptr;
}
if (arena_) {
return pool_[GetIndex(head_ + 1)];
} else {
return &normal_queue.front();
}
}

template <typename T>
T* ArenaQueue<T>::AddBack() {
if (arena_) {
uint64_t new_tail = 0;
uint64_t old_commit = 0;
uint64_t old_tail = tail_.load(std::memory_order_acquire);
do {
new_tail = old_tail + 1;
if (GetIndex(new_tail) ==
GetIndex(head_.load(std::memory_order_acquire))) {
return nullptr;
}
} while (!tail_.compare_exchange_weak(old_tail, new_tail,
std::memory_order_acq_rel,
std::memory_order_relaxed));
do {
old_commit = old_tail;
} while (cyber_unlikely(!commit_.compare_exchange_weak(
old_commit, new_tail, std::memory_order_acq_rel,
std::memory_order_relaxed)));
return pool_[GetIndex(old_tail)];
} else {
T instance;
normal_queue.push_back(instance);
return &normal_queue.back();
}
}

template <typename T>
T* ArenaQueue<T>::PopFront() {
if (Empty()) {
return nullptr;
}
if (arena_) {
uint64_t new_head = 0;
uint64_t old_head = head_.load(std::memory_order_acquire);
do {
new_head = old_head + 1;
if (new_head == commit_.load(std::memory_order_acquire)) {
return nullptr;
}
} while (!head_.compare_exchange_weak(old_head, new_head,
std::memory_order_acq_rel,
std::memory_order_relaxed));
return pool_[GetIndex(new_head)];
} else {
normal_queue.pop_front();
return nullptr;
}
}

template <typename T>
inline uint64_t ArenaQueue<T>::Size() {
if (arena_) {
return tail_ - head_ - 1;
} else {
return normal_queue.size();
}
}

template <typename T>
inline bool ArenaQueue<T>::Empty() {
if (arena_) {
return Size() == 0;
} else {
return normal_queue.empty();
}
}

template <typename T>
inline uint64_t ArenaQueue<T>::GetIndex(uint64_t num) {
return num - (num / pool_size_) * pool_size_; // faster than %
}

} // namespace base
} // namespace cyber
} // namespace apollo

#endif // CYBER_BASE_ARENA_QUEUE_H_
7 changes: 7 additions & 0 deletions cyber/node/writer_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ class WriterBase {
return role_attr_.channel_name();
}

/**
* @brief Get Writer's Channel id
*
* @return const uint64_t& const reference to the channel id
*/
const uint64_t GetChannelId() const { return role_attr_.channel_id(); }

/**
* @brief Is Writer initialized?
*
Expand Down
1 change: 1 addition & 0 deletions cyber/proto/transport_conf.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ message ArenaChannelConf {
// 2^31 - 128 * 1024 * 1024, which is hardcode in the underlying implementation
optional uint64 max_msg_size = 2 [default = 33554432];
optional uint64 max_pool_size = 3 [default = 32];
optional uint64 shared_buffer_size = 4 [default = 0];
};

message ArenaShmConf {
Expand Down
Loading

0 comments on commit 7bc54b8

Please sign in to comment.