Skip to content

Commit 364c99d

Browse files
committed
Fix misuse of max_group
1 parent dfea165 commit 364c99d

File tree

9 files changed

+66
-28
lines changed

9 files changed

+66
-28
lines changed

robot_localisation/src/Func.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
extern dsfmt_t dsfmt[NPMax];
1919

2020
/*** FPGA mode: Call SMC core */
21-
void smcFPGA(int NP, float S, int outer_idx, int itl_inner, float* state_in, float* ref_in, float* rand_num, int* seed, float* obsrv_in, float* state_out, max_group_t* engines){
21+
void smcFPGA(int NP, float S, int outer_idx, int itl_inner, float* state_in, float* ref_in, float* rand_num, int* seed, float* obsrv_in, float* state_out, max_group_t* group){
2222

23+
max_engine_t *engines[NBoard];
2324
struct timeval tv1, tv2;
2425
unsigned long long lmem_time, kernel_time, resampling_time;
2526
#if FPGA_resampling==1
@@ -86,22 +87,34 @@ void smcFPGA(int NP, float S, int outer_idx, int itl_inner, float* state_in, flo
8687
#if Use_DRAM==1
8788
// Copy states to LMEM
8889
gettimeofday(&tv1, NULL);
89-
Smc_write_run_group(engines,*actions_write);
90+
for (int i=0; i<NBoard; i++){
91+
engines[i] = max_lock_any(group);
92+
Smc_write_run(engines[i], actions_write[i]);
93+
max_unlock(engines[i]);
94+
}
9095
gettimeofday(&tv2, NULL);
9196
lmem_time = (tv2.tv_sec - tv1.tv_sec)*1000000 + (tv2.tv_usec - tv1.tv_usec);
9297
printf("Copied data to LMEM in %lu us.\n", (long unsigned int)lmem_time);
9398
#endif
9499
// Invoke FPGA kernel
95100
gettimeofday(&tv1, NULL);
96-
Smc_run_group(engines,*actions);
101+
for (int i=0; i<NBoard; i++){
102+
engines[i] = max_lock_any(group);
103+
Smc_run(engines[i], actions[i]);
104+
max_unlock(engines[i]);
105+
}
97106
gettimeofday(&tv2, NULL);
98107
kernel_time = (tv2.tv_sec - tv1.tv_sec)*1000000 + (tv2.tv_usec - tv1.tv_usec);
99108
printf("FPGA kernel finished in %lu us.\n", (long unsigned int)kernel_time);
100109
#if Use_DRAM==1
101110
// Copy states from LMEM
102111
gettimeofday(&tv1, NULL);
103-
Smc_read_run_group(engines,*actions_read);
104-
Smc_read_w_run_group(engines,*actions_read_w);
112+
for (int i=0; i<NBoard; i++){
113+
engines[i] = max_lock_any(group);
114+
Smc_read_run(engines[i], actions_read[i]);
115+
Smc_read_w_run(engines[i], actions_read_w[i]);
116+
max_unlock(engines[i]);
117+
}
105118
gettimeofday(&tv2, NULL);
106119
lmem_time = (tv2.tv_sec - tv1.tv_sec)*1000000 + (tv2.tv_usec - tv1.tv_usec);
107120
printf("Copied data from LMEM in %lu us.\n", (long unsigned int)lmem_time);

robot_localisation/src/Func.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ typedef struct ref_t
2121
float r;
2222
}ref_t;
2323

24-
void smcFPGA(int NP, float S, int outer_idx, int itl_inner, float* state_in, float* ref_in, float* rand_num, int* seed, float* obsrv_in, float* state_out, max_group_t* engines);
24+
void smcFPGA(int NP, float S, int outer_idx, int itl_inner, float* state_in, float* ref_in, float* rand_num, int* seed, float* obsrv_in, float* state_out, max_group_t* group);
2525
void resampleFPGA(int NP, float* state_out, int* index);
2626
void smcCPU(int NP, float S, int outer_idx, int itl_inner, float* state_in, float* ref_in, float* obsrv_in, float* state_out);
2727
float est(float x, float y, float h);

robot_localisation/src/Smc.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ int main(int argc, char *argv[]){
5353
// Load multiple FPGAs
5454
// Mutliple FPGAs mode is only supported when resampling in processed on CPU
5555
max_file_t *maxfile = Smc_init();
56-
//max_engarray_t *engines = max_load_array(maxfile,NBoard,"*");
57-
max_group_t *engines = max_load_group(maxfile, MAXOS_EXCLUSIVE, "group@local:*", NBoard);
56+
max_group_t *group = max_load_group(maxfile, MAXOS_EXCLUSIVE, "group@local:*", NBoard);
5857

5958
for(int t=0; t<NT; t++){
6059
for (int i=0; i<itl_outer; i++) {
@@ -79,7 +78,7 @@ int main(int argc, char *argv[]){
7978
#if Use_FPGA==1
8079
// Invoke FPGA kernel
8180
printf("Calling FPGA kernel...\n");
82-
smcFPGA(NP,S,i,itl_inner,state_in,ref_in,rand_num,seed,obsrv_in,state_out,engines);
81+
smcFPGA(NP,S,i,itl_inner,state_in,ref_in,rand_num,seed,obsrv_in,state_out,group);
8382
#else
8483
printf("Calling CPU function...\n");
8584
smcCPU(NP,S,i,itl_inner,state_in,ref_in,obsrv_in,state_out);
@@ -92,7 +91,7 @@ int main(int argc, char *argv[]){
9291
check(argv[3]);
9392

9493
// Release FPGA resources
95-
max_unload_group(engines);
94+
max_unload_group(group);
9695
max_file_free(maxfile);
9796

9897
free(obsrv);

robot_localisation_with_moving_objects/src/Func.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
extern dsfmt_t dsfmt[NPMax*slotOfP];
1919

2020
/*** FPGA mode: Call SMC core */
21-
void smcFPGA(int NP, int slotOfAllP, float S, int itl_outer, int outer_idx, int itl_inner, float* state_in, float* ref_in, int* seed, float* obsrv_in, float* state_out, float* weightObj, max_group_t* engines){
21+
void smcFPGA(int NP, int slotOfAllP, float S, int itl_outer, int outer_idx, int itl_inner, float* state_in, float* ref_in, int* seed, float* obsrv_in, float* state_out, float* weightObj, max_group_t* group){
2222

23+
max_engine_t *engines[NBoard];
2324
struct timeval tv1, tv2;
2425
unsigned long long lmem_time, kernel_time, resampling_time;
2526

@@ -69,22 +70,34 @@ void smcFPGA(int NP, int slotOfAllP, float S, int itl_outer, int outer_idx, int
6970
#if Use_DRAM==1
7071
// Copy states to LMEM
7172
gettimeofday(&tv1, NULL);
72-
Smc_write_run_group(engines,*actions_write); // for NBoard FPGAs
73+
for (int i=0; i<NBoard; i++){
74+
engines[i] = max_lock_any(group);
75+
Smc_write_run(engines[i], actions_write[i]);
76+
max_unlock(engines[i]);
77+
}
7378
gettimeofday(&tv2, NULL);
7479
lmem_time = (tv2.tv_sec - tv1.tv_sec)*1000000 + (tv2.tv_usec - tv1.tv_usec);
7580
printf("Copied data to LMEM in %lu us.\n", (long unsigned int)lmem_time);
7681
#endif
7782
// Invoke FPGA kernel
7883
gettimeofday(&tv1, NULL);
79-
Smc_run_group(engines,*actions);
84+
for (int i=0; i<NBoard; i++){
85+
engines[i] = max_lock_any(group);
86+
Smc_run(engines[i], actions[i]);
87+
max_unlock(engines[i]);
88+
}
8089
gettimeofday(&tv2, NULL);
8190
kernel_time = (tv2.tv_sec - tv1.tv_sec)*1000000 + (tv2.tv_usec - tv1.tv_usec);
8291
printf("FPGA kernel finished in %lu us.\n", (long unsigned int)kernel_time);
8392
#if Use_DRAM==1
8493
// Copy states from LMEM
8594
gettimeofday(&tv1, NULL);
86-
Smc_read_run_group(engines,*actions_read);
87-
Smc_read_w_run_group(engines,*actions_read_w);
95+
for (int i=0; i<NBoard; i++){
96+
engines[i] = max_lock_any(group);
97+
Smc_read_run(engines[i], actions_read[i]);
98+
Smc_read_w_run(engines[i], actions_read_w[i]);
99+
max_unlock(engines[i]);
100+
}
88101
gettimeofday(&tv2, NULL);
89102
lmem_time = (tv2.tv_sec - tv1.tv_sec)*1000000 + (tv2.tv_usec - tv1.tv_usec);
90103
printf("Copied data from LMEM in %lu us.\n", (long unsigned int)lmem_time);

robot_localisation_with_moving_objects/src/Func.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ typedef struct ref_t
2121
float r;
2222
}ref_t;
2323

24-
void smcFPGA(int NP, int slotOfAllP, float S, int itl_outer, int outer_idx, int itl_inner, float* state_in, float* ref_in, int* seed, float* obsrv_in, float* state_out, float* weightObj, max_group_t* engines);
24+
void smcFPGA(int NP, int slotOfAllP, float S, int itl_outer, int outer_idx, int itl_inner, float* state_in, float* ref_in, int* seed, float* obsrv_in, float* state_out, float* weightObj, max_group_t* group);
2525
void orderParticles(int NP, float* state, float* weightObj);
2626
void reOrderParticles(int NP, float* state);
2727
void resampleFPGA(int NP, float* state_out, int* index);

robot_localisation_with_moving_objects/src/Smc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ int main(int argc, char *argv[]){
4444
// Load multiple FPGAs
4545
max_file_t *maxfile = Smc_init();
4646
//max_engarray_t *engines = max_load_array(maxfile,NBoard,"*");
47-
max_group_t *engines = max_load_group(maxfile, MAXOS_EXCLUSIVE, "group@local:*", NBoard);
47+
max_group_t *group = max_load_group(maxfile, MAXOS_EXCLUSIVE, "group@local:*", NBoard);
4848

4949
for (int cnt=0; cnt<NTest; cnt++){ // Run for ten times to get the average error
5050

@@ -69,7 +69,7 @@ int main(int argc, char *argv[]){
6969
#if NC>1
7070
reOrderParticles(NP, state_in);
7171
#endif
72-
smcFPGA(NP,slotOfAllP,S,itl_outer,i,itl_inner,state_in,ref_in,seed,obsrv_in,state_out,weightObj,engines);
72+
smcFPGA(NP,slotOfAllP,S,itl_outer,i,itl_inner,state_in,ref_in,seed,obsrv_in,state_out,weightObj,group);
7373
#else
7474
printf("Calling CPU function...\n");
7575
smcCPU(NP,slotOfAllP,S,itl_outer,i,itl_inner,state_in,ref_in,obsrv_in,state_out,weightObj);
@@ -83,7 +83,7 @@ int main(int argc, char *argv[]){
8383
check(argv[3], NP, itl_outer);
8484

8585
// Release FPGA resources
86-
max_unload_group(engines);
86+
max_unload_group(group);
8787
max_file_free(maxfile);
8888

8989
free(obsrv);

stochastic_volatility/src/Func.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
extern dsfmt_t dsfmt[NPMax];
2020

2121
/*** FPGA mode: Call SMC core */
22-
void smcFPGA(int NP, float S, int outer_idx, int itl_inner, float* state_in, float* rand_num, int* seed, float* obsrv_in, float* state_out, max_group_t* engines){
22+
void smcFPGA(int NP, float S, int outer_idx, int itl_inner, float* state_in, float* rand_num, int* seed, float* obsrv_in, float* state_out, max_group_t* group){
2323

24+
max_engine_t *engines[NBoard];
2425
struct timeval tv1, tv2;
2526
unsigned long long lmem_time, kernel_time, resampling_time;
2627
#if FPGA_resampling==1
@@ -86,22 +87,34 @@ void smcFPGA(int NP, float S, int outer_idx, int itl_inner, float* state_in, flo
8687
#if Use_DRAM==1
8788
// Copy states to LMEM
8889
gettimeofday(&tv1, NULL);
89-
Smc_write_run_group(engines,*actions_write);
90+
for (int i=0; i<NBoard; i++){
91+
engines[i] = max_lock_any(group);
92+
Smc_write_run(engines[i], actions_write[i]);
93+
max_unlock(engines[i]);
94+
}
9095
gettimeofday(&tv2, NULL);
9196
lmem_time = (tv2.tv_sec - tv1.tv_sec)*1000000 + (tv2.tv_usec - tv1.tv_usec);
9297
printf("Copied data to LMEM in %lu us.\n", (long unsigned int)lmem_time);
9398
#endif
9499
// Invoke FPGA kernel
95100
gettimeofday(&tv1, NULL);
96-
Smc_run_group(engines,*actions);
101+
for (int i=0; i<NBoard; i++){
102+
engines[i] = max_lock_any(group);
103+
Smc_run(engines[i], actions[i]);
104+
max_unlock(engines[i]);
105+
}
97106
gettimeofday(&tv2, NULL);
98107
kernel_time = (tv2.tv_sec - tv1.tv_sec)*1000000 + (tv2.tv_usec - tv1.tv_usec);
99108
printf("FPGA kernel finished in %lu us.\n", (long unsigned int)kernel_time);
100109
#if Use_DRAM==1
101110
// Copy states from LMEM
102111
gettimeofday(&tv1, NULL);
103-
Smc_read_run_group(engines,*actions_read);
104-
Smc_read_w_run_group(engines,*actions_read_w);
112+
for (int i=0; i<NBoard; i++){
113+
engines[i] = max_lock_any(group);
114+
Smc_read_run(engines[i], actions_read[i]);
115+
Smc_read_w_run(engines[i], actions_read_w[i]);
116+
max_unlock(engines[i]);
117+
}
105118
gettimeofday(&tv2, NULL);
106119
lmem_time = (tv2.tv_sec - tv1.tv_sec)*1000000 + (tv2.tv_usec - tv1.tv_usec);
107120
printf("Copied data from LMEM in %lu us.\n", (long unsigned int)lmem_time);

stochastic_volatility/src/Func.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ typedef struct control_t
2121
float r;
2222
}control_t;
2323

24-
void smcFPGA(int NP, float S, int outer_idx, int itl_inner, float* state_in, float* rand_num, int* seed, float* obsrv_in, float* state_out, max_group_t* engines);
24+
void smcFPGA(int NP, float S, int outer_idx, int itl_inner, float* state_in, float* rand_num, int* seed, float* obsrv_in, float* state_out, max_group_t* group);
2525
void resampleFPGA(int NP, float* state_out, int* index);
2626
void smcCPU(int NP, float S, int outer_idx, int itl_inner, float* state_in, float* obsrv_in, float* state_out);
2727
void resampleCPU(int NP, float* state, float* weight, float* weight_sum);

stochastic_volatility/src/Smc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ int main(int argc, char *argv[]){
4444
// Mutliple FPGAs mode is only supported when resampling in processed on CPU
4545
max_file_t *maxfile = Smc_init();
4646
//max_engarray_t *engines = max_load_array(maxfile,NBoard,"*");
47-
max_group_t *engines = max_load_group(maxfile, MAXOS_EXCLUSIVE, "group@local:*", NBoard);
47+
max_group_t *group = max_load_group(maxfile, MAXOS_EXCLUSIVE, "group@local:*", NBoard);
4848

4949
for(int t=0; t<NT; t++){
5050
for (int i=0; i<itl_outer; i++) {
@@ -66,7 +66,7 @@ int main(int argc, char *argv[]){
6666
#if Use_FPGA==1
6767
// Invoke FPGA kernel
6868
printf("Calling FPGA kernel...\n");
69-
smcFPGA(NP,S,i,itl_inner,state_in,rand_num,seed,obsrv_in,state_out,engines);
69+
smcFPGA(NP,S,i,itl_inner,state_in,rand_num,seed,obsrv_in,state_out,group);
7070
#else
7171
printf("Calling CPU function...\n");
7272
smcCPU(NP,S,i,itl_inner,state_in,obsrv_in,state_out);
@@ -79,7 +79,7 @@ int main(int argc, char *argv[]){
7979
check(argv[2]);
8080

8181
// Release FPGA resources
82-
max_unload_group(engines);
82+
max_unload_group(group);
8383
max_file_free(maxfile);
8484

8585
free(obsrv);

0 commit comments

Comments
 (0)