-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SWAP] Implement inference mode #2696
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,10 +144,10 @@ void Manager::reinitialize() { | |
tensor_pool.reinitialize(); | ||
} | ||
|
||
void Manager::allocateWeights(unsigned int max_exec_order_) { | ||
void Manager::allocateWeights(unsigned int max_exec_order_, bool init) { | ||
if (!weight_pool.isAllocated()) { | ||
finalizeTensorPool(weight_pool, 0, max_exec_order_); | ||
weight_pool.allocate(); | ||
weight_pool.allocate(init); | ||
} | ||
} | ||
|
||
|
@@ -376,7 +376,9 @@ std::vector<Weight *> Manager::requestWeights( | |
* and therefore, if we remove the calcDerivative order, then tests fails. | ||
*/ | ||
|
||
TensorLifespan var_ls = TensorLifespan::MAX_LIFESPAN; | ||
TensorLifespan var_ls = swap_mode == "inference" | ||
? TensorLifespan::FORWARD_INFER_LIFESPAN | ||
: TensorLifespan::MAX_LIFESPAN; | ||
TensorLifespan grad_ls = TensorLifespan::BACKWARD_FUNC_LIFESPAN; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a pure question (it may be irrelevant to this PR, though). |
||
|
||
std::vector<Weight *> ret; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
#include <profiler.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/mman.h> | ||
#include <sys/types.h> | ||
#include <unistd.h> | ||
|
||
|
@@ -70,7 +71,7 @@ void *SwapDevice::getBuffer(off_t offset, size_t size, bool alloc_only) { | |
<< std::string(strerror_r(errno, error_buf, error_buflen)); | ||
|
||
void *buf = static_cast<void *>(ptr + diff); | ||
mapped[buf] = std::make_pair(ptr, len); | ||
mapped[buf] = std::make_tuple(ptr, len, offset, (ssize_t)size); | ||
|
||
return buf; | ||
#else | ||
|
@@ -88,7 +89,7 @@ void *SwapDevice::getBuffer(off_t offset, size_t size, bool alloc_only) { | |
<< "SwapDevice: seek file: " << dev_path; | ||
|
||
len = read(fd, ptr, size); | ||
NNTR_THROW_IF(len != (ssize_t)size, std::runtime_error) | ||
NNTR_THROW_IF(len != (size_t)size, std::runtime_error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to cast 'ssize_t' to 'size_t'? |
||
<< "SwapDevice: read file: " << dev_path; | ||
} | ||
|
||
|
@@ -107,7 +108,22 @@ void SwapDevice::putBuffer(void *ptr, bool dealloc_only) { | |
NNTR_THROW_IF(mapped.find(ptr) == mapped.end(), std::runtime_error) | ||
<< "Couldn't find buffer"; | ||
|
||
off_t off; | ||
ssize_t len; | ||
|
||
auto info = mapped[ptr]; | ||
if (!dealloc_only) { | ||
off = lseek(fd, std::get<2>(info), SEEK_SET); | ||
NNTR_THROW_IF(off < 0, std::runtime_error) | ||
<< "SwapDevice: seek file: " << dev_path; | ||
|
||
ssize_t size = std::get<3>(info); | ||
len = write(fd, ptr, size); | ||
NNTR_THROW_IF(len != size, std::runtime_error) | ||
<< "SwapDevice: write file: " << len << "::" << std::to_string(size) | ||
<< dev_path; | ||
} | ||
|
||
ret = munmap(std::get<void *>(info), std::get<size_t>(info)); | ||
const size_t error_buflen = 100; | ||
char error_buf[error_buflen]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.