Beispiel #1
0
// receive a sample frame and compute the
// inner products with all the hF basis
// polynomials.
void RxAndComputeInnerProducts()
{
	int I;
	double x;
	for(I=0; I < NSAMPLES; I++)
	{
		__loop_pipelining_on__(8,2,0);
		x = read_float64("in0_data");
		inputData[I] = x;

		// note: the sample interval will about 
		// 1ms.  Assuming a clock of 100MHz, this
		// means that the inner-product loop below
		// should finish in 100K cycles.  not likely
		// to be critical.
	}
	for (I=0; I<NSAMPLES; I=I+4){
//		__loop_pipelining_on__(15,2,0);
		__InnerProduct__(I);
	}
#ifdef SW
#ifdef debug
	for(I = 0; I < NSIGMAS; I++)
	{
		fprintf(stderr,"HW: Dot-product for sigma-index %d, HF-0, is %f.\n", I, dotP0[I]);
		fprintf(stderr,"HW: Dot-product for sigma-index %d, HF-1, is %f.\n", I, dotP1[I]);
		fprintf(stderr,"HW: Dot-product for sigma-index %d, HF-2, is %f.\n", I, dotP2[I]);
		fprintf(stderr,"HW: Dot-product for sigma-index %d, HF-3, is %f.\n", I, dotP3[I]);
		fprintf(stderr,"HW: Dot-product for sigma-index %d, HF-4, is %f.\n", I, dotP4[I]);
		fprintf(stderr,"HW: Dot-product for sigma-index %d, HF-5, is %f.\n", I, dotP5[I]);
	}
#endif
#endif
}
Beispiel #2
0
void read_float64_n(const char *id, double* buf, int buf_len)
{
  int i;
  for(i = 0; i < buf_len; i++)
    {
      buf[i] = read_float64((char*) id);
    }
}
Beispiel #3
0
TimeRecord::TimeRecord(const Source &source, const unsigned char *&ptr) {
  type = *(ptr++);
  switch (type) {
  case TIME_DOUBLE:
    time_double = read_float64(ptr);
    break;
  case TIME_TICKS32:
    time_ticks32 = read_u32(ptr);
    break;
  default:
    throw ParseError("At byte %d: Unknown TimeRecord type 0x%02x", source.pos(ptr-1), type);
  }
}
Beispiel #4
0
void initHF()
{
	int M = MEM_SIZE;
	int idx;
	int shift1, shift2, shift3, shift4, shift5;
	shift1 = M;
	shift2 = 2*M;
	shift3 = 3*M;
	shift4 = 4*M;
	shift5 = 5*M;
	for(idx = 0; idx < NSIGMAS; idx++)
	{
		__loop_pipelining_on__(8,2,0);
		dotP0[idx]  = 0;
		dotP1[idx]  = 0;
		dotP2[idx]  = 0;
		dotP3[idx]  = 0;
		dotP4[idx]  = 0;
		dotP5[idx]  = 0;
		err[idx] = 0;
		Offset[idx] = NSAMPLES*idx;
	}

	for (idx = 0; idx < 6*M; idx++){
		hFall[idx] = read_float64("in1_data");
	}

	for(idx = 0; idx < M; idx++)
	{
		__loop_pipelining_on__(15,2,0);
		hF0[idx] = hFall[idx];
		hF1[idx] = hFall[shift1+idx];
		hF2[idx] = hFall[shift2+idx];	
		hF3[idx] = hFall[shift3+idx];
		hF4[idx] = hFall[shift4+idx];
		hF5[idx] = hFall[shift5+idx];
	}
#ifdef SW
	fprintf(stderr, "reading Hermite function 6 vals completed\n");
#endif

#ifdef SW
	fprintf(stderr,"HW: initHF completed.\n");
#endif
}
Beispiel #5
0
void Receiver()
{
	int count = 0;
	FILE* fout = fopen("characterized_data.txt", "w");
	while(1)
	{
		count++;
		int64_t best_sigma_index = read_uint64("bsi_output_pipe");
		double p0 = read_float64("dotP_output_pipe");
		double p1 = read_float64("dotP_output_pipe");
		double p2 = read_float64("dotP_output_pipe");
		double p3 = read_float64("dotP_output_pipe");
		double p4 = read_float64("dotP_output_pipe");
		double p5 = read_float64("dotP_output_pipe");
		fprintf(fout, " Best sigma= %f, (index = %"PRId64").\n", (MIN_SIGMA + (((float)(best_sigma_index))*(MAX_SIGMA - MIN_SIGMA)/NSIGMAS)), best_sigma_index);
		fprintf(fout, "best fit coeffs are = %le,%le,%le,%le,%le,%le\n\n\n", p0, p1, p2, p3, p4, p5);
		printf("characterized %d number of beats\n", count);
	}	
	fclose(fout);
}
Beispiel #6
0
/* Reads a property of type 'prop_type' from 'data', and puts the
 * result 'out'. Returns 0 upon success, a negative value otherwise */
static int read_ply_property(struct file_data *data, const int prop_type, 
                             const int swap_bytes, void *out) 
{
  int c, rcode=0;
  /* Just local pointers to copy the result from the 'read_[type]'
   * functions into... */
  t_int8 *tmp_int8;
  t_uint8 *tmp_uint8;
  t_int16 *tmp_int16;
  t_uint16 *tmp_uint16;
  t_int32 *tmp_int32;
  t_uint32 *tmp_uint32;
  float *tmp_float32;
  double *tmp_float64;

  switch(prop_type) {
  case uint8:
    c = getc(data);
    if (c == EOF) 
      rcode = EOF;
    else {
      tmp_uint8 = out;
      *tmp_uint8 = (t_uint8)c;
    }
    break;
  case int8:
    c = getc(data);
    if (c == EOF) 
      rcode = EOF;
    else {
      tmp_int8= out;
      *tmp_int8 = (t_int8)c;
    }
    break;
  case uint16:
    tmp_uint16 = out;
    rcode = read_uint16(data, swap_bytes, tmp_uint16);
    break;
  case int16:
    tmp_int16 = out;
    rcode = read_int16(data, swap_bytes, tmp_int16);
    break;
  case uint32:
    tmp_uint32 = out;
    rcode = read_uint32(data, swap_bytes, tmp_uint32);
    break;
  case int32:
    tmp_int32 = out;
    rcode = read_int32(data, swap_bytes, tmp_int32);
    break;
  case float32:
    tmp_float32 = out;
    rcode = read_float32(data, swap_bytes, tmp_float32);
    break;
  case float64:
    tmp_float64 = out;
    rcode = read_float64(data, swap_bytes, tmp_float64);
    break;
  default:
    rcode = MESH_CORRUPTED;
    break;
  }

  return rcode;
}
Beispiel #7
0
int main(int argc, char* argv[])
{
	float result;
	int I;

	if(argc < 2)
	{
		fprintf(stderr,"Supply data set file.\n");
		return(1);
	}

	FILE* fp = fopen(argv[1],"r");
	if(fp == NULL)
	{
		fprintf(stderr,"Could not open data set file %s.\n", argv[1]);
		return(1);
	}

	signal(SIGINT,  Exit);
	signal(SIGTERM, Exit);

	PTHREAD_DECL(Logger);
	PTHREAD_CREATE(Logger);

#ifdef SW
	init_pipe_handler();
	PTHREAD_DECL(bestFit);
	PTHREAD_CREATE(bestFit);
#endif

	Sender();
	for(I = 0; I < NSAMPLES; I++)
	{
		double X;
		fscanf(fp, "%le", &X);
		write_float64("sample_data_pipe", X);
		samples[I] = X;
	}
	fprintf(stderr," Sent samples.\n");
	fclose(fp);

	calculateReferenceFit();

	uint32_t best_sigma_index = read_uint32("best_sigma_pipe");
	fprintf(stdout, " Best sigma= %f (index = %d).\n", (MIN_SIGMA + (best_sigma_index*(MAX_SIGMA - MIN_SIGMA)/NSIGMAS)), best_sigma_index);
	
	double p0 = read_float64("fit_coefficient_pipe");
	double p1 = read_float64("fit_coefficient_pipe");
	double p2 = read_float64("fit_coefficient_pipe");
	double p3 = read_float64("fit_coefficient_pipe");
	double p4 = read_float64("fit_coefficient_pipe");
	double p5 = read_float64("fit_coefficient_pipe");
	fprintf(stdout, "Fit coefficients = %le, %le, %le, %le, %le, %le.\n", p0,p1,p2,p3,p4,p5);

	uint32_t elapsed_time = read_uint32("elapsed_time_pipe");
	fprintf(stdout,"Elapsed time = %d.\n", elapsed_time);

#ifdef SW
	PTHREAD_CANCEL(bestFit);
	close_pipe_handler();
	return(0);
#endif
}
Beispiel #8
0
int start (void)
#endif
{
    uint64_t apl64;
    uint32_t i, apl;
    uint16_t apl16;
    uint8_t apl8,my_apl8;
    void *sptr, *rptr;
    double ong64, my_ong64;
    float ong, my_ong;
    int failure = 0;

    i = 0;

    while (i < 10) {
#ifdef RUN
        apl = rand();
#else
        apl = i + 1;
#endif
        my_ong = (float)apl;
        my_ong64 = (double)apl;
        apl64  = (uint64_t)apl;
        apl16  = (uint16_t)apl;
        my_apl8  = (uint8_t)apl16;

        write_uint64("apples64", apl64);
#ifdef RUN
        fprintf(stderr, "\n(%d.a) sent a 64-bit apple: %llu..", i, apl64);
#endif

        ong64 = read_float64("oranges64");

#ifdef RUN
        fprintf(stderr, "\ngot a (double) orange: %le.", ong64);
#endif

        failure |= (my_ong64 != ong64);

        write_uint32("apples32", apl);
#ifdef RUN
        fprintf(stderr, "\n(%d.b) sent a 32-bit apple: %d.", i, apl);
#endif

        ong = read_float32("oranges32");
#ifdef RUN
        fprintf(stderr, "\ngot a (float) orange: %f.", ong);
#endif

        failure |= (my_ong != ong);

        write_uint16("apples16", apl16);
#ifdef RUN
        fprintf(stderr, "\n(%d.c) sent a 16-bit apple: %d.", i, apl16);
#endif

        apl8 = read_uint8("oranges8");
#ifdef RUN
        fprintf(stderr, "\ngot an 8-bit orange: %d.", apl8);
#endif

        sptr = (void*) &apl;
        write_pointer("apples32", sptr);
#ifdef RUN
        fprintf(stderr, "\n(%d.d) sent a pointer apple: %d.", i, (unsigned int)sptr);
#endif

        rptr = read_pointer("oranges32");
#ifdef RUN
        fprintf(stderr, "\ngot a pointer orange: %d.",(unsigned int) rptr);
#endif

        failure |= (sptr != rptr);
        ++i;
    }

#ifdef RUN
    if (failure == 0)
        fprintf(stderr, "\nAll conversions successful.\n");
    else
        fprintf(stderr, "\nSome conversion(s) failed.\n");
#endif

    return failure;
}
Beispiel #9
0
mapnik::raster_ptr
pgraster_wkb_reader::get_raster() {

    /* Read endianness */
    endian_ = *ptr_;
    ptr_ += 1;

    /* Read version of protocol */
    uint16_t version = read_uint16(&ptr_, endian_);
    if (version != 0) {
       MAPNIK_LOG_WARN(pgraster) << "pgraster_wkb_reader: WKB version "
          << version << " unsupported";
      return mapnik::raster_ptr();
    }

    numBands_ = read_uint16(&ptr_, endian_);
    double scaleX = read_float64(&ptr_, endian_);
    double scaleY = read_float64(&ptr_, endian_);
    double ipX = read_float64(&ptr_, endian_);
    double ipY = read_float64(&ptr_, endian_);
    double skewX = read_float64(&ptr_, endian_);
    double skewY = read_float64(&ptr_, endian_);
    int32_t srid = read_int32(&ptr_, endian_);
    width_ = read_uint16(&ptr_, endian_);
    height_ = read_uint16(&ptr_, endian_);

    MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: numBands=" << numBands_;
    MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: scaleX=" << scaleX;
    MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: scaleY=" << scaleY;
    MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: ipX=" << ipX;
    MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: ipY=" << ipY;
    MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: skewX=" << skewX;
    MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: skewY=" << skewY;
    MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: srid=" << srid;
    MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: size="
      << width_ << "x" << height_;

    // this is for color interpretation
    MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: bandno=" << bandno_;

    if ( skewX || skewY ) {
      MAPNIK_LOG_WARN(pgraster) << "pgraster_wkb_reader: raster rotation is not supported";
      return mapnik::raster_ptr();
    }

    mapnik::box2d<double> ext(ipX,ipY,ipX+(width_*scaleX),ipY+(height_*scaleY));
    MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: Raster extent=" << ext;

    if ( bandno_ )
    {
      if ( bandno_ != 1 )
      {
          MAPNIK_LOG_WARN(pgraster) << "pgraster_wkb_reader: "
              "reading bands other than 1st as indexed is unsupported";
          return mapnik::raster_ptr();
      }
      MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: requested band " << bandno_;
      return read_indexed(ext, width_, height_);
    }
    else
    {
      switch (numBands_)
      {
        case 1:
          return read_grayscale(ext, width_, height_);
          break;
        case 3:
        case 4:
          return read_rgba(ext, width_, height_);
          break;
        default:
          std::ostringstream err;
          err << "pgraster_wkb_reader: raster with "
              << numBands_
              << " bands is not supported, specify a band number";
          //MAPNIK_LOG_WARN(pgraster) << err.str();
          throw mapnik::datasource_exception(err.str());
          return mapnik::raster_ptr();
      }
    }
    return mapnik::raster_ptr();
}