Skip to content

Commit a3e56c3

Browse files
committed
remote stash
Signed-off-by: Ceng23333 <[email protected]>
1 parent d87d536 commit a3e56c3

File tree

13 files changed

+49
-49
lines changed

13 files changed

+49
-49
lines changed

include/infinicore/context/context.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ infiniopHandle_t getInfiniopHandle();
2121
void syncStream();
2222
void syncDevice();
2323

24-
std::shared_ptr<Memory> allocateMemory(size_t size);
25-
std::shared_ptr<Memory> allocateHostMemory(size_t size);
26-
std::shared_ptr<Memory> allocatePinnedHostMemory(size_t size);
24+
std::shared_ptr<MemoryBlock> allocateMemory(size_t size);
25+
std::shared_ptr<MemoryBlock> allocateHostMemory(size_t size);
26+
std::shared_ptr<MemoryBlock> allocatePinnedHostMemory(size_t size);
2727

2828
void memcpyH2D(void *dst, const void *src, size_t size);
2929
void memcpyD2H(void *dst, const void *src, size_t size);

include/infinicore/memory.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
#include "memory/memory_block.hpp"
44
#include "memory/memory_pool.hpp"
5-
#include "memory/stats.hpp"
5+
#include "memory/memory_segment.hpp"

include/infinicore/memory/memory_block.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88

99
namespace infinicore {
1010

11-
class Memory {
11+
class MemoryBlock {
1212
public:
1313
using Deleter = std::function<void(std::byte *)>;
1414

15-
Memory(std::byte *data, size_t size, Device device, Deleter deleter, bool pin_memory = false);
16-
~Memory();
15+
MemoryBlock(std::byte *data, size_t size, Device device, Deleter deleter, bool pin_memory = false);
16+
~MemoryBlock();
1717

1818
// Copy constructor and copy assignment with reference counting
19-
Memory(const Memory& other);
20-
Memory& operator=(const Memory& other);
19+
MemoryBlock(const MemoryBlock& other);
20+
MemoryBlock& operator=(const MemoryBlock& other);
2121

2222
// Move constructor and move assignment
23-
Memory(Memory&& other) noexcept;
24-
Memory& operator=(Memory&& other) noexcept;
23+
MemoryBlock(MemoryBlock&& other) noexcept;
24+
MemoryBlock& operator=(MemoryBlock&& other) noexcept;
2525

2626
std::byte *data() const;
2727
Device device() const;
File renamed without changes.

include/infinicore/tensor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct TensorMetaData {
3232

3333
struct TensorData {
3434
size_t offset;
35-
std::shared_ptr<Memory> memory;
35+
std::shared_ptr<MemoryBlock> memory;
3636
};
3737

3838
struct TensorSliceParams {

src/infinicore-test/memory_test.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,12 @@ TestResult ConcurrencyTest::testMemoryAllocationRace() {
244244
std::vector<std::thread> threads;
245245
std::atomic<int> success_count{0};
246246
std::atomic<int> failure_count{0};
247-
std::vector<Memory> all_allocations;
247+
std::vector<MemoryBlock> all_allocations;
248248
std::mutex allocations_mutex;
249249

250250
for (int i = 0; i < num_threads; ++i) {
251251
threads.emplace_back([&, i]() {
252-
std::vector<Memory> thread_allocations;
252+
std::vector<MemoryBlock> thread_allocations;
253253
try {
254254
for (int j = 0; j < allocations_per_thread; ++j) {
255255
size_t size = 64 + (j % 1024);
@@ -373,7 +373,7 @@ TestResult ExceptionSafetyTest::testDeallocationException() {
373373
return measureTime("DeallocationException", [this]() -> bool {
374374
try {
375375
// Test that deallocation doesn't throw exceptions
376-
std::vector<std::shared_ptr<Memory>> memories;
376+
std::vector<std::shared_ptr<MemoryBlock>> memories;
377377

378378
// Allocate some memory
379379
for (int i = 0; i < 10; ++i) {
@@ -468,7 +468,7 @@ TestResult MemoryLeakTest::testBasicLeakDetection() {
468468
MemoryLeakDetector::instance().reset();
469469

470470
// Allocate and deallocate memory
471-
std::vector<std::shared_ptr<Memory>> memories;
471+
std::vector<std::shared_ptr<MemoryBlock>> memories;
472472
for (int i = 0; i < 100; ++i) {
473473
auto memory = context::allocateMemory(1024);
474474
if (memory) {
@@ -549,7 +549,7 @@ TestResult MemoryLeakTest::testExceptionLeakDetection() {
549549
return measureTime("ExceptionLeakDetection", [this]() -> bool {
550550
try {
551551
// Test that exceptions don't cause memory leaks
552-
std::vector<std::shared_ptr<Memory>> memories;
552+
std::vector<std::shared_ptr<MemoryBlock>> memories;
553553

554554
try {
555555
// Allocate some memory
@@ -624,7 +624,7 @@ TestResult PerformanceTest::testAllocationPerformance() {
624624

625625
auto start = std::chrono::high_resolution_clock::now();
626626

627-
std::vector<std::shared_ptr<Memory>> memories;
627+
std::vector<std::shared_ptr<MemoryBlock>> memories;
628628
for (int i = 0; i < num_allocations; ++i) {
629629
auto memory = context::allocateMemory(allocation_size);
630630
if (memory) {
@@ -784,7 +784,7 @@ TestResult StressTest::testHighFrequencyAllocations() {
784784
return measureTime("HighFrequencyAllocations", [this]() -> bool {
785785
try {
786786
const int num_allocations = iterations_;
787-
std::vector<std::shared_ptr<Memory>> memories;
787+
std::vector<std::shared_ptr<MemoryBlock>> memories;
788788
memories.reserve(num_allocations);
789789

790790
auto start = std::chrono::high_resolution_clock::now();
@@ -825,7 +825,7 @@ TestResult StressTest::testLargeMemoryAllocations() {
825825
const size_t large_size = 100 * 1024 * 1024; // 100MB
826826
const int num_allocations = 10;
827827

828-
std::vector<std::shared_ptr<Memory>> memories;
828+
std::vector<std::shared_ptr<MemoryBlock>> memories;
829829

830830
for (int i = 0; i < num_allocations; ++i) {
831831
try {
@@ -871,7 +871,7 @@ TestResult StressTest::testCrossDeviceStress() {
871871
}
872872

873873
const int num_operations = 1000;
874-
std::vector<std::shared_ptr<Memory>> pinned_memories;
874+
std::vector<std::shared_ptr<MemoryBlock>> pinned_memories;
875875

876876
for (int i = 0; i < num_operations; ++i) {
877877
// Switch to random device

src/infinicore/context/context_impl.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void syncDevice() {
153153
return ContextImpl::singleton().getCurrentRuntime()->syncDevice();
154154
}
155155

156-
std::shared_ptr<Memory> allocateMemory(size_t size) {
156+
std::shared_ptr<MemoryBlock> allocateMemory(size_t size) {
157157
spdlog::debug("context::allocateMemory() called for size={}", size);
158158
auto runtime = ContextImpl::singleton().getCurrentRuntime();
159159
spdlog::debug("Current runtime device: {}", runtime->device().toString());
@@ -162,14 +162,14 @@ std::shared_ptr<Memory> allocateMemory(size_t size) {
162162
return memory;
163163
}
164164

165-
std::shared_ptr<Memory> allocateHostMemory(size_t size) {
165+
std::shared_ptr<MemoryBlock> allocateHostMemory(size_t size) {
166166
spdlog::debug("context::allocateHostMemory() called for size={}", size);
167167
auto memory = ContextImpl::singleton().getCpuRuntime()->allocateMemory(size);
168168
spdlog::debug("context::allocateHostMemory() returned memory={}", static_cast<void *>(memory.get()));
169169
return memory;
170170
}
171171

172-
std::shared_ptr<Memory> allocatePinnedHostMemory(size_t size) {
172+
std::shared_ptr<MemoryBlock> allocatePinnedHostMemory(size_t size) {
173173
spdlog::debug("context::allocatePinnedHostMemory() called for size={}", size);
174174
auto memory = ContextImpl::singleton().getCurrentRuntime()->allocatePinnedHostMemory(size);
175175
spdlog::debug("context::allocatePinnedHostMemory() returned memory={}", static_cast<void *>(memory.get()));

src/infinicore/context/runtime/runtime.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,22 @@ void Runtime::syncDevice() {
5454
INFINICORE_CHECK_ERROR(infinirtDeviceSynchronize());
5555
}
5656

57-
std::shared_ptr<Memory> Runtime::allocateMemory(size_t size) {
57+
std::shared_ptr<MemoryBlock> Runtime::allocateMemory(size_t size) {
5858
std::byte *data_ptr = device_memory_allocator_->allocate(size);
59-
return std::make_shared<Memory>(
59+
return std::make_shared<MemoryBlock>(
6060
data_ptr, size, device_,
6161
[alloc = device_memory_allocator_.get()](std::byte *p) {
6262
alloc->deallocate(p);
6363
});
6464
}
6565

66-
std::shared_ptr<Memory> Runtime::allocatePinnedHostMemory(size_t size) {
66+
std::shared_ptr<MemoryBlock> Runtime::allocatePinnedHostMemory(size_t size) {
6767
if (!pinned_host_memory_allocator_) {
6868
spdlog::warn("For CPU devices, pinned memory is not supported, falling back to regular host memory");
6969
return allocateMemory(size);
7070
}
7171
std::byte *data_ptr = pinned_host_memory_allocator_->allocate(size);
72-
return std::make_shared<Memory>(
72+
return std::make_shared<MemoryBlock>(
7373
data_ptr, size, device_,
7474
[alloc = pinned_host_memory_allocator_.get()](std::byte *p) {
7575
alloc->deallocate(p);

src/infinicore/context/runtime/runtime.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class Runtime {
3131
void syncStream();
3232
void syncDevice();
3333

34-
std::shared_ptr<Memory> allocateMemory(size_t size);
35-
std::shared_ptr<Memory> allocatePinnedHostMemory(size_t size);
34+
std::shared_ptr<MemoryBlock> allocateMemory(size_t size);
35+
std::shared_ptr<MemoryBlock> allocatePinnedHostMemory(size_t size);
3636

3737
void memcpyH2D(void *dst, const void *src, size_t size);
3838
void memcpyD2H(void *dst, const void *src, size_t size);

src/infinicore/memory.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
#include "spdlog/spdlog.h"
44
namespace infinicore {
55

6-
Memory::Memory(std::byte *data,
6+
MemoryBlock::MemoryBlock(std::byte *data,
77
size_t size,
88
Device device,
9-
Memory::Deleter deleter,
9+
MemoryBlock::Deleter deleter,
1010
bool pin_memory)
1111
: data_{data}, size_{size}, device_{device}, deleter_{deleter}, is_pinned_(pin_memory) {
1212
// Register this memory allocation in the pool
@@ -15,7 +15,7 @@ Memory::Memory(std::byte *data,
1515
static_cast<void *>(data), device.toString());
1616
}
1717

18-
Memory::~Memory() {
18+
MemoryBlock::~MemoryBlock() {
1919
if (data_ && deleter_) {
2020
spdlog::debug("Memory::~Memory() called for memory={} at Device: {}",
2121
static_cast<void *>(data_), device_.toString());
@@ -24,7 +24,7 @@ Memory::~Memory() {
2424
}
2525
}
2626

27-
Memory::Memory(const Memory &other)
27+
MemoryBlock::MemoryBlock(const MemoryBlock &other)
2828
: data_{other.data_}, size_{other.size_}, device_{other.device_},
2929
deleter_{other.deleter_}, is_pinned_{other.is_pinned_} {
3030
if (data_) {
@@ -34,7 +34,7 @@ Memory::Memory(const Memory &other)
3434
}
3535
}
3636

37-
Memory &Memory::operator=(const Memory &other) {
37+
MemoryBlock &MemoryBlock::operator=(const MemoryBlock &other) {
3838
if (this != &other) {
3939
// Release current memory if it exists
4040
if (data_ && deleter_) {
@@ -59,7 +59,7 @@ Memory &Memory::operator=(const Memory &other) {
5959
return *this;
6060
}
6161

62-
Memory::Memory(Memory &&other) noexcept
62+
MemoryBlock::MemoryBlock(MemoryBlock &&other) noexcept
6363
: data_{other.data_}, size_{other.size_}, device_{other.device_},
6464
deleter_{std::move(other.deleter_)}, is_pinned_{other.is_pinned_} {
6565
// Clear the moved-from object to prevent double-free
@@ -68,7 +68,7 @@ Memory::Memory(Memory &&other) noexcept
6868
spdlog::debug("Memory::Memory(Memory&&) move constructor called");
6969
}
7070

71-
Memory &Memory::operator=(Memory &&other) noexcept {
71+
MemoryBlock &MemoryBlock::operator=(MemoryBlock &&other) noexcept {
7272
if (this != &other) {
7373
// Release current memory if it exists
7474
if (data_ && deleter_) {
@@ -91,19 +91,19 @@ Memory &Memory::operator=(Memory &&other) noexcept {
9191
return *this;
9292
}
9393

94-
std::byte *Memory::data() const {
94+
std::byte *MemoryBlock::data() const {
9595
return data_;
9696
}
9797

98-
Device Memory::device() const {
98+
Device MemoryBlock::device() const {
9999
return device_;
100100
}
101101

102-
size_t Memory::size() const {
102+
size_t MemoryBlock::size() const {
103103
return size_;
104104
}
105105

106-
bool Memory::is_pinned() const {
106+
bool MemoryBlock::is_pinned() const {
107107
return is_pinned_;
108108
}
109109
} // namespace infinicore

0 commit comments

Comments
 (0)