Exemplo n.º 1
0
std::shared_ptr<BuildItem>
PackageConfig::transform( TransformSet &xform ) const
{
	std::shared_ptr<BuildItem> ret = xform.getTransform( this );
	if ( ret )
		return ret;

	DEBUG( "transform PackageConfig " << getName() );
	if ( myPackageFile.empty() )
		ret = std::make_shared<BuildItem>( getName(), getDir() );
	else
	{
		ret = std::make_shared<BuildItem>( getName(), std::shared_ptr<Directory>() );
		ret->addExternalOutput( myPackageFile );
	}
	ret->addToVariable( "cflags", getCFlags() );
	ret->addToVariable( "cflags", getVariable( "cflags" ) );
	ret->addToVariable( "ldflags", getLibs() );
	ret->addToVariable( "ldflags", getVariable( "ldflags" ) );

	if ( myPackageFile.empty() )
	{
		ret->addToVariable( "libdirs", getVariable( "libdirs" ) );
		ret->addToVariable( "includes", getVariable( "includes" ) );
	}

	xform.recordTransform( this, ret );
	return ret;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    cout.precision(16);
    int_t i, n = N;
    //cin >> n;
   
    typedef DFT TransformType;
    typedef ValueType::ValueType CT;

    TransformSet gfft;
    TransformSet::ObjectType* fftobj  = gfft.CreateTransformObject(n, ValueType::ID, TransformType::ID, 1, 
								   OpenMP<2>::ID, Place::ID);
    
// create sample data
    CT* data = new CT[n];
    CT* dataout = new CT[n];
    for (i=0; i < n; ++i) {
      // distribute in [-0.5;0.5] as in FFTW's benchmarks
       //data[i] = std::complex(rand()/(double)RAND_MAX - 0.5, rand()/(double)RAND_MAX - 0.5);
       data[i] = CT(2*i, 2*i+1); 
       dataout[i] = CT(0,0);
    }

    DFT_wrapper<CT::value_type> dft(data, n);

 // print out sample data
    cout<<"Input data:"<<endl;
    for (i=0; i < n; ++i)
      cout<<"("<<data[i].real()<<","<<data[i].imag()<<")"<<endl;

// apply FFT out-of-place
   fftobj->fft(data, dataout);

// do simple dft
   dft.apply();
    
   CT::value_type* dataout1 = dft.getdata();

// print out transformed data
   cout.precision(3);
   cout<<"Result of transform:"<<endl;
   for (i=0; i < n; ++i)
      cout<<"("<<dataout[i].real()<<","<<dataout[i].imag()<<")   \t("<<dataout1[2*i]<<","<<dataout1[2*i+1]<<") \t"<<endl;

   dft.diff(dataout);

   cout<<"Check against DFT:"<<endl;
   double mx(-1);
   for (i=0; i < n; ++i) {
      cout<<"("<<fabs(dataout[i].real())<<","<<fabs(dataout[i].imag())<<")"<<endl;
      mx = max(mx, fabs(dataout[i].real()));
      mx = max(mx, fabs(dataout[i].imag()));
   }
   cout<<"---------------------------------------------"<<endl;
   cout << mx << endl;
   
   delete [] data;
   delete [] dataout;
}
Exemplo n.º 3
0
std::shared_ptr<BuildItem>
Item::transform( TransformSet &xform ) const
{
	std::shared_ptr<BuildItem> ret = xform.getTransform( this );
	if ( ret )
		return ret;

	DEBUG( "transform Item " << getName() );
	ret = std::make_shared<BuildItem>( getName(), getDir() );
	ret->setDefaultTarget( isDefaultTarget() );
	ret->setUseName( isUseNameAsInput() );
	ret->setTopLevel( isTopLevel(), myPseudoName );

	VariableSet buildvars;
	extractVariables( buildvars );
	ret->setVariables( std::move( buildvars ) );

	if ( myForceToolAll == "<pseudo>" )
	{
		ret->addExternalOutput( getName() );
		ret->setOutputDir( getDir()->reroot( xform.getArtifactDir() ) );
	}
	else
	{
		std::shared_ptr<Tool> t = getTool( xform );

		if ( t )
		{
			DEBUG( getName() << " transformed by tool '" << t->getTag() << "' (" << t->getName() << ")" );
			if ( t->getGeneratedExecutable() )
			{
				std::shared_ptr<BuildItem> x = t->getGeneratedExecutable()->transform( xform );
				ret->addDependency( DependencyType::IMPLICIT, x );
			}
			ret->setTool( t );
			ret->setOutputDir( getDir()->reroot( xform.getArtifactDir() ) );
			std::string overOpt;
			for ( auto &i: t->allOptions() )
			{
				if ( hasToolOverride( i.first, overOpt ) )
					ret->setVariable( t->getOptionVariable( i.first ),
									  t->getOptionValue( i.first, overOpt ) );
			}
		}
		else
			WARNING( "No tools found for " << getName() );
	}

	xform.recordTransform( this, ret );
	return ret;
}
Exemplo n.º 4
0
std::shared_ptr<BuildItem>
CodeFilter::transform( TransformSet &xform ) const
{
	std::shared_ptr<BuildItem> ret = xform.getTransform( this );
	if ( ret )
		return ret;

	DEBUG( "transform CodeFilter " << getName() );
	ret = std::make_shared<BuildItem>( getName(), getDir() );
	ret->setUseName( false );

	VariableSet buildvars;
	extractVariables( buildvars );
	ret->setVariables( std::move( buildvars ) );

	if ( myTool )
	{
		ItemPtr genExe = myTool->getGeneratedExecutable();
		if ( genExe )
		{
			std::shared_ptr<BuildItem> exeDep = genExe->transform( xform );
			ret->addDependency( DependencyType::IMPLICIT, exeDep );
		}

		for ( const ItemPtr &i: myItems )
		{
			// huh, we can't call transform on these because then
			// cpp files we're going to filter will be transformed to
			// .o files.
			auto inp = std::make_shared<BuildItem>( i->getName(), i->getDir() );
			inp->setUseName( false );
			inp->setOutputDir( getDir() );
			inp->setOutputs( { i->getName() } );
			ret->addDependency( DependencyType::EXPLICIT, inp );
		}
		
		ret->setTool( myTool );
		auto outd = getDir()->reroot( xform.getArtifactDir() );
		ret->setOutputDir( outd );
		ret->setVariable( "current_output_dir", outd->fullpath() );
		ret->setOutputs( myOutputs );
	}

	xform.recordTransform( this, ret );

	return ret;
}
Exemplo n.º 5
0
void
Item::copyDependenciesToBuild( TransformSet &xform ) const
{
	std::shared_ptr<BuildItem> ret = xform.getTransform( this );
	if ( ! ret )
		return;

	for ( auto dep: myDependencies )
	{
		if ( dep.first )
		{
			std::shared_ptr<BuildItem> d = xform.getTransform( dep.first.get() );
			if ( d )
				ret->addDependency( dep.second, d );
		}
	}
}
Exemplo n.º 6
0
std::shared_ptr<Tool>
Item::getTool( TransformSet &xform, const std::string &ext ) const
{
	if ( ! myForceToolAll.empty() )
		return xform.findToolByTag( myForceToolAll, ext );

	auto x = myForceToolExt.find( ext );
	if ( x != myForceToolExt.end() )
	{
		DEBUG( "Overriding tool for extension '" << ext << "' to '" << x->second << "'" );
		return xform.findToolByTag( x->second, ext );
	}

	ItemPtr i = getParent();

	if ( i )
		return i->getTool( xform, ext );

	return xform.findTool( ext );
}
Exemplo n.º 7
0
Rule
Tool::createRule( const TransformSet &xset, bool useBraces ) const
{
	ToolSubst x( *this, xset, useBraces );

	std::string desc = myDescription;
	String::substituteVariables( desc, false, x );
	
	Rule ret( getTag(), desc );

	std::vector<std::string> cmd;
	for ( std::string ci: myCommand )
	{
		String::substituteVariables( ci, false, x );
		cmd.emplace_back( std::move( ci ) );
	}
	for ( std::string ci: myImplDepCmd )
	{
		String::substituteVariables( ci, false, x );
		cmd.emplace_back( std::move( ci ) );
	}
	ret.setCommand( std::move( cmd ) );

	for ( auto &i: myOptions )
	{
		std::string opt;
		opt = xset.getOptionValue( i.first );
		if ( opt.empty() )
			opt = getDefaultOption( i.first );

		auto io = i.second.find( opt );
		if ( io != i.second.end() )
		{
			std::stringstream rval;
			bool notfirst = false;
			for ( const std::string &oss: io->second )
			{
				if ( notfirst )
					rval << ' ';
				rval << oss;
				notfirst = true;
			}
			ret.setVariable( getOptionVariable( i.first ), rval.str() );
		}
	}

	ret.setDependencyFile( myImplDepName );
	ret.setDependencyStyle( myImplDepStyle );
	ret.setJobPool( myPool );
	ret.setOutputRestat( myOutputRestat );

	return ret;
}
Exemplo n.º 8
0
int main(int argc, char *argv[])
{
    unsigned int p = 2;
    typedef DFT TransformType;

    TransformSet gfft;
    TransformSet::ObjectType* fftobj  = gfft.CreateTransformObject(p, ValueType::ID, TransformType::ID, 1);
    TransformSet::ObjectType* ifftobj = gfft.CreateTransformObject(p, ValueType::ID, TransformType::Inverse::ID, 1);

    unsigned long i, n = (TransformType::ID == RDFT::ID) ? (1<<(p-1)) : (1<<p);

// create sample data
    ValueType::ValueType* data = new ValueType::ValueType [2*n];
    for (i=0; i < n; ++i) {
       data[2*i] = 2*i;
       data[2*i+1] = 2*i+1; //2*i+1;
    }

// print out sample data
    cout<<"Input data:"<<endl;
    for (i=0; i < n; ++i)
      cout<<"("<<data[2*i]<<","<<data[2*i+1]<<")"<<endl;

// apply FFT in-place
    fftobj->fft(data);

// print out transformed data
    cout<<"Result of transform:"<<endl;
    for (i=0; i < n; ++i)
      cout<<"("<<data[2*i]<<","<<data[2*i+1]<<")"<<endl;

    ifftobj->fft(data);

// print out transformed data
    cout<<"Result of backward transform:"<<endl;
    for (i=0; i < n; ++i)
      cout<<"("<<data[2*i]<<","<<data[2*i+1]<<")"<<endl;

}
Exemplo n.º 9
0
Arquivo: gfft.cpp Projeto: scpp/gfft
int main(int /*argc*/, char** /*argv[]*/)
{
    cout.precision(16);
    long_t i;
   
    typedef DFT TransformType;
    typedef ValueType::ValueType T;
    typedef ValueType::base_type BT;
    static const int C = Loki::TypeTraits<T>::isStdFundamental ? 2 : 1;

    TransformSet gfft;
    TransformSet::ObjectType* fftobj  = gfft.CreateTransformObject(N, ValueType::ID, TransformType::ID, 1, 
								   OpenMP<NThreads>::ID, Place::ID);
//     TransformSet::ObjectType* ifftobj = gfft.CreateTransformObject(n, ValueType::ID, TransformType::Inverse::ID, 1, 
// 								   ParallelizationGroup::Default::ID, Place::ID);
    
// create sample data
    T* data = new T [C*N];
#if PLACE == OUT_OF_PLACE
    T* dataout = new T [C*N];
#endif
    for (i=0; i < N; ++i) {
//      GenInput<T>::rand(data, i);  // distribute in [-0.5;0.5] as in FFTW
       GenInput<T>::seq(data, i);
    }

    DFT_wrapper<BT> dft(data, N);

 // print out sample data
#ifdef FOUT
    cout<<"Input data:"<<endl;
    for (i=0; i < N; ++i)
      cout << GenOutput<T>(data,i) << endl;
#endif

#if PLACE == OUT_OF_PLACE
// apply FFT out-of-place
   fftobj->fft(data, dataout);
#else
// apply FFT in-place
   fftobj->fft(data);
   T* dataout = data;
#endif
   
// do simple dft
   dft.apply();

   BT* dataout1 = dft.getdata();

// print out transformed data
   cout.precision(3);
#ifdef FOUT
   cout<<"Result of transform:"<<endl;
   for (i=0; i < N; ++i)
     cout << GenOutput<T>(dataout,i) << "   \t"<< GenOutput<BT>(dataout1,i) <<" \t"<<endl;
#endif

   dft.diff(dataout);

   cout<<"Check against DFT:"<<endl;
   double mx(-1);
   double s = 0.;
   for (i=0; i < N; ++i) {
#ifdef FOUT
      cout << GenOutput<T>(dataout,i) << endl;
#endif
      double re = ComplexWrapper<T>(dataout,i).real();
      double im = ComplexWrapper<T>(dataout,i).imag();
      mx = max(mx, fabs(re));
      mx = max(mx, fabs(im));
      s += re*re;
      s += im*im;
   }
   cout<<"---------------------------------------------"<<endl;
   cout << N << ": " << ValueType::name() << ", " << Place::name() << endl;
   cout << mx << "  " << sqrt(s) << endl;

   delete [] data;
#if PLACE == OUT_OF_PLACE
   delete [] dataout;
#endif
}