Ejemplo n.º 1
0
void GpuRule::generateKernel(Transform& trans, CodeGenerator& o, bool local) {
  std::string SUFFIX;
  if(local)
    SUFFIX = "_local";
  else
    SUFFIX = "_nolocal";

  CLCodeGenerator clcodegen(o.cgPtr());
  IterationDefinition iterdef(*_rule, _rule->getSelfDependency(), _rule->isSingleCall());
  std::vector<std::string> packedargs = iterdef.packedargs();
  std::vector<std::string> packedargnames = iterdef.packedargnames();
  o.os() << "// GPURULE DECL CODE " << _rule->id() << " " << this << "\n";

  // Create variables to hold handles to program, kernel
  o.os( ) << "cl_program " <<  "clprog_" << _rule->id() << SUFFIX
	  << " = 0;\n";
  o.os( ) << "cl_kernel " << "clkern_" << _rule->id() << SUFFIX
	  << " = 0;\n";

  // Create init function call
  o.beginFunc("void", codename()+"_init"+SUFFIX, std::vector<std::string>(),false);
  trans.addInitCall(codename()+"_init"+SUFFIX);

  _rule->generateOpenCLKernel( trans, clcodegen, iterdef, local);

  //o.os( ) << "/* -- Testing purposes only, to make this easy to read --\n\n";
  //clcodegen.outputStringTo( o.os( ) );
  //o.os( ) << "\n*/\n";

  o.os( ) << "const char* clsrc = ";
  clcodegen.outputEscapedStringTo( o.os( ) );
  o.os( ) << ";\n";

  o.os() << "bool rv = OpenCLUtil::buildKernel(clprog_" << _rule->id() << SUFFIX << ", clkern_" << _rule->id() << SUFFIX << ", clsrc);\n";
  o.os() << "JASSERT(rv);\n";

  o.endFunc();

  // Get kernel
  o.beginFunc("cl_kernel", "get_kernel_" + jalib::XToString(_rule->id()) + SUFFIX);
#ifdef DEBUG
  o.write("JASSERT(clkern_" + jalib::XToString(_rule->id()) + SUFFIX + " != 0);");
#endif
  o.write("return clkern_" + jalib::XToString(_rule->id()) + SUFFIX + ";");
  o.endFunc();

  // Get program
  o.beginFunc("cl_program", "get_program_" + jalib::XToString(_rule->id()) + SUFFIX);
#ifdef DEBUG
  o.write("JASSERT(clprog_" + jalib::XToString(_rule->id()) + SUFFIX + " != 0);");
#endif
  o.write("return clprog_" + jalib::XToString(_rule->id()) + SUFFIX + ";");
  o.endFunc();

}
Ejemplo n.º 2
0
static void code_start( Telem* elem )
{
  codeindent();
  if (elem->name && elem->elemidx != IMAGE && elem->elemidx != COLOR)
    generatename( elem );
  if ( codename( elem ) )
    fprintf( outfile, " = " );
  if (elem->name)
    fprintf( outfile, "IupSetAtt( \"%s\", ", elem->name );
  else
    fprintf( outfile, "IupSetAtt( NULL, " );
  codeelemname( elem );
}
Ejemplo n.º 3
0
void nVIDIAEmbedder::embed( const char *name )
{
	QFileInfo   fileinfo( name );
	QString     basename( fileinfo.baseName() );
	QString     codename( basename );
	QImage      image( name );
	
	codename = codename.replace( QRegExp("[^a-zA-Z0-9]"), "_" );
	
	stream << "static const QRgb " << codename << "_data[] = {" << endl << "\t";
	stream.setf( QTextStream::hex | QTextStream::right );
	stream.fill( '0' );
	
	int pixels = image.width() * image.height();
	Q_UINT32 *data = reinterpret_cast<Q_UINT32*>( image.bits() );
	bool hasAlpha = false;

	
	for ( int i = 0, j = 0; i < pixels; i++ ) {
		if ( qAlpha( *data ) && qAlpha( *data ) != 0xff )
			hasAlpha = true;
		
		stream << "0x" << qSetW(8) << *(data++);
		
		if ( i != pixels-1 ) {
			stream << ',';
		
			if ( j++ > 4 ) {
				j = 0;
				stream << endl << "\t";
			} else
				stream << ' ';
		}
	}

	stream.reset();
	
	stream << endl << "}; // " << codename << "_data" << endl << endl;

	EmbedImage *imginfo = new EmbedImage;
	imginfo->width = image.width();
	imginfo->height = image.height();
	imginfo->alpha = hasAlpha;
	imginfo->name = codename;
	imginfo->string = basename;
	index->append( imginfo ); 
}
Ejemplo n.º 4
0
static void code_decl( Telem *e )
{
  if (e->name || e->attrs)
  {
    code_start( e );
    elems[e->elemidx].code( e ); 
    code_attrs( e );
  }
  else
  {
    codeindent();
    if (e->name && e->elemidx != IMAGE && e->elemidx != COLOR)
      generatename( e );
    if ( codename( e ) )
      fprintf( outfile, " = " );
    codeelemname( e );
    elems[e->elemidx].code( e ); 
  }
}
Ejemplo n.º 5
0
Archivo: ledc.c Proyecto: sanikoyes/iup
static void codeelemparam( Tparam* param )
{
  if (param->tag == ELEM_PARAM)
  {
    code_decl( param->data.elem );
  }
  else
  {
    Telem *e = namedelem( param->data.name );
    codeindent();
    if (e)
    {
      codename( e );
      fprintf( outfile, " /* %s */", param->data.name );
    }
    else
    {
      fprintf( outfile, "IupGetHandle( \"%s\" )", param->data.name );
    }
  }
}
Ejemplo n.º 6
0
void
GpuRule::generateCallTaskCode(const std::string& name, Transform& trans, CodeGenerator& o, const SimpleRegionPtr& region)
{
  o.comment( "GENERATECALLTASKCODE" );
  o.mkSpatialTask(name, trans.instClassName(), codename(), region, RuleFlavor::WORKSTEALING);
}
Ejemplo n.º 7
0
void
GpuRule::generateCallCodeSimple(Transform& /*trans*/, CodeGenerator& o, const SimpleRegionPtr& region)
{
  o.comment( "GENERATECALLCODESIMPLE" );
  o.callSpatial(codename(), region);
}
Ejemplo n.º 8
0
QString getLinuxDistribution() {
	
#if defined(HAVE_POPEN) && defined(HAVE_PCLOSE)
	{
		QString distro(getOutputOf("lsb_release -d").trimmed());
		QString prefix("Description:");
		if(distro.startsWith(prefix)) {
			distro = distro.mid(prefix.length()).trimmed();
		}
		if(!distro.isEmpty()) {
			
			QString codename(getOutputOf("lsb_release -c").trimmed());
			QString prefix("Codename:");
			if(codename.startsWith(prefix)) {
				codename = codename.mid(prefix.length()).trimmed();
			}
			
			if(!codename.isEmpty() && codename != "n/a") {
				distro += " (";
				distro += codename;
				distro += ")";
			}
			
			return distro;
		}
	}
#endif
	
	// Fallback for older / non-LSB-compliant distros.
	// Release file list taken from http://linuxmafia.com/faq/Admin/release-files.html
	
	const char * release_files[] = {
		"/etc/annvix-release",
		"/etc/arch-release",
		"/etc/arklinux-release",
		"/etc/aurox-release",
		"/etc/blackcat-release",
		"/etc/cobalt-release",
		"/etc/conectiva-release",
		"/etc/fedora-release",
		"/etc/gentoo-release",
		"/etc/immunix-release",
		"/etc/lfs-release",
		"/etc/linuxppc-release",
		"/etc/mandriva-release",
		"/etc/mandrake-release",
		"/etc/mandakelinux-release",
		"/etc/mklinux-release",
		"/etc/nld-release",
		"/etc/pld-release",
		"/etc/slackware-release",
		"/etc/e-smith-release",
		"/etc/release",
		"/etc/sun-release",
		"/etc/SuSE-release",
		"/etc/novell-release",
		"/etc/sles-release",
		"/etc/tinysofa-release",
		"/etc/turbolinux-release",
		"/etc/ultrapenguin-release",
		"/etc/UnitedLinux-release",
		"/etc/va-release",
		"/etc/yellowdog-release",
		"/etc/debian_release",
		"/etc/redhat-release",
	};
	
	const char * version_files[][2] = {
		{ "/etc/debian_version", "Debian " },
		{ "/etc/knoppix_version", "Knoppix " },
		{ "/etc/redhat_version", "RedHat " },
		{ "/etc/slackware-version", "Slackware " },
	};
	
	const char * lsb_release = "/etc/lsb-release";
	
	for(size_t i = 0; i < ARRAY_SIZE(release_files); i++) {
		QFile file(release_files[i]);
		if(file.exists()) {
			file.open(QIODevice::ReadOnly);
			QString distro(QString(file.readAll()).trimmed());
			file.close();
			if(!distro.isEmpty()) {
				return distro;
			}
		}
	}
	
	for(size_t i = 0; i < ARRAY_SIZE(version_files); i++) {
		QFile file(version_files[i][0]);
		if(file.exists()) {
			file.open(QIODevice::ReadOnly);
			QString distro(version_files[i][1] + QString(file.readAll()).trimmed());
			file.close();
			if(!distro.isEmpty()) {
				return distro;
			}
		}
	}
	
	QFile file(lsb_release);
	if(file.exists()) {
		file.open(QIODevice::ReadOnly);
		QString distro(QString(file.readAll()).trimmed());
		file.close();
		QString prefix("DISTRIB_ID=\"");
		QString suffix("\"");
		if(distro.startsWith(prefix) && distro.endsWith(suffix)) {
			distro = distro.mid(
				prefix.length(),
				distro.length() - prefix.length() - suffix.length()
			).trimmed();
		}
		return distro;
	}
	
	return QString();
}