简体   繁体   English

OpenCL —在不同的设备上有不同的内核“ printf()”结果吗?

[英]OpenCL — Different kernel “printf()” results on different devices?

I've got a peculiar result from running a hello_world kernel that simply prints a buffer passed via the command queue. 通过运行hello_world内核,我得到了一个奇特的结果,该内核仅打印通过命令队列传递的缓冲区。 I am getting two different results from different devices on the same platform. 我从同一平台上的不同设备得到两个不同的结果。 See the bottom of the console output below: 请参阅以下控制台输出的底部:

Here is my kernel code: 这是我的内核代码:

__kernel void hello_world (__global char* message, int messageSize) {
    for (int i =0; i < messageSize; i++) {
        printf("%c", message[i]);
    }
}

and here is my function call: 这是我的函数调用:

  std::string message = "Hello World!";
  int messageSize = message.length();
  std::cout << "          ---> Creating Buffer... ";
  cl::Buffer buffer(CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(char) * messageSize, (char*)message.c_str());

  kernel.setArg(0,buffer);
  kernel.setArg(1,sizeof(int),&messageSize);
  std::cout << "Done!" << std::endl;

  for (cl_uint i = 0; i<m_deviceCount[m_currentPlatform]; i++) {
        std::cout << "          ---> Queuing Kernel Task on Device #"<< m_currentPlatform << "." << i << "... ";
        m_commandQueues[i].enqueueTask(kernel);
        std::cout << "Done!" << std::endl;
        std::cout << "          ---> Executing... Output:\n\n";
        m_commandQueues[i].finish();
        std::cout << "\n\n          ---> Done!" << std::endl;
    }

And my console output: 和我的控制台输出:

Found 1 Platforms

Platform #0:
  Name:  AMD Accelerated Parallel Processing
  Found  2 Devices
      Device #0.0:
          --> Name:               Juniper
          --> Vendor:             Advanced Micro Devices, Inc.
          --> Max Compute Units:  10
          --> Max Clock Freq:     850
          --> Global Mem Size:    512 MBs
          --> Local Mem Size:     32 KBs
          --> Hardware Version:   OpenCL 1.2 AMD-APP (1800.11)
          --> Software Version:   1800.11
          --> Open CL Version:    OpenCL C 1.2 
          --> Images Supported:   YES
      Device #0.1:
          --> Name:               Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
          --> Vendor:             GenuineIntel
          --> Max Compute Units:  8
          --> Max Clock Freq:     3796
          --> Global Mem Size:    15905 MBs
          --> Local Mem Size:     32 KBs
          --> Hardware Version:   OpenCL 1.2 AMD-APP (1800.11)
          --> Software Version:   1800.11 (sse2,avx)
          --> Open CL Version:    OpenCL C 1.2 
          --> Images Supported:   YES

    Using Platform With Most Available Devices: Platform #0
          ---> Creating Context.... Done!
          ---> Creating Command Queue for Device #0.0.... Done!
          ---> Creating Command Queue for Device #0.1.... Done!
          ---> Loading Program: hello_world.cl...
                  > Compiling... Done!
          ---> Creating Buffer... Done!

          ---> Queuing Kernel Task on Device #0.0... Done!
          ---> Executing... Output:

H(null)e(null)l(null)l(null)o(null) (null)W(null)o(null)r(null)l(null)d(null)!(null)

          ---> Done!
          ---> Queuing Kernel Task on Device #0.1... Done!
          ---> Executing... Output:

Hello World!

          ---> Done!

Does anyone know why the AMD GPU inserts "(null)" in between characters, while the Intel CPU not? 有谁知道为什么AMD GPU在字符之间插入“(null)”,而Intel CPU没有? Is that normal for AMD's implementation of OpenCL? AMD实施OpenCL是否正常?

I also tried to pull off the printf in kernel. 我还尝试过在内核中使用printf。 You can refer to my program at: 您可以在以下位置参考我的程序:

https://github.com/pradyotsn/opencl_printf https://github.com/pradyotsn/opencl_printf

Thank you 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM