aboutsummaryrefslogblamecommitdiffstats
path: root/include/os/linux/vgpu/platform_vgpu_tegra.c
blob: 948323ef64d694dba708d21502eeba84f9146468 (plain) (tree)
































































































                                                                            
/*
 * Tegra Virtualized GPU Platform Interface
 *
 * Copyright (c) 2014-2018, NVIDIA CORPORATION.  All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <nvgpu/nvhost.h>
#include <nvgpu/gk20a.h>

#include "os/linux/platform_gk20a.h"
#include "vgpu/clk_vgpu.h"
#include "vgpu_linux.h"

static int gk20a_tegra_probe(struct device *dev)
{
#ifdef CONFIG_TEGRA_GK20A_NVHOST
	struct gk20a_platform *platform = dev_get_drvdata(dev);
	int ret;

	ret = nvgpu_get_nvhost_dev(platform->g);
	if (ret)
		return ret;

	vgpu_init_clk_support(platform->g);
	return 0;
#else
	return 0;
#endif
}

long vgpu_plat_clk_round_rate(struct device *dev, unsigned long rate)
{
	/* server will handle frequency rounding */
	return rate;
}

int vgpu_plat_clk_get_freqs(struct device *dev, unsigned long **freqs,
			int *num_freqs)
{
	struct gk20a_platform *platform = gk20a_get_platform(dev);
	struct gk20a *g = platform->g;

	return vgpu_clk_get_freqs(g, freqs, num_freqs);
}

int vgpu_plat_clk_cap_rate(struct device *dev, unsigned long rate)
{
	struct gk20a_platform *platform = gk20a_get_platform(dev);
	struct gk20a *g = platform->g;

	return vgpu_clk_cap_rate(g, rate);
}

struct gk20a_platform vgpu_tegra_platform = {
	.has_syncpoints = true,
	.aggressive_sync_destroy_thresh = 64,

	/* power management configuration */
	.can_railgate_init	= false,
	.can_elpg_init          = false,
	.enable_slcg            = false,
	.enable_blcg            = false,
	.enable_elcg            = false,
	.enable_elpg            = false,
	.enable_aelpg           = false,
	.can_slcg               = false,
	.can_blcg               = false,
	.can_elcg               = false,

	.ch_wdt_timeout_ms = 5000,

	.probe = gk20a_tegra_probe,

	.clk_round_rate = vgpu_plat_clk_round_rate,
	.get_clk_freqs = vgpu_plat_clk_get_freqs,

	/* frequency scaling configuration */
	.devfreq_governor = "userspace",

	.virtual_dev = true,

	/* power management callbacks */
	.suspend = vgpu_tegra_suspend,
	.resume = vgpu_tegra_resume,
};
8'>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
/*

  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;
  // Reset heap
  audiobeam_free_all();

  /*
    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" )
  for ( i = 0; i < num_mic; i++ ) {
    distances[i] = ( audiobeam_sqrt( ( audiobeam_mic_locations[i][0]
                                       - source_location[0] ) *
                                     ( audiobeam_mic_locations[i][0]
                                       - source_location[0] ) +
                                     ( audiobeam_mic_locations[i][1]
                                       - source_location[1] ) *
                                     ( audiobeam_mic_locations[i][1]
                                       - source_location[1] ) +
                                     ( audiobeam_mic_locations[i][2]
                                       - source_location[2] ) *
                                     ( audiobeam_mic_locations[i][2]
                                       - source_location[2] ) ) );
  }
}


void audiobeam_calc_delays( float *distances, float *delays, int sound_speed,
                            int sampling_rate, int num_mic )
{
  int i;

  _Pragma( "loopbound min 15 max 15" )
  for ( i = 0; i < num_mic; i++ )
    delays[i] = ( distances[i] / sound_speed ) * sampling_rate;
}


void audiobeam_adjust_delays( float *delays, int num_mic )
{
  int i;
  long int min_delay = audiobeam_find_min_in_arr ( delays, num_mic ) - 1;

  _Pragma( "loopbound min 15 max 15" )
  for ( i = 0; i < num_mic; i++ )
    delays[i] -= min_delay;
}


float *audiobeam_calc_weights_lr ( int num_mic )
{
  float *weights = ( float * ) audiobeam_malloc( num_mic * sizeof( float ) );
  int index = 0;
  int y, z;

  int half = num_mic / 4;

  _Pragma( "loopbound min 0 max 0" )
  for ( z = 1; z >= -1; z -= 2 ) {
    _Pragma( "loopbound min 0 max 0" )
    for ( y = 0; y < half; y++ ) {
      weights[index] = 0.54 + 0.46 * audiobeam_cos( audiobeam_M_PI