-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
993 additions
and
541 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 |
---|---|---|
@@ -1,29 +1,41 @@ | ||
project(cpu) | ||
cmake_minimum_required(VERSION 3.13) | ||
|
||
add_library(cpu_cmodel STATIC | ||
src/hardware_context.cpp | ||
src/dummy.cpp | ||
) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
|
||
target_include_directories(cpu_cmodel PUBLIC include) | ||
target_link_libraries(cpu_cmodel PUBLIC fmt::fmt spdlog::spdlog) | ||
if(NOT APPLE AND NOT MSVC) | ||
target_link_libraries(cpu_cmodel PRIVATE rt) | ||
endif() | ||
target_include_directories(cpu_cmodel PUBLIC /compiler/huochenghai/GNNE/rebuild-ir/nncase/src/Native/include/ /compiler/huochenghai/GNNE/rebuild-ir/nncase/modules/cpu/include/) | ||
target_include_directories(cpu_cmodel PUBLIC /root/.conan/data/gsl-lite/0.37.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/) | ||
# target_link_libraries(cpu_cmodel PUBLIC gsl::gsl-lite) | ||
# if(NOT APPLE AND NOT MSVC) | ||
# target_link_libraries(cpu_cmodel PRIVATE rt) | ||
# endif() | ||
set_target_properties(cpu_cmodel PROPERTIES POSITION_INDEPENDENT_CODE ON) | ||
add_executable(cpu_cmodel_cli src/cpu_cmodel.cpp ../shared_memory.cpp) | ||
target_link_libraries(cpu_cmodel_cli PUBLIC cpu_cmodel) | ||
set_target_properties(cpu_cmodel_cli PROPERTIES POSITION_INDEPENDENT_CODE ON | ||
OUTPUT_NAME "nncase.simulator.cpu.c") | ||
install(TARGETS cpu_cmodel_cli COMPONENT nncase-runtime) | ||
|
||
# add_executable(cpu_cmodel_cli src/cpu_cmodel.cpp ../shared_memory.cpp) | ||
# target_link_libraries(cpu_cmodel_cli PUBLIC cpu_cmodel) | ||
# set_target_properties(cpu_cmodel_cli PROPERTIES POSITION_INDEPENDENT_CODE ON | ||
# OUTPUT_NAME "nncase.simulator.cpu.c") | ||
# install(TARGETS cpu_cmodel_cli COMPONENT nncase-runtime) | ||
|
||
|
||
function(add_test name test_path) | ||
if (CMAKE_BUILD_TYPE STREQUAL "Release") | ||
add_compile_options(-O1) | ||
endif() | ||
add_link_options(-no-pie -nostartfiles -fPIC -fno-stack-protector -static -Wl,-e,_Z6_startP19hardware_context_mtP15runtime_util_mtPhS3_S3_) | ||
add_executable(${name} "${test_path}/main.cpp") | ||
target_link_libraries(${name} cpu_cmodel spdlog::spdlog) | ||
target_link_libraries(${name} cpu_cmodel) | ||
endfunction(add_test) | ||
|
||
add_test(demo1 tests/demo1) | ||
add_test(demo2 tests/demo2) | ||
add_test(demo3 tests/demo3) | ||
add_test(norm tests/norm) | ||
add_test(embed tests/embed) | ||
add_test(head tests/head) | ||
# add_test(demo1 tests/demo1) | ||
# add_test(demo2 tests/demo2) | ||
# add_test(demo3 tests/demo3) | ||
add_test(demo4 tests/demo4) | ||
# add_test(norm tests/norm) | ||
# add_test(embed tests/embed) | ||
# add_test(head tests/head) |
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
53 changes: 37 additions & 16 deletions
53
modules/cpu/src/runtime/cmodel/include/hardware_context.h
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,30 +1,51 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
#include <iostream> | ||
#include <memory> | ||
// #include <memory> | ||
|
||
struct hardware_context_impl; | ||
struct hardware_context_mt { | ||
void (*lock_block)(int bid); | ||
int (*mark_block_visit)(int bid, int tid); | ||
void (*unlock_block)(int bid); | ||
void (*wait_block_sync)(int bid, int visited, | ||
std::function<void()> callable); | ||
void (*lock_all)(); | ||
int (*mark_all_visit)(int bid, int tid); | ||
void (*unlock_all)(); | ||
void (*wait_all_sync)(int visited, std::function<void()> callable); | ||
void (*init)(); | ||
}; | ||
|
||
class hardware_context { | ||
public: | ||
hardware_context(); | ||
void lock_block(int bid); | ||
int mark_block_visit(int bid, int tid); | ||
void unlock_block(int bid); | ||
// hardware_context(hardware_context_mt *impl) : impl_(impl){}; | ||
void lock_block(int bid) { impl_->lock_block(bid); } | ||
int mark_block_visit(int bid, int tid) { | ||
return impl_->mark_block_visit(bid, tid); | ||
} | ||
void unlock_block(int bid) { impl_->unlock_block(bid); } | ||
void wait_block_sync( | ||
int bid, int visited, std::function<void()> callable = []() -> void {}); | ||
void lock_all(); | ||
int mark_all_visit(int bid, int tid); | ||
void unlock_all(); | ||
int bid, int visited, | ||
std::function<void()> callable = []() -> void {}) { | ||
impl_->wait_block_sync(bid, visited, callable); | ||
} | ||
void lock_all() { impl_->lock_all(); } | ||
int mark_all_visit(int bid, int tid) { | ||
return impl_->mark_all_visit(bid, tid); | ||
} | ||
void unlock_all() { impl_->unlock_all(); } | ||
void wait_all_sync( | ||
int visited, std::function<void()> callable = []() -> void {}); | ||
int visited, std::function<void()> callable = []() -> void {}) { | ||
impl_->wait_all_sync(visited, callable); | ||
} | ||
void *global_var = nullptr; | ||
|
||
private: | ||
std::unique_ptr<hardware_context_impl> impl_; | ||
hardware_context_mt* impl_; | ||
}; | ||
|
||
extern std::unique_ptr<hardware_context> global_hardware_ctx; | ||
static hardware_context global_hardware_ctx; | ||
|
||
void global_hardware_init(); | ||
void global_hardware_init(hardware_context_mt *impl) { | ||
global_hardware_ctx.impl_ = impl; | ||
impl->init(); | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.