How to add watch sycl accessors in gdb?

Hello, I want to get values of accessor, but when I try to add it watch I got “no symbol operator in current context” error. Could somebody help?

Hello Kest,

I see what your problem may be. However, the information provided is quite limited in terms of no source code and/or specific steps taken are provided. So if this answer doesn’t get it fixed, feel free to provide those. :slightly_smiling_face:

Firstly, are you running your code on the host device or on OpenCL device because you will be able to take advantage of regular debuggers only when running on the host, thus use cl::sycl::host_selector{}

Second, the reason for getting a “no symbol operator in current context” is that either the compiler has optimized out some of your code, which is possible as operator[]() for accessors is a template, or you’re probably not setting your breakpoints at the correct place before setting a watchpoint on your variable.

I have tried debugging an example from the computecpp-sdk - simple-vector-add
and have successfully watched one of the read accessors, named accessorB.
What I have done, however, is to assign it to a local (auto) variable named b, set a breakpoint on that line, and then watched b. This is just a simple example of how you would do it.

I will provide you an output from the terminal to look at for a reference (below):

Reading symbols from ./samples/simple-vector-add/simple-vector-add...done.
(gdb) run
Starting program: /home/georgi/projects/code-of-conduct/computecpp-sdk/computecpp-sdk/build/samples/simple-vector-add/simple-vector-add 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff6112700 (LWP 24398)]
[New Thread 0x7ffff5911700 (LWP 24399)]
[New Thread 0x7ffff5110700 (LWP 24400)]
[New Thread 0x7ffff4400700 (LWP 24401)]
[Thread 0x7ffff5911700 (LWP 24399) exited]
[Thread 0x7ffff5110700 (LWP 24400) exited]
[Thread 0x7ffff6112700 (LWP 24398) exited]
[New Thread 0x7ffff5110700 (LWP 24403)]
[New Thread 0x7ffff5911700 (LWP 24404)]
[New Thread 0x7ffff6112700 (LWP 24405)]
[New Thread 0x7ffee64f2700 (LWP 24406)]
[New Thread 0x7ffee5cf1700 (LWP 24407)]
[New Thread 0x7ffee54f0700 (LWP 24408)]
[New Thread 0x7ffee4cef700 (LWP 24409)]
[New Thread 0x7ffedffff700 (LWP 24410)]
[Thread 0x7ffff5110700 (LWP 24403) exited]
[Thread 0x7ffff6112700 (LWP 24405) exited]
[Thread 0x7ffee64f2700 (LWP 24406) exited]
[Thread 0x7ffee5cf1700 (LWP 24407) exited]
[Thread 0x7ffff5911700 (LWP 24404) exited]
[Thread 0x7ffee54f0700 (LWP 24408) exited]
[Thread 0x7ffee4cef700 (LWP 24409) exited]
[Thread 0x7ffedffff700 (LWP 24410) exited]
[New Thread 0x7ffedffff700 (LWP 24411)]
[New Thread 0x7ffee4cef700 (LWP 24412)]
[New Thread 0x7ffee54f0700 (LWP 24413)]
[Thread 0x7ffedffff700 (LWP 24411) exited]
[Thread 0x7ffee54f0700 (LWP 24413) exited]
[New Thread 0x7ffee54f0700 (LWP 24414)]
[Thread 0x7ffee4cef700 (LWP 24412) exited]
[New Thread 0x7ffee4cef700 (LWP 24415)]
[New Thread 0x7ffedffff700 (LWP 24416)]
[New Thread 0x7ffee5cf1700 (LWP 24417)]
[New Thread 0x7ffff6112700 (LWP 24418)]
[New Thread 0x7ffff5911700 (LWP 24419)]
[New Thread 0x7ffff5110700 (LWP 24420)]
[New Thread 0x7ffee64f2700 (LWP 24421)]
[Thread 0x7ffee54f0700 (LWP 24414) exited]
[Thread 0x7ffee4cef700 (LWP 24415) exited]
[Thread 0x7ffedffff700 (LWP 24416) exited]
[Thread 0x7ffee5cf1700 (LWP 24417) exited]
[Thread 0x7ffff6112700 (LWP 24418) exited]
[Thread 0x7ffff5911700 (LWP 24419) exited]
The results are correct!
[Thread 0x7ffee64f2700 (LWP 24421) exited]
[Thread 0x7ffff5110700 (LWP 24420) exited]
[Thread 0x7ffff4400700 (LWP 24401) exited]
[Inferior 1 (process 24394) exited normally]
(gdb) break 60
Breakpoint 1 at 0x555555558354: /home/georgi/projects/code-of-conduct/computecpp-sdk/computecpp-sdk/samples/simple-vector-add/simple-vector-add.cpp:60. (2 locations)
(gdb) run
Starting program: /home/georgi/projects/code-of-conduct/computecpp-sdk/computecpp-sdk/build/samples/simple-vector-add/simple-vector-add 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff6112700 (LWP 24436)]
[New Thread 0x7ffff5911700 (LWP 24437)]
[New Thread 0x7ffff5110700 (LWP 24438)]
[New Thread 0x7ffff4400700 (LWP 24439)]
[Switching to Thread 0x7ffff5911700 (LWP 24437)]

Thread 3 "simple-vector-a" hit Breakpoint 1, void simple_vadd<int, 4ul>(std::array<int, 4ul> const&, std::array<int, 4ul> const&, std::array<int, 4ul>&)::{lambda(cl::sycl::handler&)#1}::operator()(cl::sycl::handler&) const:`:{lambda(cl::sycl::id<1>)#1}::operator()(cl::sycl::id) const (__closure=0x7ffed8000b40, 
    wiID=...) at /home/georgi/projects/code-of-conduct/computecpp-sdk/computecpp-sdk/samples/simple-vector-add/simple-vector-add.cpp:60
60	      auto b = accessorB[wiID];
(gdb) watch accessorB 
Watchpoint 2: accessorB
(gdb) watch b
Hardware watchpoint 3: b
(gdb) c
Continuing.

Thread 3 "simple-vector-a" hit Hardware watchpoint 3: b

Old value = 32767
New value = 1
void simple_vadd<int, 4ul>(std::array<int, 4ul> const&, std::array<int, 4ul> const&, std::array<int, 4ul>&)::{lambda(cl::sycl::handler&)#1}::operator()(cl::sycl::handler&) const::{lambda(cl::sycl::id<1>)#1}::operator()(cl::sycl::id) const (__closure=0x7ffed8000b40, wiID=...)
    at /home/georgi/projects/code-of-conduct/computecpp-sdk/computecpp-sdk/samples/simple-vector-add/simple-vector-add.cpp:61
61	      accessorC[wiID] = accessorA[wiID] + accessorB[wiID];

Hello, Georgi,

  1. Thanks, you answered my question about accessors debugging practice. I was thinking it is possible to watch it’s corresponding memory values like simple array (for example if I want to watch 10 values not one).
  2. About "No symbol operator [] in current context": I use vscode to debug with gdb, debug output is here:
=thread-group-added,id="i1"
GNU gdb (GDB) 8.2.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
Stopped due to shared library event (no libraries added or removed)
Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Breakpoint 1, main () at /home/kest/Projects/syclTest/syclTest.cpp:25
25	{
[New Thread 0x7ffff7123700 (LWP 3193)]
[New Thread 0x7ffff6922700 (LWP 3194)]
[New Thread 0x7ffff6121700 (LWP 3195)]
[New Thread 0x7ffff279f700 (LWP 3196)]
[New Thread 0x7ffff1f9e700 (LWP 3197)]
[New Thread 0x7ffff179d700 (LWP 3198)]
[New Thread 0x7ffff0f9c700 (LWP 3199)]
[New Thread 0x7fffd7fff700 (LWP 3200)]
[Switching to Thread 0x7fffd7fff700 (LWP 3200)]

Thread 9 "runSyclTest" hit Breakpoint 2, <lambda(cl::sycl::handler&)>::<lambda(cl::sycl::nd_item<2>)>::operator()(cl::sycl::nd_item<2>) const (__closure=0x7fffdc000b40, item=...) at /home/kest/Projects/syclTest/syclTest.cpp:90
90	                        Treg[i * size * size + y * size + x] = (y == 15) ? 10.f : 0;
Loaded '/opt/ComputeCpp-CE/lib/libComputeCpp.so'. Symbols loaded.
Loaded '/usr/lib/libOpenCL.so.1'. Symbols loaded.
Loaded '/usr/lib/libstdc++.so.6'. Symbols loaded.
Loaded '/usr/lib/libm.so.6'. Symbols loaded.
Loaded '/usr/lib/libgcc_s.so.1'. Symbols loaded.
Loaded '/usr/lib/libc.so.6'. Symbols loaded.
Loaded '/usr/lib/libdl.so.2'. Symbols loaded.
Loaded '/usr/lib/libpthread.so.0'. Symbols loaded.
Loaded '/usr/lib/libnvidia-opencl.so.1'. Symbols loaded.
Loaded '/usr/lib/librt.so.1'. Symbols loaded.
Loaded '/usr/lib/libnvidia-fatbinaryloader.so.430.14'. Symbols loaded.
Loaded '/usr/lib/libcuda.so.1'. Symbols loaded.
Execute debugger commands using "-exec <command>", for example "-exec info registers" will list registers in use (when GDB is the debugger)
-exec print T[1]

No symbol "operator[]" in current context.

syclTest.cpp (breakpoint at line 90):

#include <CL/sycl.hpp>

#include <iostream>
#include <fstream>
#include <time.h>
#include <sys/time.h>

using namespace cl::sycl;

class kernel1Name;
class kernel2Name;

double get_wall_time()
{
    struct timeval time;
    if (gettimeofday(&time, NULL))
    {
        //  Handle error
        return 0;
    }
    return (double)time.tv_sec + (double)time.tv_usec * .000001;
}

int main()
{
    const uint Ncount = 8;
    const uint size = 32;
    uint t_start, t_end;
    double wall0;

    //   float *V_YXHost = new float[cellCountX * cellCountY];
    float *THost = new float[size * size];
    float *TregHost = new float[size * size * Ncount];

    for (uint t = 0; t < Ncount; t++)
        for (uint y = 0; y < size; y++)
            for (uint x = 0; x < size; x++)
            {
                THost[y * size + x] = (x > 14 && x < 16) ? 10.f : 0;
                TregHost[t * size * size + y * size + x] = (x > 14 && x < 16) ? 10.f : 0;
            }

    try
    {
        // default_selector selector;
        host_selector selector;
        queue myQueue(selector, [](exception_list l) {
            for (auto ep : l)
            {
                try
                {
                    std::rethrow_exception(ep);
                }
                catch (const exception &e)
                {
                    std::cout << "Asynchronous exception caught:\n"
                              << e.what();
                }
            }
        });

        // buffer<float, 1> IBuff(IHost, range<1>(cellCountX * cellCountY));
        // buffer<float, 1> V_YXBuff(V_YXHost, range<1>(cellCountX * cellCountY));
        buffer<float, 1> TBuff(THost, range<1>(size * size));
        buffer<float, 1> TregBuff(THost, range<1>(size * size * Ncount));

        printf("Starting calc..\n");
        t_start = clock();
        wall0 = get_wall_time();

        for (uint i = 0; i < Ncount; i++)
        {
            myQueue.submit([&](handler &cgh) {
                stream out(1024, 256, cgh);

                auto T = TBuff.get_access<access::mode::read_write>(cgh);
                auto Treg = TregBuff.get_access<access::mode::read_write>(cgh);

                auto myRange = nd_range<2>(range<2>(size, size), range<2>(size / 8, size / 8));

                auto myKernel1 = ([i, size, T, Treg](nd_item<2> item) {
                    uint x = item.get_global_id()[0];
                    uint y = item.get_global_id()[1];

                    // if (x < size && y < size)
                    {
                        uint adrT = i * size * size;
                        uint adr = y * size + x;

                        Treg[i * size * size + y * size + x] = (y == 15) ? 10.f : 0;

                        // if (x > 0 && x < size - 1 && y > 0 && y < size - 1)
                        // {
                        //     float T0 = T[adr];
                        //     // float dx1 = T[size * y + x - 1] - T0;
                        //     // float dx2 = T[size * y + x + 1] - T0;
                        //     if (x == 15 && y == 15)
                        //     {
                        //         T0 += 1.f;
                        //         T[adr] = T0;
                        //         Treg[adrT + adr] = T0;
                        //         float aa = Treg[adrT + adr];
                        //         float bb = aa;
                        //     }
                        // }
                    }
                });
                cgh.parallel_for<kernel1Name>(myRange, myKernel1);
            });
        }
        //V_tYX_reg_ = V_tYX_regBuff.get_access<access::mode::read>();
    }
    catch (const exception &e)
    {
        std::cout << "Synchronous exception caught:\n"
                  << e.what();
        return 2;
    }
    printf("Calc. done.\n");
    t_end = clock();
    double wall1 = get_wall_time();

    std::cout << "Wall Time = " << wall1 - wall0 << std::endl;
    std::cout << "CPU time required for execution: "
              << (double)(t_end - t_start) / CLOCKS_PER_SEC
              << " seconds."
              << "\n";
    // writes output file

    FILE *f = fopen("trink.binary", "wb");
    if (f == NULL)
    {
        perror("Failed: ");
        return 1;
    }
    fwrite(TregHost, sizeof(float), size * size * Ncount, f);
    fclose(f);
    printf("File wrote.\n");
    return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.4.3)
project(syclTest)

set(CMAKE_BUILD_TYPE Debug)
# set(CMAKE_BUILD_TYPE Release)

set(COMPUTECPP_RUNTIME_LIBRARY /opt/ComputeCpp-CE/lib/libComputeCpp.so)
set(COMPUTECPP_RUNTIME_LIBRARY_DEBUG /opt/ComputeCpp-CE/lib/libComputeCpp.so)
set(ComputeCpp_INCLUDE_DIRS /opt/ComputeCpp-CE/include)
set(COMPUTECPP_BITCODE "ptx64")
# set(COMPUTECPP_USER_FLAGS "-O3 -std=c++14")

list(APPEND CMAKE_MODULE_PATH /home/kest/computecpp-sdk/cmake/Modules/)

find_package(ComputeCpp REQUIRED)

add_executable(runSyclTest ${CMAKE_CURRENT_SOURCE_DIR}/syclTest.cpp)
target_compile_options(runSyclTest PUBLIC -g -std=c++11 -Wall)
add_sycl_to_target(TARGET runSyclTest
  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/syclTest.cpp)

We can’t see the line numbers in the code so it’s not clear what line you are referring to. Have you investigated where it fails? The error suggests you are trying to use […] where it is not supported.

I think the problem is that VSCode is telling gdb to break on the wrong operator[] - there are 3 I think that could be relevant in this context.

I’ve never used VSCode + gdb before I’m afraid, you might be treading new ground - my recommendation is to try using gdb from the terminal, like @georgi suggests. You might also try setting a breakpoint on the first line of the kernel, and stepping from there.