Skip to content

Commit 8014f24

Browse files
committed
issue/506 add test case for TensorMetaData Desconstructor
Signed-off-by: Ceng23333 <441651826@qq.com>
1 parent 60d9430 commit 8014f24

6 files changed

Lines changed: 370 additions & 16 deletions

File tree

src/infinicore-test/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ xmake build infinicore-test
6464
./infinicore-test --moore
6565
./infinicore-test --iluvatar
6666
./infinicore-test --kunlun
67-
./infinicore-test --sugon
67+
./infinicore-test --hygon
6868
```
6969

7070
### Customize Test Parameters

src/infinicore-test/main.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "memory_test.h"
2+
#include "test_tensor_destructor.h"
23
#include <iostream>
34
#include <memory>
45
#include <spdlog/spdlog.h>
@@ -36,7 +37,7 @@ void printUsage() {
3637
<< " moore" << std::endl
3738
<< " iluvatar" << std::endl
3839
<< " kunlun" << std::endl
39-
<< " sugon" << std::endl
40+
<< " hygon" << std::endl
4041
<< std::endl
4142
<< "Available tests:" << std::endl
4243
<< " basic - Basic memory allocation and deallocation tests" << std::endl
@@ -74,8 +75,8 @@ ParsedArgs parseArgs(int argc, char *argv[]) {
7475
args.device_type = INFINI_DEVICE_ILUVATAR;
7576
} else if (arg == "--kunlun") {
7677
args.device_type = INFINI_DEVICE_KUNLUN;
77-
} else if (arg == "--sugon") {
78-
args.device_type = INFINI_DEVICE_SUGON;
78+
} else if (arg == "--hygon") {
79+
args.device_type = INFINI_DEVICE_HYGON;
7980
} else if (arg == "--test") {
8081
if (i + 1 >= argc) {
8182
std::cerr << "Error: --test requires a test name" << std::endl;
@@ -164,6 +165,10 @@ int main(int argc, char *argv[]) {
164165
spdlog::debug("Adding BasicMemoryTest");
165166
runner.addTest(std::make_unique<infinicore::test::BasicMemoryTest>());
166167
spdlog::debug("BasicMemoryTest added successfully");
168+
169+
spdlog::debug("Adding TensorDestructorTest");
170+
runner.addTest(std::make_unique<infinicore::test::TensorDestructorTest>());
171+
spdlog::debug("TensorDestructorTest added successfully");
167172
}
168173

169174
if (args.run_concurrency) {

src/infinicore-test/memory_test.cc

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,35 @@ TestResult BasicMemoryTest::run() {
3030
spdlog::debug("BasicMemoryTest: Testing memory access");
3131
// Test memory access
3232
std::byte *data = memory->data();
33-
spdlog::debug("BasicMemoryTest: Got memory data pointer");
33+
spdlog::debug("BasicMemoryTest: Got memory data pointer: {}", static_cast<void *>(data));
3434
if (!data) {
3535
std::cerr << "Memory data pointer is null" << std::endl;
3636
return false;
3737
}
3838
spdlog::debug("BasicMemoryTest: Memory data pointer is valid");
3939

40-
spdlog::debug("BasicMemoryTest: Testing memory write/read");
41-
// Test memory write/read
42-
std::memset(data, 0xAB, 1024);
43-
spdlog::debug("BasicMemoryTest: Memory memset completed");
44-
for (size_t i = 0; i < 1024; ++i) {
45-
if (data[i] != static_cast<std::byte>(0xAB)) {
46-
std::cerr << "Memory write/read test failed at index " << i << std::endl;
47-
return false;
40+
// Check if this is GPU memory that can't be accessed directly
41+
Device current_device = context::getDevice();
42+
spdlog::debug("BasicMemoryTest: Current device type: {}", static_cast<int>(current_device.getType()));
43+
spdlog::debug("BasicMemoryTest: Memory is pinned: {}", memory->is_pinned());
44+
45+
// For GPU memory, we shouldn't try to access it directly with memset
46+
if (current_device.getType() != Device::Type::CPU) {
47+
spdlog::debug("BasicMemoryTest: Skipping direct memory access for GPU device");
48+
spdlog::debug("BasicMemoryTest: GPU memory access test completed (skipped)");
49+
} else {
50+
spdlog::debug("BasicMemoryTest: Testing memory write/read");
51+
// Test memory write/read
52+
std::memset(data, 0xAB, 1024);
53+
spdlog::debug("BasicMemoryTest: Memory memset completed");
54+
for (size_t i = 0; i < 1024; ++i) {
55+
if (data[i] != static_cast<std::byte>(0xAB)) {
56+
std::cerr << "Memory write/read test failed at index " << i << std::endl;
57+
return false;
58+
}
4859
}
60+
spdlog::debug("BasicMemoryTest: Memory write/read test completed");
4961
}
50-
spdlog::debug("BasicMemoryTest: Memory write/read test completed");
5162

5263
spdlog::debug("BasicMemoryTest: Testing pinned memory allocation");
5364
// Test pinned memory allocation
@@ -60,8 +71,8 @@ TestResult BasicMemoryTest::run() {
6071

6172
spdlog::debug("BasicMemoryTest: Checking pinned memory properties");
6273
// For CPU devices, pinned memory falls back to regular memory, so it may not be marked as pinned
63-
Device current_device = context::getDevice();
64-
if (current_device.getType() != Device::Type::CPU && !pinned_memory->is_pinned()) {
74+
Device pinned_device = context::getDevice();
75+
if (pinned_device.getType() != Device::Type::CPU && !pinned_memory->is_pinned()) {
6576
std::cerr << "Pinned memory not marked as pinned" << std::endl;
6677
return false;
6778
}

0 commit comments

Comments
 (0)