Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit 7978347

Browse files
Merge branch 'master' into sarkars/unify_pooling_translate_functions
2 parents 2989bd7 + 40fbf84 commit 7978347

6 files changed

+71
-5
lines changed

Diff for: CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ if (NOT USE_PRE_BUILT_NGRAPH)
239239
ExternalProject_Add(
240240
ext_ngraph
241241
GIT_REPOSITORY https://github.com/NervanaSystems/ngraph
242-
GIT_TAG v0.12.0
242+
GIT_TAG v0.14.0-rc.0
243243
CMAKE_ARGS
244244
-DNGRAPH_DISTRIBUTED_ENABLE=${NGRAPH_DISTRIBUTED_ENABLE}
245245
-DNGRAPH_INSTALL_PREFIX=${NGRAPH_ARTIFACTS_DIR}

Diff for: build_ngtf.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def main():
432432
#-------------------------------
433433

434434
# Component versions
435-
ngraph_version = "v0.12.0"
435+
ngraph_version = "v0.14.0-rc.0"
436436
tf_version = "v1.12.0"
437437

438438
# Default directories
@@ -521,9 +521,9 @@ def main():
521521
ngraph_cmake_flags.extend(["-DCMAKE_BUILD_TYPE=Debug"])
522522

523523
if (arguments.distributed_build):
524-
ngraph_cmake_flags.extend(["-DNGRAPH_DISTRIBUTED_ENABLE=TRUE"])
524+
ngraph_cmake_flags.extend(["-DNGRAPH_DISTRIBUTED_OMPI_ENABLE=TRUE"])
525525
else:
526-
ngraph_cmake_flags.extend(["-DNGRAPH_DISTRIBUTED_ENABLE=FALSE"])
526+
ngraph_cmake_flags.extend(["-DNGRAPH_DISTRIBUTED_OMPI_ENABLE=FALSE"])
527527

528528
build_ngraph("./ngraph", ngraph_cmake_flags, verbosity)
529529

Diff for: src/ngraph_encapsulate_op.cc

+42-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "ngraph_mark_for_clustering.h"
3535
#include "ngraph_utils.h"
3636

37+
#include "ngraph/runtime/backend.hpp"
3738
#include "ngraph/runtime/interpreter/int_backend.hpp"
3839

3940
#if defined NGRAPH_DISTRIBUTED
@@ -262,11 +263,18 @@ class NGraphEncapsulateOp : public OpKernel {
262263
//
263264
// TODO(amprocte): Investigate performance of the compilation cache.
264265
if (it == m_ng_functions.end()) {
266+
// Measure the total memory here first
267+
long vm, rss, vm0, rss0;
268+
269+
MemoryProfile(vm0, rss0);
270+
265271
NGRAPH_VLOG(1) << "Compilation cache miss: " << ctx->op_kernel().name();
266272
OP_REQUIRES_OK(
267273
ctx, Builder::TranslateGraph(input_shapes, static_input_map, &m_graph,
268274
ng_function));
269275

276+
auto function_size = ng_function->get_graph_size() / 1024; // kb unit
277+
270278
// Serialize to nGraph if needed
271279
if (std::getenv("NGRAPH_ENABLE_SERIALIZE") != nullptr) {
272280
std::string file_name =
@@ -282,9 +290,39 @@ class NGraphEncapsulateOp : public OpKernel {
282290
ng_function);
283291
#endif
284292
}
285-
293+
// Evict the cache if the number of elements exceeds 16
294+
const char* m_cache_depth_specified =
295+
std::getenv("NGRAPH_TF_FUNCTION_CACHE_ITEM_DEPTH");
296+
if (m_cache_depth_specified != nullptr) {
297+
NGRAPH_TF_FUNCTION_CACHE_ITEM_DEPTH = atoi(m_cache_depth_specified);
298+
}
299+
if (m_ng_functions.size() >= NGRAPH_TF_FUNCTION_CACHE_ITEM_DEPTH) {
300+
op_backend->remove_compiled_function(m_ng_functions[m_lru.back()]);
301+
m_ng_functions.erase(m_lru.back());
302+
m_lru.pop_back();
303+
}
286304
m_ng_functions[signature] = ng_function;
305+
m_lru.push_front(signature);
306+
// Memory after
307+
MemoryProfile(vm, rss);
308+
auto delta_vm_mem = vm - vm0;
309+
auto delta_res_mem = rss - rss0;
310+
311+
NGRAPH_VLOG(1) << "NGRAPH_TF_CACHE_PROFILE: " << ctx->op_kernel().name()
312+
<< " Step_ID: " << ctx->step_id()
313+
<< " Delta VM: " << delta_vm_mem
314+
<< " Delta RSS: " << delta_res_mem
315+
<< " Function name: " << ng_function->get_name()
316+
<< " Function Memory Measurment: " << function_size
317+
<< " Total RSS in KB: " << rss
318+
<< " Total VM in KB: " << vm
319+
<< " Cache length: " << m_ng_functions.size() << endl;
287320
} else {
321+
// Update the lru list
322+
if (signature != m_lru.front()) {
323+
m_lru.remove(signature);
324+
m_lru.push_front(signature);
325+
}
288326
ng_function = it->second;
289327
}
290328

@@ -465,6 +503,7 @@ class NGraphEncapsulateOp : public OpKernel {
465503
try {
466504
op_backend->call(op_backend->compile(ng_function), ng_outputs,
467505
ng_inputs);
506+
468507
} catch (const std::exception& exp) {
469508
BackendManager::UnlockBackend(m_op_backend_name);
470509
NgraphSerialize(
@@ -541,6 +580,8 @@ class NGraphEncapsulateOp : public OpKernel {
541580
std::vector<bool> m_input_is_static;
542581
std::mutex m_compute_lock;
543582
string m_op_backend_name;
583+
std::list<std::string> m_lru;
584+
int NGRAPH_TF_FUNCTION_CACHE_ITEM_DEPTH = 16;
544585
};
545586

546587
} // namespace ngraph_bridge

Diff for: src/ngraph_mark_for_clustering.cc

+1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ Status MarkForClustering(Graph* graph) {
287287
confirmation_function_map["PreventGradient"] =
288288
SimpleConfirmationFunction();
289289
confirmation_function_map["Prod"] = SimpleConfirmationFunction();
290+
confirmation_function_map["Rank"] = SimpleConfirmationFunction();
290291
confirmation_function_map["QuantizeAndDequantizeV2"] = [](Node* n,
291292
bool* result) {
292293
// accept only when num_bits == 8 and range is given

Diff for: src/ngraph_utils.cc

+21
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,27 @@ void NgraphSerialize(const std::string& file_name,
242242
<< std::endl;
243243
NGRAPH_VLOG(0) << e.what() << std::endl;
244244
}
245+
}
246+
247+
void MemoryProfile(long& vm_usage, long& resident_set) {
248+
vm_usage = 0;
249+
resident_set = 0;
250+
251+
// Get the two fields we want
252+
long vsize;
253+
long rss;
254+
255+
std::ifstream ifs("/proc/self/stat", std::ios_base::in);
256+
std::string mem_in;
257+
getline(ifs, mem_in);
258+
vector<string> mem_str = ng::split(mem_in, ' ');
259+
vsize = std::stol(mem_str[22]);
260+
rss = std::stol(mem_str[23]);
261+
262+
long page_size_kb = sysconf(_SC_PAGE_SIZE) /
263+
1024; // in case x86-64 is configured to use 2MB pages
264+
vm_usage = vsize / 1024; // unit kb
265+
resident_set = rss * page_size_kb;
245266
};
246267

247268
} // namespace ngraph_bridge

Diff for: src/ngraph_utils.h

+3
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ Status CheckAxisDimInRange(std::vector<int64> axes, size_t rank);
202202
void NgraphSerialize(const std::string&,
203203
const std::shared_ptr<ngraph::Function>&);
204204

205+
// Collect the total memory usage through /proc/self/stat
206+
void MemoryProfile(long&, long&);
207+
205208
} // namespace ngraph_bridge
206209

207210
} // namespace tensorflow

0 commit comments

Comments
 (0)