-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsa_batch.c
174 lines (140 loc) · 3.88 KB
/
dsa_batch.c
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <dml/dml.h>
#include <libpmem2.h>
int main(int argc, char **argv) {
if (argc < 2) {
fprintf(stderr, "usage: dsa_batch <file>");
exit(-1);
}
char *file = argv[1];
printf("file: %s\n", file);
int n_vals = 8;
int buf_alloc_size = sizeof(char) * n_vals;
char *buf = malloc(buf_alloc_size);
memset(buf, 9, n_vals);
unsigned complete = 0;
struct pmem2_source *src;
struct pmem2_config *cfg;
struct pmem2_map *map;
int fd = open(file, O_RDWR | O_CREAT, S_IRUSR | S_IRGRP | S_IROTH);
if (fd < 0) {
perror("open");
return errno;
}
int ret = ftruncate(fd, sizeof(buf));
if (ret == -1) {
perror("ftruncate");
return errno;
}
/* PMEM2 */
ret = pmem2_source_from_fd(&src, fd);
if (ret) {
pmem2_perror("pmem2_source_from_fd");
return ret;
}
ret = pmem2_config_new(&cfg);
if (ret) {
pmem2_perror("pmem2_config_new");
return ret;
}
ret = pmem2_config_set_required_store_granularity(cfg,
PMEM2_GRANULARITY_CACHE_LINE);
if (ret) {
pmem2_perror("pmem2_config_set_required_store_granularity");
return ret;
}
ret = pmem2_map_new(&map, cfg, src);
if (ret) {
pmem2_perror("pmem2_map_new");
return ret;
}
void *map_addr = pmem2_map_get_address(map);
size_t map_size = pmem2_map_get_size(map);
/* DML */
dml_status_t status;
uint32_t job_size_ptr;
dml_job_t *dml_job_ptr;
status = dml_get_job_size(DML_PATH_HW, &job_size_ptr);
if (status != DML_STATUS_OK) {
fprintf(stderr, "dml_get_job_size error: %d", status);
return status;
}
dml_job_ptr = (dml_job_t *)malloc(job_size_ptr);
status = dml_init_job(DML_PATH_HW, dml_job_ptr);
if (status != DML_STATUS_OK) {
fprintf(stderr, "dml_init_job error: %d", status);
return status;
}
uint32_t operations_count = 2;
uint32_t batch_buffer_length = 0;
status = dml_get_batch_size(dml_job_ptr, operations_count, &batch_buffer_length);
if (status != DML_STATUS_OK) {
fprintf(stderr, "dml_get_batch_size error: %d", status);
return status;
}
uint8_t * batch_buffer_ptr = (uint8_t *) malloc(batch_buffer_length);
dml_job_ptr->operation = DML_OP_BATCH;
dml_job_ptr->destination_first_ptr = batch_buffer_ptr;
dml_job_ptr->destination_length = batch_buffer_length;
status = dml_batch_set_mem_move_by_index(dml_job_ptr, 0, (uint8_t *)buf,
(uint8_t *)map_addr,
buf_alloc_size, 0);
if (status != DML_STATUS_OK) {
fprintf(stderr, "dml_batch_set_mem_move_by_index error: %d", status);
return status;
}
uint8_t fill = 1;
status = dml_batch_set_fill_by_index(dml_job_ptr, 1, &fill, (uint8_t *)&complete, sizeof(uint8_t), 0);
if (status != DML_STATUS_OK) {
fprintf(stderr, "dml_batch_set_fill_by_index error: %d", status);
return status;
}
status = dml_submit_job(dml_job_ptr);
if (status != DML_STATUS_OK) {
fprintf(stderr, "dml_execute_job error: %d", status);
return status;
}
status = dml_check_job(dml_job_ptr);
printf("dml_check_job status: %d\n", status);
dml_wait_job(dml_job_ptr);
status = dml_check_job(dml_job_ptr);
printf("dml_check_job status: %d\n", status);
/* validation */
for (int i = 0; i < n_vals; i++) {
printf("dst[%d]: %d\n", i, ((char *)map_addr)[i]);
}
printf("complete: %d\n", complete);
/* cleanup */
status = dml_finalize_job(dml_job_ptr);
if (status != DML_STATUS_OK) {
fprintf(stderr, "dml_finalize_job error: %d", status);
return status;
}
ret = pmem2_map_delete(&map);
if (ret) {
pmem2_perror("pmem2_map_delete");
return ret;
}
ret = pmem2_config_delete(&cfg);
if (ret) {
pmem2_perror("pmem2_config_delete");
return ret;
}
ret = pmem2_source_delete(&src);
if (ret) {
pmem2_perror("pmem2_source_delete");
return ret;
}
ret = close(fd);
if (ret == -1) {
perror("close");
return errno;
}
free(buf);
return 0;
}