From: Junyan He <junyan...@intel.com> Fix somes bugs of compiler and runtime, make 2.0's pipe work.
Signed-off-by: Junyan He <junyan...@intel.com> --- backend/src/backend/context.cpp | 3 +- backend/src/backend/gen_program_elf.cpp | 8 ++++- src/cl_api.c | 51 ---------------------------- src/cl_api_mem.c | 59 +++++++++++++++++++++++++++++++++ src/cl_kernel.c | 16 +++++++-- src/cl_kernel.h | 1 + src/cl_mem.h | 4 +++ src/gen/cl_command_queue_gen.c | 4 +-- 8 files changed, 88 insertions(+), 58 deletions(-) diff --git a/backend/src/backend/context.cpp b/backend/src/backend/context.cpp index 51ef3a7..bdb1909 100644 --- a/backend/src/backend/context.cpp +++ b/backend/src/backend/context.cpp @@ -510,7 +510,8 @@ namespace gbe kernel->args[argID].size = sizeof(void*); break; case ir::FunctionArgument::PIPE: - kernel->args[argID].type = GBE_ARG_TYPE_SAMPLER; + kernel->args[argID].type = GBE_ARG_TYPE_PIPE; + kernel->args[argID].arg_space_type = GBE_ADDRESS_SPACE_GLOBAL; kernel->args[argID].size = sizeof(void*); kernel->args[argID].bti = arg.bti; break; diff --git a/backend/src/backend/gen_program_elf.cpp b/backend/src/backend/gen_program_elf.cpp index 0c78964..4e7842e 100644 --- a/backend/src/backend/gen_program_elf.cpp +++ b/backend/src/backend/gen_program_elf.cpp @@ -529,7 +529,13 @@ void GenProgramElfContext::emitOneKernel(GenKernel &kernel) argi->addr_space = kernel.getArgAddressSpace(i); argi->align = kernel.getArgAlign(i); - if (argi->type == GBE_ARG_TYPE_POINTER && argi->addr_space == GBE_ADDRESS_SPACE_GLOBAL) { + if (argi->type == GBE_ARG_TYPE_POINTER) { + if (argi->addr_space == GBE_ADDRESS_SPACE_GLOBAL || + (argi->addr_space == GBE_ADDRESS_SPACE_CONSTANT && kernel.getOclVersion() >= 200)) { + argi->extra = kernel.getArgBTI(i); + } + } else if (argi->type == GBE_ARG_TYPE_PIPE) { + assert(kernel.getOclVersion() >= 200); argi->extra = kernel.getArgBTI(i); } else if (argi->type == GBE_ARG_TYPE_IMAGE) { assert(image_data_sz > 0); diff --git a/src/cl_api.c b/src/cl_api.c index 397b941..6c5f4da 100644 --- a/src/cl_api.c +++ b/src/cl_api.c @@ -779,57 +779,6 @@ error: return err; } -cl_mem clCreatePipe (cl_context context, - cl_mem_flags flags, - cl_uint pipe_packet_size, - cl_uint pipe_max_packets, - const cl_pipe_properties *properties, - cl_int *errcode_ret) -{ - cl_mem mem = NULL; - cl_int err = CL_SUCCESS; - cl_uint device_max_size = 0; - - CHECK_CONTEXT (context); - - if(UNLIKELY((flags & ~(CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS)) != 0)) { - err = CL_INVALID_VALUE; - goto error; - } - - if(UNLIKELY(properties != NULL)) { - err = CL_INVALID_VALUE; - goto error; - } - - if(UNLIKELY(pipe_packet_size == 0 || pipe_max_packets == 0)) { - err = CL_INVALID_PIPE_SIZE; - goto error; - } - if ((err = cl_device_get_info(context->devices[0], - CL_DEVICE_PIPE_MAX_PACKET_SIZE, - sizeof(device_max_size), - &device_max_size, - NULL)) != CL_SUCCESS) { - goto error; - } - - if(UNLIKELY(pipe_packet_size > device_max_size)) { - err = CL_INVALID_PIPE_SIZE; - goto error; - } - - if(flags == 0) - flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS; - - mem = cl_mem_new_pipe(context, flags, pipe_packet_size, pipe_max_packets, &err); - -error: - if (errcode_ret) - *errcode_ret = err; - return mem; -} - cl_int clGetPipeInfo (cl_mem pipe, cl_pipe_info param_name, size_t param_value_size, diff --git a/src/cl_api_mem.c b/src/cl_api_mem.c index d842349..3836fff 100644 --- a/src/cl_api_mem.c +++ b/src/cl_api_mem.c @@ -2436,3 +2436,62 @@ clReleaseMemObject(cl_mem memobj) cl_mem_delete(memobj); return CL_SUCCESS; } + +cl_mem +clCreatePipe(cl_context context, + cl_mem_flags flags, + cl_uint pipe_packet_size, + cl_uint pipe_max_packets, + const cl_pipe_properties *properties, + cl_int *errcode_ret) +{ + cl_mem mem = NULL; + cl_int err = CL_SUCCESS; + cl_uint device_max_size = 0; + cl_int i; + + do { + if (!CL_OBJECT_IS_CONTEXT(context)) { + err = CL_INVALID_CONTEXT; + break; + } + + if ((flags & ~(CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS)) != 0) { + err = CL_INVALID_VALUE; + break; + } + + if (properties != NULL) { + err = CL_INVALID_VALUE; + break; + } + + if (pipe_packet_size == 0 || pipe_max_packets == 0) { + err = CL_INVALID_PIPE_SIZE; + break; + } + + for (i = 0; i < context->device_num; i++) { + if ((err = cl_device_get_info(context->devices[i], CL_DEVICE_PIPE_MAX_PACKET_SIZE, + sizeof(device_max_size), &device_max_size, NULL)) != CL_SUCCESS) { + break; + } + + if (pipe_packet_size > device_max_size) { + err = CL_INVALID_PIPE_SIZE; + break; + } + } + if (err != CL_SUCCESS) + break; + + if (flags == 0) + flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS; + + mem = cl_mem_new_pipe(context, flags, pipe_packet_size, pipe_max_packets, &err); + } while (0); + + if (errcode_ret) + *errcode_ret = err; + return mem; +} diff --git a/src/cl_kernel.c b/src/cl_kernel.c index 60fb1dc..5d0f2bc 100644 --- a/src/cl_kernel.c +++ b/src/cl_kernel.c @@ -124,6 +124,16 @@ cl_kernel_set_arg(cl_kernel kernel, cl_uint index, size_t sz, const void *value) return CL_SUCCESS; } + if (arg->arg_type == ArgTypePipe) { + if (!CL_OBJECT_IS_MEM(*(cl_mem *)value)) + return CL_INVALID_ARG_VALUE; + + arg->val.val_mem = *(cl_mem *)value; + arg->val_size = sizeof(cl_mem); + arg->is_set = CL_TRUE; + return CL_SUCCESS; + } + /* For image, we should have a cl_mem object, and it is a image. */ if (arg->arg_type == ArgTypeSampler) { if (!CL_OBJECT_IS_SAMPLER(*(cl_sampler *)value)) @@ -227,9 +237,9 @@ cl_kernel_get_argument_info(cl_kernel k, cl_uint arg_index, cl_kernel_arg_info p case CL_KERNEL_ARG_TYPE_QUALIFIER: if ((k->args[arg_index].arg_type_qualifier & - (~(CL_KERNEL_ARG_TYPE_NONE | CL_KERNEL_ARG_TYPE_CONST | - CL_KERNEL_ARG_TYPE_RESTRICT | CL_KERNEL_ARG_TYPE_VOLATILE | - CL_KERNEL_ARG_TYPE_PIPE))) != 0) + (~(CL_KERNEL_ARG_TYPE_NONE | CL_KERNEL_ARG_TYPE_CONST | + CL_KERNEL_ARG_TYPE_RESTRICT | CL_KERNEL_ARG_TYPE_VOLATILE | + CL_KERNEL_ARG_TYPE_PIPE))) != 0) return CL_KERNEL_ARG_INFO_NOT_AVAILABLE; if (param_value_size_ret) *param_value_size_ret = sizeof(cl_kernel_arg_type_qualifier); diff --git a/src/cl_kernel.h b/src/cl_kernel.h index 07d8996..dd2afdf 100644 --- a/src/cl_kernel.h +++ b/src/cl_kernel.h @@ -44,6 +44,7 @@ typedef enum cl_arg_type { ArgTypePointer, ArgTypeImage, ArgTypeSampler, + ArgTypePipe, } cl_arg_type; typedef struct cl_argument { diff --git a/src/cl_mem.h b/src/cl_mem.h index 4764401..708a514 100644 --- a/src/cl_mem.h +++ b/src/cl_mem.h @@ -116,6 +116,10 @@ typedef struct _cl_mem { ((cl_base_object)mem)->magic == CL_OBJECT_MEM_MAGIC && \ CL_OBJECT_GET_REF(mem) >= 1 && \ mem->type < CL_MEM_IMAGE_TYPE)) +#define CL_OBJECT_IS_SUB_BUFFER(mem) ((mem && \ + ((cl_base_object)mem)->magic == CL_OBJECT_MEM_MAGIC && \ + CL_OBJECT_GET_REF(mem) >= 1 && \ + mem->type == CL_MEM_SUBBUFFER_TYPE)) typedef struct _cl_mem_pipe { _cl_mem base; diff --git a/src/gen/cl_command_queue_gen.c b/src/gen/cl_command_queue_gen.c index 1f3e1c1..4e8e5a9 100644 --- a/src/gen/cl_command_queue_gen.c +++ b/src/gen/cl_command_queue_gen.c @@ -270,7 +270,7 @@ gen_gpgpu_setup_global_mem(cl_kernel kernel, cl_kernel_gen kernel_gen, gen_gpgpu DEV_PRIVATE_DATA(kernel->program, gpu->device, prog_gen); for (i = 0; i < kernel->arg_n; i++) { - if (kernel->args[i].arg_type != ArgTypePointer) + if (kernel->args[i].arg_type != ArgTypePointer && kernel->args[i].arg_type != ArgTypePipe) continue; if (kernel->args[i].arg_addrspace != AddressSpaceGlobal && @@ -288,7 +288,7 @@ gen_gpgpu_setup_global_mem(cl_kernel kernel, cl_kernel_gen kernel_gen, gen_gpgpu } bti = kernel_gen->arg_extra_info[i].arg_misc; - if (CL_OBJECT_IS_BUFFER(mem)) + if (CL_OBJECT_IS_SUB_BUFFER(mem)) offset += ((struct _cl_mem_buffer *)mem)->sub_offset; if (gpu->mem.max_bti < bti) -- 2.7.4 _______________________________________________ Beignet mailing list Beignet@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/beignet