aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristofer Jonsson <kristofer.jonsson@arm.com>2020-11-23 16:22:10 +0100
committerKristofer Jonsson <kristofer.jonsson@arm.com>2020-11-25 15:36:20 +0100
commit34e249686923a0299a041fb6af10e56fc9fb76cd (patch)
tree14083b0245c981efa00ffc1041b8721e17b96198
parent2cbaaa9150c3a3c4cff4e15cbe5b7116a133a523 (diff)
downloadethos-u-core-software-34e249686923a0299a041fb6af10e56fc9fb76cd.tar.gz
Improved cache maintenance
Invalidating and cleaning buffers exchanged between Core and remote CPU. Change-Id: Icd9ce6c916422a6bbcdd42e31651a622240d0ce4
-rw-r--r--applications/inference_process/include/inference_process.hpp6
-rw-r--r--applications/inference_process/src/inference_process.cc46
-rw-r--r--applications/message_process/src/message_process.cc4
3 files changed, 55 insertions, 1 deletions
diff --git a/applications/inference_process/include/inference_process.hpp b/applications/inference_process/include/inference_process.hpp
index 53b9331..ec682d1 100644
--- a/applications/inference_process/include/inference_process.hpp
+++ b/applications/inference_process/include/inference_process.hpp
@@ -29,6 +29,9 @@ struct DataPtr {
size_t size;
DataPtr(void *data = nullptr, size_t size = 0);
+
+ void invalidate();
+ void clean();
};
struct InferenceJob {
@@ -46,6 +49,9 @@ struct InferenceJob {
const std::vector<DataPtr> &output,
const std::vector<DataPtr> &expectedOutput,
size_t numBytesToPrint);
+
+ void invalidate();
+ void clean();
};
class InferenceProcess {
diff --git a/applications/inference_process/src/inference_process.cc b/applications/inference_process/src/inference_process.cc
index 7743f8c..61db73d 100644
--- a/applications/inference_process/src/inference_process.cc
+++ b/applications/inference_process/src/inference_process.cc
@@ -87,6 +87,20 @@ bool copyOutput(const TfLiteTensor &src, InferenceProcess::DataPtr &dst) {
namespace InferenceProcess {
DataPtr::DataPtr(void *_data, size_t _size) : data(_data), size(_size) {}
+void DataPtr::invalidate() {
+#if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
+ printf("Invalidate. data=%p, size=%zu\n", data, size);
+ SCB_InvalidateDCache_by_Addr(reinterpret_cast<uint32_t *>(data), size);
+#endif
+}
+
+void DataPtr::clean() {
+#if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
+ printf("Clean. data=%p, size=%zu\n", data, size);
+ SCB_CleanDCache_by_Addr(reinterpret_cast<uint32_t *>(data), size);
+#endif
+}
+
InferenceJob::InferenceJob() : numBytesToPrint(0) {}
InferenceJob::InferenceJob(const string &_name,
@@ -99,6 +113,38 @@ InferenceJob::InferenceJob(const string &_name,
networkModel(_networkModel), input(_input), output(_output), expectedOutput(_expectedOutput),
numBytesToPrint(_numBytesToPrint) {}
+void InferenceJob::invalidate() {
+ networkModel.invalidate();
+
+ for (auto &it : input) {
+ it.invalidate();
+ }
+
+ for (auto &it : output) {
+ it.invalidate();
+ }
+
+ for (auto &it : expectedOutput) {
+ it.invalidate();
+ }
+}
+
+void InferenceJob::clean() {
+ networkModel.clean();
+
+ for (auto &it : input) {
+ it.clean();
+ }
+
+ for (auto &it : output) {
+ it.clean();
+ }
+
+ for (auto &it : expectedOutput) {
+ it.clean();
+ }
+}
+
InferenceProcess::InferenceProcess() : lock(0) {}
// NOTE: Adding code for get_lock & free_lock with some corrections from
diff --git a/applications/message_process/src/message_process.cc b/applications/message_process/src/message_process.cc
index 200d92b..c890399 100644
--- a/applications/message_process/src/message_process.cc
+++ b/applications/message_process/src/message_process.cc
@@ -201,7 +201,7 @@ bool MessageProcess::handleMessage() {
return false;
}
- printf("InferenceReq. user_arg=0x%" PRIx64 ", network={0x%" PRIu32 ", %" PRIu32 "}",
+ printf("InferenceReq. user_arg=0x%" PRIx64 ", network={0x%" PRIx32 ", %" PRIu32 "}",
req.user_arg,
req.network.ptr,
req.network.size);
@@ -241,8 +241,10 @@ bool MessageProcess::handleMessage() {
vector<DataPtr> expectedOutput;
InferenceJob job("job", networkModel, ifm, ofm, expectedOutput, -1);
+ job.invalidate();
bool failed = inferenceProcess.runJob(job);
+ job.clean();
sendInferenceRsp(req.user_arg, job.output, failed);
break;