|
1 | 1 | #include "infinirt_cpu.h" |
| 2 | +#include <chrono> |
2 | 3 | #include <cstdlib> |
3 | 4 | #include <cstring> |
4 | 5 |
|
@@ -34,23 +35,50 @@ infiniStatus_t streamWaitEvent(infinirtStream_t stream, infinirtEvent_t event) { |
34 | 35 | } |
35 | 36 |
|
36 | 37 | infiniStatus_t eventCreate(infinirtEvent_t *event_ptr) { |
37 | | - return INFINI_STATUS_NOT_IMPLEMENTED; |
| 38 | + // For CPU implementation, we use a simple timestamp as event |
| 39 | + auto now = std::chrono::steady_clock::now(); |
| 40 | + auto *timestamp = new std::chrono::steady_clock::time_point(now); |
| 41 | + *event_ptr = timestamp; |
| 42 | + return INFINI_STATUS_SUCCESS; |
| 43 | +} |
| 44 | + |
| 45 | +infiniStatus_t eventCreateWithFlags(infinirtEvent_t *event_ptr, uint32_t flags) { |
| 46 | + // CPU implementation ignores flags for simplicity |
| 47 | + return eventCreate(event_ptr); |
38 | 48 | } |
39 | 49 |
|
40 | 50 | infiniStatus_t eventRecord(infinirtEvent_t event, infinirtStream_t stream) { |
41 | | - return INFINI_STATUS_NOT_IMPLEMENTED; |
| 51 | + // Update the event timestamp |
| 52 | + auto *timestamp = static_cast<std::chrono::steady_clock::time_point *>(event); |
| 53 | + *timestamp = std::chrono::steady_clock::now(); |
| 54 | + return INFINI_STATUS_SUCCESS; |
42 | 55 | } |
43 | 56 |
|
44 | 57 | infiniStatus_t eventQuery(infinirtEvent_t event, infinirtEventStatus_t *status_ptr) { |
45 | | - return INFINI_STATUS_NOT_IMPLEMENTED; |
| 58 | + // CPU events are always complete immediately |
| 59 | + *status_ptr = INFINIRT_EVENT_COMPLETE; |
| 60 | + return INFINI_STATUS_SUCCESS; |
46 | 61 | } |
47 | 62 |
|
48 | 63 | infiniStatus_t eventSynchronize(infinirtEvent_t event) { |
49 | | - return INFINI_STATUS_NOT_IMPLEMENTED; |
| 64 | + // CPU events are synchronized immediately |
| 65 | + return INFINI_STATUS_SUCCESS; |
50 | 66 | } |
51 | 67 |
|
52 | 68 | infiniStatus_t eventDestroy(infinirtEvent_t event) { |
53 | | - return INFINI_STATUS_NOT_IMPLEMENTED; |
| 69 | + auto *timestamp = static_cast<std::chrono::steady_clock::time_point *>(event); |
| 70 | + delete timestamp; |
| 71 | + return INFINI_STATUS_SUCCESS; |
| 72 | +} |
| 73 | + |
| 74 | +infiniStatus_t eventElapsedTime(float *ms_ptr, infinirtEvent_t start, infinirtEvent_t end) { |
| 75 | + auto *start_time = static_cast<std::chrono::steady_clock::time_point *>(start); |
| 76 | + auto *end_time = static_cast<std::chrono::steady_clock::time_point *>(end); |
| 77 | + |
| 78 | + auto duration = std::chrono::duration_cast<std::chrono::microseconds>(*end_time - *start_time); |
| 79 | + *ms_ptr = static_cast<float>(duration.count()) / 1000.0f; // Convert microseconds to milliseconds |
| 80 | + |
| 81 | + return INFINI_STATUS_SUCCESS; |
54 | 82 | } |
55 | 83 |
|
56 | 84 | infiniStatus_t mallocDevice(void **p_ptr, size_t size) { |
|
0 commit comments