NVIDIA / nsight-vscode-edition

A Visual Studio Code extension for building and debugging CUDA applications.
Other
72 stars 11 forks source link

Reference variables in lambdas don't show the values in the watch window while debugging #31

Closed Saitama10000 closed 5 months ago

Saitama10000 commented 1 year ago

Reference variables in lambdas don't show the values in the watch window while debugging.

Example code:

#include <iostream>
#include "cooperative_groups.h"
namespace cg = cooperative_groups;

template <typename _value_type, int _size>
class Array
{
public:
    using value_type = _value_type;
    __device__ __host__ constexpr Array(std::initializer_list<_value_type> l) { int i = 0; for (auto x : l) (*this)[i++] = x; }
    __device__ __host__ constexpr auto operator[](int i) const { return data[i]; }
    __device__ __host__ constexpr auto operator[](int i) -> auto& { return data[i]; }
    __device__ __host__ constexpr auto size() const { return _size; }
private:
    value_type data[_size]{};
};

__global__ void kernel()
{
    // not showing values of arr, references don't work?
    auto iota = []<typename T, int size>(Array<T, size>& arr, T start)
    {
        for (int i = 0; i < arr.size(); i++)
            arr[i] = start++;
    };

    // showing values of arr
    auto iota2 = []<typename T, int size>(Array<T, size> arr, T start)
    {
        for (int i = 0; i < arr.size(); i++)
            arr[i] = start++;
        return arr;
    };

    Array<int, 8> arr{};
    iota(arr, 0);
    arr = iota2(arr, 0);
}

int main()
{

    kernel<<<1, 8>>>();
    cudaDeviceSynchronize();
}

image image

I don't know if this is a bug, a known limitation or if I'm doing something wrong on my end.

sanannavyaa commented 1 year ago

What CTK version are you using?

Saitama10000 commented 1 year ago

@sanannavyaa 12.0.1

sanannavyaa commented 1 year ago

This is a cuda-gdb bug, thanks for reporting it. We're working on it! I will make sure to update this issue when the bug has been fixed.