aboutsummaryrefslogtreecommitdiffstats
path: root/include/nvgpu/linux/lock.h
diff options
context:
space:
mode:
authorJoshua Bakita <jbakita@cs.unc.edu>2024-11-04 11:28:21 -0500
committerJoshua Bakita <jbakita@cs.unc.edu>2024-11-04 11:28:21 -0500
commit6143114460e5125621747cde2f712fed445b9a15 (patch)
tree14465bb256527e958766140bcc6811dd597cfe99 /include/nvgpu/linux/lock.h
parentf347fde22f1297e4f022600d201780d5ead78114 (diff)
Fix a critical regression in 71be6bb5 causing multiple API failuresjbakita-wip
Instead of printing the read in `nvdebug_reg32_read()`, another read was being performed, using the first read value as the register offset! This is a mistaken incomplete removal of the old pre-error- -handling logic in 71be6bb5. This caused any APIs using this function to not work by returning bizzare or incorrect values, or crashing the system on Jetson boards.
Diffstat (limited to 'include/nvgpu/linux/lock.h')
0 files changed, 0 insertions, 0 deletions
d='n98' href='#n98'>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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
/*

  This program is part of the TACLeBench benchmark suite.
  Version V 2.0

  Name: audiobeam

  Author: Eugene Weinstein

  Function: Audio beam former

  Source: StreamIt
          http://groups.csail.mit.edu/cag/streamit/

  Changes: no functional changes

  License: see license.txt

*/


/*
  Include section
*/

#include "extra.h"
#include "audiobeamlibm.h"
#include "audiobeamlibmalloc.h"
#include "audiobeam.h"

/*
  Forward declaration of functions
*/

void audiobeam_init();
int audiobeam_return();
void audiobeam_main( void );
//int main( void );
void audiobeam_preprocess_delays( struct audiobeam_PreprocessedDelays
                                  prep_delays[], float *delays );
float *audiobeam_parse_line( float *float_arr, int num_mic );
long int audiobeam_find_max_in_arr( float *arr, int size );
long int audiobeam_find_min_in_arr( float *arr, int size );
int audiobeam_wrapped_inc_offset( int i, int offset, int max_i );
int audiobeam_wrapped_dec_offset( int i, int offset, int max_i );
int audiobeam_wrapped_inc( int i, int max_i );
int audiobeam_wrapped_dec( int i, int max_i );
struct audiobeam_DataQueue *audiobeam_init_data_queue( int max_delay,
    int num_mic );
struct audiobeam_Delays *audiobeam_init_delays ( int num_angles, int num_mic );
void audiobeam_calc_distances( float *source_location,
                               float audiobeam_mic_locations[15][3],
                               float *distances,
                               int num_mic );
void audiobeam_calc_delays( float *distances, float *delays, int sound_speed,
                            int sampling_rate, int num_mic );
void audiobeam_adjust_delays( float *delays, int num_mic );
float *audiobeam_calc_weights_lr ( int num_mic );
float *audiobeam_calc_weights_left_only ( int num_mic );
float audiobeam_calculate_energy( float *samples, int num_samples );
float audiobeam_do_beamforming( struct audiobeam_PreprocessedDelays
                                preprocessed_delays[],
                                float **sample_queue,
                                int queue_head,
                                long int max_delay,
                                int num_mic,
                                float *weights );
int audiobeam_process_signal( struct audiobeam_Delays *delays, int num_mic,
                              float sampling_rate, float **beamform_results,
                              struct audiobeam_DataQueue *queue,
                              int num_beams, int window, float *weights );
int audiobeam_calc_beamforming_result( struct audiobeam_Delays *delays,
                                       float **beamform_results,
                                       float *energies,
                                       struct audiobeam_DataQueue *queue,
                                       int num_beams, int window,
                                       int hamming );
void audiobeam_calc_single_pos( float source_location[3],
                                float audiobeam_mic_locations[15][3],
                                int hamming );


/*
  Declaration of global variables
*/

extern float audiobeam_input[5760];
extern float audiobeam_mic_locations[15][3];
extern float audiobeam_source_location[3];
extern float audiobeam_origin_location[3];
int audiobeam_input_pos;
int audiobeam_checksum;


/*
  Initialization- and return-value-related functions
*/

void audiobeam_init()
{
  audiobeam_input_pos = 0;
  audiobeam_checksum = 0;

  unsigned int i;
  unsigned char *p;
  volatile char bitmask = 0;

  /*
    Apply volatile XOR-bitmask to entire input array.
  */
  p = ( unsigned char * ) &audiobeam_input[ 0 ];
  _Pragma( "loopbound min 23040 max 23040" )
  for ( i = 0; i < sizeof( audiobeam_input ); ++i, ++p )
    *p ^= bitmask;

  p = ( unsigned char * ) &audiobeam_mic_locations[ 0 ];
  _Pragma( "loopbound min 180 max 180" )
  for ( i = 0; i < sizeof( audiobeam_mic_locations ); ++i, ++p )
    *p ^= bitmask;

  p = ( unsigned char * ) &audiobeam_source_location[ 0 ];
  _Pragma( "loopbound min 12 max 12" )
  for ( i = 0; i < sizeof( audiobeam_source_location ); ++i, ++p )
    *p ^= bitmask;

  p = ( unsigned char * ) &audiobeam_origin_location[ 0 ];
  _Pragma( "loopbound min 12 max 12" )
  for ( i = 0; i < sizeof( audiobeam_origin_location ); ++i, ++p )
    *p ^= bitmask;
}


int audiobeam_return()
{
  return ( audiobeam_checksum +1!= 0 );
}


/*
  Algorithm core functions
*/

void audiobeam_preprocess_delays( struct audiobeam_PreprocessedDelays
                                  prep_delays[], float *delays )
{
  int i;

  _Pragma( "loopbound min 15 max 15" )
  for ( i = 0; i < 15; i++ ) {
    prep_delays[i].delay = delays[i];
    prep_delays[i].high = ( int ) audiobeam_ceil( delays[i] );
    prep_delays[i].low = ( int ) audiobeam_floor( delays[i] );
    prep_delays[i].offset = delays[i] - prep_delays[i].low;
  }
}


float *audiobeam_parse_line( float *float_arr, int num_mic )
{
  int i;

  _Pragma( "loopbound min 15 max 15" )
  for ( i = 0; i < num_mic; i++ )
    float_arr[i] = audiobeam_input[audiobeam_input_pos++];

  return float_arr;
}


long int audiobeam_find_max_in_arr( float *arr, int size )
{
  int i;
  float max = 0;

  _Pragma( "loopbound min 15 max 15" )
  for ( i = 0; i < size; i++ ) {
    if ( arr[i] > max )
      max = arr[i];
  }

  return audiobeam_ceil( max );
}


long int audiobeam_find_min_in_arr( float *arr, int size )
{
  int i;
  float min = arr[0];

  _Pragma( "loopbound min 15 max 15" )
  for ( i = 0; i < size; i++ ) {
    if ( arr[i] < min )
      min = arr[i];
  }

  return audiobeam_floor( min );
}


int audiobeam_wrapped_inc_offset( int i, int offset, int max_i )
{
  if ( i + offset > max_i )
    return ( i + offset - max_i - 1 );
  else
    return ( i + offset );
}


int audiobeam_wrapped_dec_offset( int i, int offset, int max_i )
{
  if ( i - offset < 0 )
    return ( max_i - ( offset - i ) + 1 );
  else
    return ( i - offset );
}


int audiobeam_wrapped_inc( int i, int max_i )
{
  return audiobeam_wrapped_inc_offset( i, 1, max_i );
}


int audiobeam_wrapped_dec( int i, int max_i )
{
  return audiobeam_wrapped_dec_offset( i, 1, max_i );
}


struct audiobeam_DataQueue *audiobeam_init_data_queue( int max_delay,
    int num_mic )
{
  int i, j;

  struct audiobeam_DataQueue *queue;
  queue = ( struct audiobeam_DataQueue * ) audiobeam_malloc( sizeof(
            struct audiobeam_DataQueue ) );
  queue->sample_queue = ( float ** ) audiobeam_malloc( ( max_delay + 1 )
                        * sizeof( float * ) );

  _Pragma( "loopbound min 15 max 15" )
  for ( i = 0; i < ( max_delay + 1 ); i++ ) {
    ( queue->sample_queue )[i] = ( float * ) audiobeam_malloc( num_mic
                                 * sizeof( float ) );
    _Pragma( "loopbound min 15 max 15" )
    for ( j = 0; j < num_mic; j++ ) {
      ( queue->sample_queue )[i][j] = 0.0; // Initialize values to 0
    }
  }

  queue->head = 0;
  queue->tail = 0;
  queue->full = 0;

  return queue;
}


struct audiobeam_Delays *audiobeam_init_delays ( int num_angles, int num_mic )
{
  struct audiobeam_Delays *delays;
  int i;

  delays = ( struct audiobeam_Delays * ) audiobeam_malloc( sizeof(
             struct audiobeam_Delays ) );

  // Initialize the delays array
  delays->delay_values = ( float ** ) audiobeam_malloc( num_angles
                         * sizeof( float * ) );

  _Pragma( "loopbound min 1 max 1" )
  for ( i = 0; i < ( num_angles ); i++ ) {
    delays->delay_values[i] = ( float * ) audiobeam_malloc( num_mic
                              * sizeof( float ) );
  }

  return delays;
}

void audiobeam_calc_distances( float *source_location,
                               float audiobeam_mic_locations[15][3],
                               float *distances,
                               int num_mic )
{
  int i;

  _Pragma( "loopbound min 15 max 15" )