-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper_functions.c
More file actions
44 lines (35 loc) · 1.12 KB
/
helper_functions.c
File metadata and controls
44 lines (35 loc) · 1.12 KB
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
#include"helper_functions.h"
void validate(int *a, int *b, int length) {
for (int i = 0; i < length; ++i) {
if (a[i] != b[i]) {
printf("Different value detected at position: %d,"
" expected %d but get %d\n", i, a[i], b[i]);
return;
}
}
printf("Tests PASSED successfully! There is no differences\n");
}
void initialize_data_random(int **data, int data_size) {
static time_t t;
srand((unsigned)time(&t));
*data = (int *)malloc(sizeof(int) * data_size);
for (int i = 0; i < data_size; i++) {
(*data)[i] = rand() % RANDOM_NUMBER_MAX;
}
}
void initialize_data_zero(int **data, int data_size) {
*data = (int *)malloc(sizeof(int) * data_size);
memset(*data, 0, data_size * sizeof(int));
}
void initialize_data_random_cudaMallocHost(int **data, int data_size){
static time_t t;
srand((unsigned) time(&t));
cudaMallocHost((void **)data, sizeof(int) * data_size);
for(int i = 0; i < data_size; i++){
(*data)[i] = rand() % RANDOM_NUMBER_MAX;
}
}
void initialize_data_zero_cudaMallocHost(int **data, int data_size){
cudaMallocHost((void **)data, sizeof(int) * data_size);
memset(*data, 0, data_size*sizeof(int));
}