-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeGenKernelHeaders.hh
50 lines (44 loc) · 1.57 KB
/
CodeGenKernelHeaders.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <cstddef>
#include <fstream>
#include <iostream>
#include <hip/hip_runtime.h>
#include <iomanip>
inline float calculateChecksum(const char* data, std::size_t size) {
float checksum = 0.0f;
for (std::size_t i = 0; i < size; ++i) {
checksum += static_cast<float>(data[i]);
}
return checksum;
}
inline bool loadTraceData(const char* filename, std::size_t offset, std::size_t size, void* dest) {
std::ifstream file(filename, std::ios::binary);
if (!file.is_open()) {
std::cerr << "Failed to open trace file: " << filename << std::endl;
return false;
}
// First seek to the offset in the pre_state data
file.seekg(offset);
if (!file) {
std::cerr << "Failed to seek to offset " << offset << std::endl;
return false;
}
// Read the data directly into the destination
file.read(static_cast<char*>(dest), size);
if (!file) {
std::cerr << "Failed to read " << size << " bytes at offset " << offset << std::endl;
return false;
}
// Calculate and print the checksum
float checksum = calculateChecksum(static_cast<char*>(dest), size);
// std::cout << "Checksum: " << std::hex << std::setprecision(8) << checksum << std::dec << std::endl;
return true;
}
// Add error checking macro
#define CHECK_HIP(cmd) \
do { \
hipError_t error = (cmd); \
if (error != hipSuccess) { \
std::cerr << "HIP error: " << hipGetErrorString(error) << " at " << __FILE__ << ":" << __LINE__ << std::endl; \
return 1; \
} \
} while (0)