[Mesa-dev] [PATCH 1/2] gallium: PIPE_COMPUTE_CAP_IR_TARGET - allow drivers to specify a processor v2

Francisco Jerez currojerez at riseup.net
Thu Mar 14 09:43:53 PDT 2013


Tom Stellard <tom at stellard.net> writes:

> From: Tom Stellard <thomas.stellard at amd.com>
>
> This target string now contains four values instead of three.  The old
> processor field (which was really being interpreted as arch) has been split
> into two fields: processor and arch.  This allows drivers to pass a
> more a more detailed description of the hardware to compiler frontends.
>
Looks OK to me.

Reviewed-by: Francisco Jerez <currojerez at riseup.net>

> v2:
>   - Adapt to libclc changes
> ---
>  src/gallium/docs/source/screen.rst                 |    8 +-
>  src/gallium/drivers/r600/r600_llvm.c               |   63 -----------------
>  src/gallium/drivers/r600/r600_llvm.h               |    2 -
>  src/gallium/drivers/r600/r600_pipe.c               |   74 ++++++++++++++++++-
>  src/gallium/drivers/r600/r600_pipe.h               |    2 +
>  src/gallium/drivers/radeonsi/radeonsi_pipe.c       |   11 +++
>  src/gallium/drivers/radeonsi/radeonsi_pipe.h       |    1 +
>  src/gallium/drivers/radeonsi/radeonsi_shader.c     |    4 +-
>  .../state_trackers/clover/llvm/invocation.cpp      |   18 ++++--
>  9 files changed, 104 insertions(+), 79 deletions(-)
>
> diff --git a/src/gallium/docs/source/screen.rst b/src/gallium/docs/source/screen.rst
> index 68d1a35..10836f1 100644
> --- a/src/gallium/docs/source/screen.rst
> +++ b/src/gallium/docs/source/screen.rst
> @@ -222,10 +222,10 @@ PIPE_COMPUTE_CAP_*
>  Compute-specific capabilities. They can be queried using
>  pipe_screen::get_compute_param.
>  
> -* ``PIPE_COMPUTE_CAP_IR_TARGET``: A description of the target as a target
> -  triple specification of the form ``processor-manufacturer-os`` that will
> -  be passed on to the compiler.  This CAP is only relevant for drivers
> -  that specify PIPE_SHADER_IR_LLVM for their preferred IR.
> +* ``PIPE_COMPUTE_CAP_IR_TARGET``: A description of the target of the form
> +  ``processor-arch-manufacturer-os`` that will be passed on to the compiler.
> +  This CAP is only relevant for drivers that specify PIPE_SHADER_IR_LLVM for
> +  their preferred IR.
>    Value type: null-terminated string.
>  * ``PIPE_COMPUTE_CAP_GRID_DIMENSION``: Number of supported dimensions
>    for grid and block coordinates.  Value type: ``uint64_t``.
> diff --git a/src/gallium/drivers/r600/r600_llvm.c b/src/gallium/drivers/r600/r600_llvm.c
> index c7aa45f..37e5e14 100644
> --- a/src/gallium/drivers/r600/r600_llvm.c
> +++ b/src/gallium/drivers/r600/r600_llvm.c
> @@ -562,69 +562,6 @@ LLVMModuleRef r600_tgsi_llvm(
>  	return ctx->gallivm.module;
>  }
>  
> -const char * r600_llvm_gpu_string(enum radeon_family family)
> -{
> -	const char * gpu_family;
> -
> -	switch (family) {
> -	case CHIP_R600:
> -	case CHIP_RV610:
> -	case CHIP_RV630:
> -	case CHIP_RV620:
> -	case CHIP_RV635:
> -	case CHIP_RV670:
> -	case CHIP_RS780:
> -	case CHIP_RS880:
> -		gpu_family = "r600";
> -		break;
> -	case CHIP_RV710:
> -		gpu_family = "rv710";
> -		break;
> -	case CHIP_RV730:
> -		gpu_family = "rv730";
> -		break;
> -	case CHIP_RV740:
> -	case CHIP_RV770:
> -		gpu_family = "rv770";
> -		break;
> -	case CHIP_PALM:
> -	case CHIP_CEDAR:
> -		gpu_family = "cedar";
> -		break;
> -	case CHIP_SUMO:
> -	case CHIP_SUMO2:
> -	case CHIP_REDWOOD:
> -		gpu_family = "redwood";
> -		break;
> -	case CHIP_JUNIPER:
> -		gpu_family = "juniper";
> -		break;
> -	case CHIP_HEMLOCK:
> -	case CHIP_CYPRESS:
> -		gpu_family = "cypress";
> -		break;
> -	case CHIP_BARTS:
> -		gpu_family = "barts";
> -		break;
> -	case CHIP_TURKS:
> -		gpu_family = "turks";
> -		break;
> -	case CHIP_CAICOS:
> -		gpu_family = "caicos";
> -		break;
> -	case CHIP_CAYMAN:
> -        case CHIP_ARUBA:
> -		gpu_family = "cayman";
> -		break;
> -	default:
> -		gpu_family = "";
> -		fprintf(stderr, "Chip not supported by r600 llvm "
> -			"backend, please file a bug at bugs.freedesktop.org\n");
> -		break;
> -	}
> -	return gpu_family;
> -}
> -
>  unsigned r600_llvm_compile(
>  	LLVMModuleRef mod,
>  	unsigned char ** inst_bytes,
> diff --git a/src/gallium/drivers/r600/r600_llvm.h b/src/gallium/drivers/r600/r600_llvm.h
> index 090d909..b5e2af2 100644
> --- a/src/gallium/drivers/r600/r600_llvm.h
> +++ b/src/gallium/drivers/r600/r600_llvm.h
> @@ -15,8 +15,6 @@ LLVMModuleRef r600_tgsi_llvm(
>  	struct radeon_llvm_context * ctx,
>  	const struct tgsi_token * tokens);
>  
> -const char * r600_llvm_gpu_string(enum radeon_family family);
> -
>  unsigned r600_llvm_compile(
>  	LLVMModuleRef mod,
>  	unsigned char ** inst_bytes,
> diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c
> index 78002ae..96c76ae 100644
> --- a/src/gallium/drivers/r600/r600_pipe.c
> +++ b/src/gallium/drivers/r600/r600_pipe.c
> @@ -745,18 +745,84 @@ static int r600_get_video_param(struct pipe_screen *screen,
>  	}
>  }
>  
> +const char * r600_llvm_gpu_string(enum radeon_family family)
> +{
> +	const char * gpu_family;
> +
> +	switch (family) {
> +	case CHIP_R600:
> +	case CHIP_RV610:
> +	case CHIP_RV630:
> +	case CHIP_RV620:
> +	case CHIP_RV635:
> +	case CHIP_RV670:
> +	case CHIP_RS780:
> +	case CHIP_RS880:
> +		gpu_family = "r600";
> +		break;
> +	case CHIP_RV710:
> +		gpu_family = "rv710";
> +		break;
> +	case CHIP_RV730:
> +		gpu_family = "rv730";
> +		break;
> +	case CHIP_RV740:
> +	case CHIP_RV770:
> +		gpu_family = "rv770";
> +		break;
> +	case CHIP_PALM:
> +	case CHIP_CEDAR:
> +		gpu_family = "cedar";
> +		break;
> +	case CHIP_SUMO:
> +	case CHIP_SUMO2:
> +	case CHIP_REDWOOD:
> +		gpu_family = "redwood";
> +		break;
> +	case CHIP_JUNIPER:
> +		gpu_family = "juniper";
> +		break;
> +	case CHIP_HEMLOCK:
> +	case CHIP_CYPRESS:
> +		gpu_family = "cypress";
> +		break;
> +	case CHIP_BARTS:
> +		gpu_family = "barts";
> +		break;
> +	case CHIP_TURKS:
> +		gpu_family = "turks";
> +		break;
> +	case CHIP_CAICOS:
> +		gpu_family = "caicos";
> +		break;
> +	case CHIP_CAYMAN:
> +        case CHIP_ARUBA:
> +		gpu_family = "cayman";
> +		break;
> +	default:
> +		gpu_family = "";
> +		fprintf(stderr, "Chip not supported by r600 llvm "
> +			"backend, please file a bug at bugs.freedesktop.org\n");
> +		break;
> +	}
> +	return gpu_family;
> +}
> +
> +
>  static int r600_get_compute_param(struct pipe_screen *screen,
>          enum pipe_compute_cap param,
>          void *ret)
>  {
> +	struct r600_screen *rscreen = (struct r600_screen *)screen;
>  	//TODO: select these params by asic
>  	switch (param) {
> -	case PIPE_COMPUTE_CAP_IR_TARGET:
> +	case PIPE_COMPUTE_CAP_IR_TARGET: {
> +		const char *gpu = r600_llvm_gpu_string(rscreen->family);
>  		if (ret) {
> -			strcpy(ret, "r600--");
> +			sprintf(ret, "%s-r600--", gpu);
>  		}
> -		return 7 * sizeof(char);
> -
> +		return (8 + strlen(gpu)) * sizeof(char);
> +	}
>  	case PIPE_COMPUTE_CAP_GRID_DIMENSION:
>  		if (ret) {
>  			uint64_t * grid_dimension = ret;
> diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h
> index cb52083..f723d54 100644
> --- a/src/gallium/drivers/r600/r600_pipe.h
> +++ b/src/gallium/drivers/r600/r600_pipe.h
> @@ -662,6 +662,8 @@ boolean r600_rings_is_buffer_referenced(struct r600_context *ctx,
>  void *r600_buffer_mmap_sync_with_rings(struct r600_context *ctx,
>  					struct r600_resource *resource,
>  					unsigned usage);
> +const char * r600_llvm_gpu_string(enum radeon_family family);
> +
>  
>  /* r600_query.c */
>  void r600_init_query_functions(struct r600_context *rctx);
> diff --git a/src/gallium/drivers/radeonsi/radeonsi_pipe.c b/src/gallium/drivers/radeonsi/radeonsi_pipe.c
> index acf3e2d..1f545d4 100644
> --- a/src/gallium/drivers/radeonsi/radeonsi_pipe.c
> +++ b/src/gallium/drivers/radeonsi/radeonsi_pipe.c
> @@ -274,6 +274,17 @@ static const char* r600_get_vendor(struct pipe_screen* pscreen)
>  	return "X.Org";
>  }
>  
> +const char *r600_get_llvm_processor_name(enum radeon_family family)
> +{
> +	switch (family) {
> +		case CHIP_TAHITI: return "tahiti";
> +		case CHIP_PITCAIRN: return "pitcairn";
> +		case CHIP_VERDE: return "verde";
> +		case CHIP_OLAND: return "oland";
> +		default: return "";
> +	}
> +}
> +
>  static const char *r600_get_family_name(enum radeon_family family)
>  {
>  	switch(family) {
> diff --git a/src/gallium/drivers/radeonsi/radeonsi_pipe.h b/src/gallium/drivers/radeonsi/radeonsi_pipe.h
> index d0f04f4..c79e03b 100644
> --- a/src/gallium/drivers/radeonsi/radeonsi_pipe.h
> +++ b/src/gallium/drivers/radeonsi/radeonsi_pipe.h
> @@ -210,6 +210,7 @@ void r600_upload_index_buffer(struct r600_context *rctx,
>  /* r600_pipe.c */
>  void radeonsi_flush(struct pipe_context *ctx, struct pipe_fence_handle **fence,
>  		    unsigned flags);
> +const char *r600_get_llvm_processor_name(enum radeon_family family);
>  
>  /* r600_query.c */
>  void r600_init_query_functions(struct r600_context *rctx);
> diff --git a/src/gallium/drivers/radeonsi/radeonsi_shader.c b/src/gallium/drivers/radeonsi/radeonsi_shader.c
> index 95ccd1e..00a46a9 100644
> --- a/src/gallium/drivers/radeonsi/radeonsi_shader.c
> +++ b/src/gallium/drivers/radeonsi/radeonsi_shader.c
> @@ -1040,7 +1040,9 @@ int si_pipe_shader_create(
>  	if (dump) {
>  		LLVMDumpModule(mod);
>  	}
> -	radeon_llvm_compile(mod, &inst_bytes, &inst_byte_count, "SI", dump);
> +	radeon_llvm_compile(mod, &inst_bytes, &inst_byte_count,
> +			r600_get_llvm_processor_name(rctx->screen->family)
> +			, dump);
>  	if (dump) {
>  		fprintf(stderr, "SI CODE:\n");
>  		for (i = 0; i < inst_byte_count; i+=4 ) {
> diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
> index 2785d10..f5d7793 100644
> --- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
> +++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
> @@ -109,7 +109,8 @@ namespace {
>  
>     llvm::Module *
>     compile(const std::string &source, const std::string &name,
> -           const std::string &triple, const std::string &opts) {
> +           const std::string &triple, const std::string &processor,
> +           const std::string &opts) {
>  
>        clang::CompilerInstance c;
>        clang::CompilerInvocation invocation;
> @@ -174,6 +175,7 @@ namespace {
>  
>        c.getLangOpts().NoBuiltin = true;
>        c.getTargetOpts().Triple = triple;
> +      c.getTargetOpts().CPU = processor;
>  #if HAVE_LLVM <= 0x0301
>        c.getInvocation().setLangDefaults(clang::IK_OpenCL);
>  #else
> @@ -214,12 +216,14 @@ namespace {
>  
>     void
>     link(llvm::Module *mod, const std::string &triple,
> +        const std::string &processor,
>          const std::vector<llvm::Function *> &kernels) {
>  
>        llvm::PassManager PM;
>        llvm::PassManagerBuilder Builder;
>        llvm::sys::Path libclc_path =
> -                            llvm::sys::Path(LIBCLC_LIBEXECDIR + triple + ".bc");
> +                            llvm::sys::Path(LIBCLC_LIBEXECDIR + processor +
> +			                    "-" + triple + ".bc");
>  
>        // Link the kernel with libclc
>  #if HAVE_LLVM < 0x0303
> @@ -338,18 +342,22 @@ namespace {
>  module
>  clover::compile_program_llvm(const compat::string &source,
>                               enum pipe_shader_ir ir,
> -                             const compat::string &triple,
> +                             const compat::string &target,
>                               const compat::string &opts) {
>  
>     std::vector<llvm::Function *> kernels;
> +   size_t processor_str_len = std::string(target.begin()).find_first_of("-");
> +   std::string processor(target.begin(), 0, processor_str_len);
> +   std::string triple(target.begin(), processor_str_len + 1,
> +                      target.size() - processor_str_len - 1);
>  
>     // The input file name must have the .cl extension in order for the
>     // CompilerInvocation class to recognize it as an OpenCL source file.
> -   llvm::Module *mod = compile(source, "input.cl", triple, opts);
> +   llvm::Module *mod = compile(source, "input.cl", triple, processor, opts);
>  
>     find_kernels(mod, kernels);
>  
> -   link(mod, triple, kernels);
> +   link(mod, triple, processor, kernels);
>  
>     // Build the clover::module
>     switch (ir) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 229 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20130314/5057f06c/attachment-0001.pgp>


More information about the mesa-dev mailing list