@@ -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