Skip to content

Commit

Permalink
basic/pthread: compile static WG size even if dynamic WG binaries exist
Browse files Browse the repository at this point in the history
Previously, pocl's basic/pthread driver used dynamic WG binaries first
if they were available, even if pocl was built with LLVM (= able to
build a static WG binary).

As consequence, PyOpenCL always used dynamic WG binaries, since it calls
clGetProgramInfo(BINARIES) right after it builds a program, which triggers
a build of dynamic WG binaries.

This commit changes pocl_check_kernel_disk_cache() to call llvm_codegen() even
if a dynamic WG binary already exists.
  • Loading branch information
franz committed Mar 26, 2019
1 parent a4f6c4c commit 44100cf
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 39 deletions.
83 changes: 46 additions & 37 deletions lib/CL/devices/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@
*/

#ifdef OCS_AVAILABLE
char *
llvm_codegen (unsigned device_i, cl_kernel kernel, cl_device_id device,
size_t local_x, size_t local_y, size_t local_z)
int
llvm_codegen (char *output, unsigned device_i, cl_kernel kernel,
cl_device_id device, size_t local_x, size_t local_y,
size_t local_z)
{
POCL_MEASURE_START (llvm_codegen);
int error = 0;
Expand Down Expand Up @@ -255,9 +256,12 @@ llvm_codegen (unsigned device_i, cl_kernel kernel, cl_device_id device,
POCL_MEASURE_FINISH (llvm_codegen);

if (error)
return NULL;
return error;
else
return strdup (final_binary_path);
{
memcpy (output, final_binary_path, POCL_FILENAME_LENGTH);
return 0;
}
}
#endif

Expand Down Expand Up @@ -933,48 +937,53 @@ pocl_check_kernel_disk_cache (_cl_command_node *cmd)
cl_program p = k->program;
unsigned dev_i = cmd->command.run.device_i;

if (p->binaries[dev_i] && !p->pocl_binaries[dev_i])
size_t x = cmd->command.run.local_x;
size_t y = cmd->command.run.local_y;
size_t z = cmd->command.run.local_z;

module_fn = malloc (POCL_FILENAME_LENGTH);
pocl_cache_final_binary_path (module_fn, p, dev_i, k, x, y, z);
if (pocl_exists (module_fn))
{
POCL_MSG_PRINT_INFO (
"For %zu x %zu x %zu, using static WG size binary: %s\n", x, y, z,
module_fn);
return module_fn;
}

if (p->binaries[dev_i])
{
#ifdef OCS_AVAILABLE

POCL_LOCK (pocl_llvm_codegen_lock);
module_fn = (char *)llvm_codegen (dev_i,
cmd->command.run.kernel,
cmd->device,
cmd->command.run.local_x,
cmd->command.run.local_y,
cmd->command.run.local_z);
int error = llvm_codegen (module_fn, dev_i, cmd->command.run.kernel,
cmd->device, x, y, z);
POCL_UNLOCK (pocl_llvm_codegen_lock);
if (module_fn == NULL)
if (error)
{
POCL_ABORT ("Final linking of kernel %s failed.\n", k->name);
}
POCL_MSG_PRINT_INFO("Using static WG size binary: %s\n", module_fn);
POCL_MSG_PRINT_INFO (
"For %zu x %zu x %zu, using static WG size binary: %s\n", x, y, z,
module_fn);
return module_fn;
#else
POCL_ABORT("pocl built without online compiler support"
" cannot compile LLVM IRs to machine code\n");
if (!p->pocl_binaries[dev_i])
POCL_ABORT ("pocl built without online compiler support"
" cannot compile LLVM IRs to machine code\n");
#endif
}
else
{
module_fn = malloc (POCL_FILENAME_LENGTH);
/* First try to find a static WG binary for the local size as they
are always more efficient than the dynamic ones. Also, in case
of reqd_wg_size, there might not be a dynamic sized one at all. */
pocl_cache_final_binary_path (module_fn, p, dev_i, k,
cmd->command.run.local_x,
cmd->command.run.local_y,
cmd->command.run.local_z);
if (!pocl_exists (module_fn))
{
pocl_cache_final_binary_path (module_fn, p, dev_i, k, 0, 0, 0);
if (!pocl_exists (module_fn))
POCL_ABORT("Dynamic WG size binary does not exist\n");
POCL_MSG_PRINT_INFO("Using dynamic local size binary: %s\n",
module_fn);
}
else
POCL_MSG_PRINT_INFO("Using static local size binary: %s\n", module_fn);
}

// pocl_binaries must exist
assert (p->pocl_binaries[dev_i]);

pocl_cache_final_binary_path (module_fn, p, dev_i, k, 0, 0, 0);
if (!pocl_exists (module_fn))
POCL_ABORT ("Can't find either static or dynamic WG size binary!\n");

POCL_MSG_PRINT_INFO (
"For %zu x %zu x %zu, using dynamic WG size binary: %s\n", x, y, z,
module_fn);
return module_fn;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/CL/devices/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ extern "C" {

void pocl_init_cpu_device_infos (cl_device_id dev);

char *llvm_codegen (unsigned device_i, cl_kernel kernel, cl_device_id device,
size_t local_x, size_t local_y, size_t local_z);
int llvm_codegen (char *output, unsigned device_i, cl_kernel kernel,
cl_device_id device, size_t local_x, size_t local_y,
size_t local_z);

void fill_dev_image_t (dev_image_t* di, struct pocl_argument* parg,
cl_device_id device);
Expand Down

0 comments on commit 44100cf

Please sign in to comment.