-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update project structure and add interned strings and add ci
- Loading branch information
Showing
10 changed files
with
368 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: ci | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
cmake_build: | ||
name: cmake_build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: setup | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install build-essential cmake g++ clang-15 libgtest-dev libgmock-dev make | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.9' | ||
- name: Generate makefile using CMake | ||
run: | | ||
mkdir build | ||
cd build | ||
cmake .. -DCMAKE_CXX_COMPILER=/usr/bin/clang++-15 | ||
- name: Run make | ||
run: | | ||
cd build | ||
make -j$(nproc) | ||
- name: Run unittests | ||
run: | | ||
cd build | ||
ctest -j$(nproc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# my_ai_training | ||
# my_ai_training | ||
|
||
练习ai相关代码的仓库,目前在过onnx代码中。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright (c) ONNX Project Contributors | ||
|
||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// ATTENTION: The code in this file is highly EXPERIMENTAL. | ||
// Adventurous users should note that the APIs will probably change. | ||
|
||
#include "ir/interned_strings.h" | ||
|
||
#include <stdint.h> | ||
|
||
#include <mutex> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
#include "ir/assertions.h" | ||
|
||
namespace my_ai_training::ir { | ||
|
||
struct InternedStrings { | ||
InternedStrings() | ||
: next_sym(kLastSymbol){ | ||
#define REGISTER_SYMBOL(s) \ | ||
string_to_sym_[#s] = k##s; \ | ||
sym_to_string_[k##s] = #s; | ||
FORALL_BUILTIN_SYMBOLS(REGISTER_SYMBOL) | ||
#undef REGISTER_SYMBOL | ||
} uint32_t symbol(const std::string& s) { | ||
std::lock_guard<std::mutex> guard(mutex_); | ||
auto it = string_to_sym_.find(s); | ||
if (it != string_to_sym_.end()) return it->second; | ||
uint32_t k = next_sym++; | ||
string_to_sym_[s] = k; | ||
sym_to_string_[k] = s; | ||
return k; | ||
} | ||
const char* string(Symbol sym) { | ||
// Builtin Symbols are also in the maps, but | ||
// we can bypass the need to acquire a lock | ||
// to read the map for Builtins because we already | ||
// know their string value | ||
switch (sym) { | ||
#define DEFINE_CASE(s) \ | ||
case k##s: \ | ||
return #s; | ||
FORALL_BUILTIN_SYMBOLS(DEFINE_CASE) | ||
#undef DEFINE_CASE | ||
default: | ||
return customString(sym); | ||
} | ||
} | ||
|
||
private: | ||
const char* customString(Symbol sym) { | ||
std::lock_guard<std::mutex> guard(mutex_); | ||
auto it = sym_to_string_.find(sym); | ||
ONNX_ASSERT(it != sym_to_string_.end()); | ||
return it->second.c_str(); | ||
} | ||
std::unordered_map<std::string, uint32_t> string_to_sym_; | ||
std::unordered_map<uint32_t, std::string> sym_to_string_; | ||
uint32_t next_sym; | ||
std::mutex mutex_; | ||
}; | ||
|
||
static InternedStrings& globalStrings() { | ||
static InternedStrings s; | ||
return s; | ||
} | ||
|
||
const char* Symbol::toString() const { return globalStrings().string(*this); } | ||
|
||
Symbol::Symbol(const std::string& s) : value(globalStrings().symbol(s)) {} | ||
|
||
} // namespace my_ai_training::ir |
Oops, something went wrong.