MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / RefPtr

Class RefPtr

dnn/include/megdnn/basic_types.h:409–457  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

407};
408
409class RefPtr {
410 std::shared_ptr<void*> m_ref;
411 size_t m_offset;
412 bool m_mutable;
413
414public:
415 RefPtr() {
416 m_ref = std::make_shared<void*>((void*)nullptr);
417 m_offset = 0;
418 m_mutable = true;
419 }
420
421 RefPtr(void* ref_ptr, const size_t offset = 0) {
422 m_ref = std::make_shared<void*>(ref_ptr);
423 m_offset = offset;
424 m_mutable = true;
425 }
426
427 explicit RefPtr(
428 std::shared_ptr<void*> ref_ptr, const size_t offset = 0,
429 bool is_mutable = true) {
430 m_ref = ref_ptr;
431 m_offset = offset;
432 m_mutable = is_mutable;
433 }
434
435 void* get_ptr() const {
436 return static_cast<void*>(
437 (*m_ref != NULL) ? static_cast<dt_byte*>(*m_ref) + m_offset : nullptr);
438 }
439
440 bool is_mutable() const { return m_mutable; }
441
442 void reset(const void* ptr, size_t offset = 0);
443
444 RefPtr& operator+=(size_t offset) {
445 m_offset += offset;
446 return *this;
447 }
448
449 bool operator==(const RefPtr& other) const {
450 return *m_ref == *other.m_ref && m_offset == other.m_offset;
451 }
452
453 template <typename T>
454 T* ptr() const {
455 return static_cast<T*>(get_ptr());
456 }
457};
458
459/**
460 * \brief A simple encapsulation class for n-dimensional tensor.

Callers 5

kern_fallbackMethod · 0.85
execMethod · 0.85
repMethod · 0.85
TensorNDMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected