OpenCL clBuildProgram缓存源,并且如果#include的源发生更改,则不会重新编译 [英] OpenCL clBuildProgram caches source, and does not recompile if #include'd source changes

查看:507
本文介绍了OpenCL clBuildProgram缓存源,并且如果#include的源发生更改,则不会重新编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用opencl实施了一个项目.我有一个包含内核功能的文件,内核使用的功能包含在单独的头文件中,但是当我更改其中包含的文件时,有时会应用更改,而有时却没有应用,这使我感到困惑应用程序是否有错误.

I have implemented a project with opencl. I have a file which contains the kernel function and the functions which are used by the kernel are included in a seperate header file but when I change the file which is included, sometimes the changes are applied and sometimes they are not and it makes me confused if the application has bug or not.

我检查了stackoverflow中的其他帖子,发现nvidia传递-I{include directory}存在严重问题,因此我对其进行了更改,并明确给了头文件地址,但是opencl编译器仍然无法在头文件中找到错误.包含在内核文件名中.

I checked the other posts in stackoverflow and see nvidia has serious problem with passing -I{include directory}, so I changed it and give the header files address explicitly, but still the opencl compiler is not able to find the errors in the header file which is included in the kernel file name.

此外,我正在使用nvidia gtx 980,并且已经在计算机上安装了CUDA 7.0.

Also, I am using nvidia gtx 980 and I have intalled CUDA 7.0 on my computer.

任何人都有相同的经历吗?我该如何解决?

Anyone has the same experience? how can I fix it?

所以,假设我有一个这样的内核:

So, Assume I have a kernel like this:

#include "../../src/cl/test_kernel_include.cl"

void __kernel test_kernel(
  __global int* result,
  int n
  )
{
  int thread_idx = get_global_id(0);
  result[thread_idx] = test_func();
}

test_kernel_include.cl如下:

int test_func()
{
  return 1;
}

然后我运行代码,并得到一个数组,该数组的所有成员都等于我们期望的1.现在,我将test_kernel_include.cl更改为:

Then I run the code and I get an array which all the members are equal to 1 as we expect. Now, I change the test_kernel_include.cl to:

int test_func()
{
  return 2;
}

,但结果仍然是一个数组,所有成员都等于1,应更改为2,但不是.

but the result is still an array which all the members are equal to 1 which should change to 2 but they are not.

推荐答案

为了缩短内核编译时间,NVIDIA实施了一种缓存方案,将已编译的内核二进制文件存储到磁盘中,并在下次编译同一内核时进行加载.在内核源代码上会计算出一些哈希值,然后将这些哈希值用作已编译内核缓存的索引.

In order to improve kernel compilation times, NVIDIA implement a caching scheme, whereby a compiled kernel binary is stored to disk and loaded next time the same kernel is compiled. Some hash is computed on the kernel source code which is then used as the index into the compiled kernel cache.

不幸的是,这些散列不包括主内核源所包含的任何头文件.这意味着,当您更改包含的头文件中的内容时,驱动程序实质上将忽略该更改并从磁盘重新加载以前的内核二进制文件(除非主内核源中也进行了更改).

Unfortunately, these hashes do not include any header files that are included by the main kernel source. This means that when you change something in an included header file, the driver will essentially ignore the change and reload the previous kernel binary from disk (unless something changed in the main kernel source as well).

在Linux系统上,可以在~/.nv/ComputeCache中找到内核缓存.如果您在更改其中一个包含文件后删除了该目录,则它应强制驱动程序实际重新编译OpenCL内核.

On Linux systems, the kernel cache can be found in ~/.nv/ComputeCache. If you delete this directory after making a change to one of your include files, then it should force the driver to actually recompile the OpenCL kernel.

这篇关于OpenCL clBuildProgram缓存源,并且如果#include的源发生更改,则不会重新编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆