Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when lambda insert "__device__" "__host__",report error #10455

Closed
lishi8168797 opened this issue Feb 2, 2023 · 15 comments
Closed

when lambda insert "__device__" "__host__",report error #10455

lishi8168797 opened this issue Feb 2, 2023 · 15 comments
Labels
bug Feature: CUDA fixed Check the Milestone for the release in which the fix is or will be available. Language Service Visual Studio Inherited from Visual Studio
Milestone

Comments

@lishi8168797
Copy link

lishi8168797 commented Feb 2, 2023

Environment

  • OS and Version: ubuntu 20.04
  • VS Code Version: 1.74.3
  • C/C++ Extension Version: 1.14.0
  • If using SSH remote, specify OS of remote machine: no

Bug Summary and Steps to Reproduce

2023-02-02 16-03-54 的屏幕截图
please see red line
it can compile,but in vscode it report error and has a red line

Configuration and Logs

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/opt/ros/noetic/include",
                "/usr/local/cuda/include"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

Other Extensions

No response

Additional context

No response

@browntarik browntarik self-assigned this Feb 3, 2023
@browntarik browntarik added Language Service investigate: repro This issue's repro steps needs to be investigated/confirmed labels Feb 3, 2023
@browntarik
Copy link
Contributor

Thank you for submitting this issue! We are currently looking into it.

@browntarik
Copy link
Contributor

I am having a hard time reproducing your error, could you provide a simple test case to reproduce the error? Could you also provide the error output?

@browntarik browntarik added Automated test Issue or work item related to automated testing of extension more info needed The issue report is not actionable in its current state and removed Automated test Issue or work item related to automated testing of extension labels Feb 6, 2023
@Colengms
Copy link
Collaborator

Colengms commented Feb 9, 2023

Hi @lishi8168797 . It looks like you're using CUDA. Is the code you posted in an .cu (or .cuh) file?

If you're currently using a .cpp file, you might try renaming it to use .cu. Or, you could specify nvcc as the compilerPath to cause all .cpp files to be treated as CUDA. Or, you could use a compile_commands.json, or a custom configuration provider, to cause files to be configured exactly as built. The actual command line used to build the file will be considered in those cases.

Unfortunately, simply changing the language ID of the document to "CUDA C++" in the editor is insufficient to cause the C/C++ Extension to treat the file as CUDA. I've opened #10494 to address that specific scenario.

@lishi8168797
Copy link
Author

@browntarik
2023-02-09 10-59-47 的屏幕截图
it reported this error,and make other code after it error,in fact they are all correct.

@lishi8168797
Copy link
Author

lishi8168797 commented Feb 9, 2023

@Colengms yes,I am using CUDA,and it is a .cu file,but it still report this red line,and make other code after it also have red line,it bother me.
2023-02-09 10-59-47 的屏幕截图

@sean-mcmanus sean-mcmanus assigned Colengms and unassigned browntarik Feb 9, 2023
@sean-mcmanus sean-mcmanus added more info needed The issue report is not actionable in its current state and removed more info needed The issue report is not actionable in its current state labels Feb 9, 2023
@sean-mcmanus
Copy link
Collaborator

Can you provide the output of running the C/C++: Log Diagnostics command and/or look in that logging for an misconfiguration? I'm guessing you may need to set your compilerPath to the nvcc compiler or make sure gcc isn't being used instead.

@lishi8168797
Copy link
Author

sorry,I may not understand that "Can you provide the output of running the C/C++",because,this code run correct,it only report this error in vscode. Does C/C++ Extension provied "insert device in a lambda"?
And I set compiler with nvcc in c_cpp_properties.json,but it does not work.

@sean-mcmanus
Copy link
Collaborator

The C/C++: Log Diagnostics command is run from the VS Code command palette -- it can show what IntelliSense configuration is being used. It looks like something is causing the CUDA configuration to fail. @Colengms might have more info when he gets back.

@lishi8168797
Copy link
Author

@sean-mcmanus
Thank you,this my log:

-------- Diagnostics - 2023/2/10 10:26:20
Version: 1.14.1
Current Configuration:
{
"name": "Linux",
"includePath": [
"/media/lishi/work/图像点云预处理/点云预处理/ros_env/src/pcl_preprocessing/",
"/opt/ros/noetic/include",
"/usr/local/cuda/include"
],
"defines": [],
"compilerPath": "/usr/local/cuda/bin/nvcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64",
"compilerPathIsExplicit": true,
"cStandardIsExplicit": true,
"cppStandardIsExplicit": true,
"intelliSenseModeIsExplicit": true,
"mergeConfigurations": false,
"browse": {
"path": [
"${workspaceFolder}/
",
"/opt/ros/noetic/include",
"/usr/local/cuda/include"
],
"limitSymbolsToIncludedHeaders": true
}
}
Translation Unit Mappings:
[ /media/lishi/work/图像点云预处理/点云预处理/ros_env/src/pcl_preprocessing/src/octree/octree.cu ]:
/media/lishi/work/图像点云预处理/点云预处理/ros_env/src/pcl_preprocessing/src/octree/octree.cu
Translation Unit Configurations:
[ /media/lishi/work/图像点云预处理/点云预处理/ros_env/src/pcl_preprocessing/src/octree/octree.cu ]:
Process ID: 7754
Memory Usage: 553 MB
Compiler Path: /usr/bin/gcc
Includes:
/opt/ros/noetic/include
/usr/local/cuda-11.6/targets/x86_64-linux/include
/usr/include/c++/9
/usr/include/x86_64-linux-gnu/c++/9
/usr/include/c++/9/backward
/usr/lib/gcc/x86_64-linux-gnu/9/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
/media/lishi/work/图像点云预处理/点云预处理/ros_env/src/pcl_preprocessing/include
Defines:
CUDA_ARCH=520
CUDA_ARCH_LIST=520
CUDA_DOUBLE_MATH_FUNCTIONS
CUDACC
NVCC
CUDACC_VER_MAJOR=11
CUDACC_VER_MINOR=6
CUDACC_VER_BUILD=55
CUDA_API_VER_MAJOR=11
CUDA_API_VER_MINOR=6
NVCC_DIAG_PRAGMA_SUPPORT=1
Forced Includes:
/usr/local/cuda/include/cuda_runtime.h
Standard Version: c++14
IntelliSense Mode: linux-gcc-x64
Other Flags:
--g++
--gnu_version=90400
--cuda
Total Memory Usage: 553 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 38229

@sean-mcmanus
Copy link
Collaborator

Your logging does indicate that it's compiling in CUDA mode, so that looks like __device__ __host__ should be recognized -- I'll wait for @Colengms to get back to see if he has any ideas what could be going wrong. (I'm guessing the /usr/bin/gcc compiler path is just showing what nvcc uses to compile the C++ code with).

@sean-mcmanus sean-mcmanus removed the more info needed The issue report is not actionable in its current state label Feb 10, 2023
@Colengms
Copy link
Collaborator

Hi @lishi8168797 . If your file is being correctly interpreted as CUDA, and your code compiles properly, perhaps there is an issue with IntelliSense resulting in __host__ and __device__ (aka __attribute__((host)) and __attribute__((device))) not being recognized in certain contexts.

Can you provide a simple isolated example that we might pass along to our IntelliSense team, to further investigate the issue?

@lishi8168797
Copy link
Author

Hi @Colengms .This is my example,thanks for your help.

    float dim_x,dim_y,dim_z;
    float x_min,y_min_,z_min; 
    int depth_mult=1024;
    auto morton_func=[dim_x,dim_y,dim_z,depth_mult,x_min_,y_min_,z_min_]  
        __host__ __device__ 
        (const float& x,const float& y,const float& z,int& code){
        int cellx,celly,cellz;
        cellx = min((int)std::floor(depth_mult * (x-x_min_)/dim_x), depth_mult - 1);
        celly = min((int)std::floor(depth_mult * (y-y_min_)/dim_y), depth_mult - 1);
        cellz = min((int)std::floor(depth_mult * (z-z_min_)/dim_z), depth_mult - 1);
        //......................9876543210
        cellx = (cellx | (cellx << 10)) & 0x000f801f; //............98765..........43210
        cellx = (cellx | (cellx <<  4)) & 0x00e181c3; //........987....56......432....10
        cellx = (cellx | (cellx <<  2)) & 0x03248649; //......98..7..5..6....43..2..1..0
        cellx = (cellx | (cellx <<  2)) & 0x09249249; //....9..8..7..5..6..4..3..2..1..0
        //......................9876543210
        celly = (celly | (celly << 10)) & 0x000f801f; //............98765..........43210
        celly = (celly | (celly <<  4)) & 0x00e181c3; //........987....56......432....10
        celly = (celly | (celly <<  2)) & 0x03248649; //......98..7..5..6....43..2..1..0
        celly = (celly | (celly <<  2)) & 0x09249249; //....9..8..7..5..6..4..3..2..1..0
        celly=celly << 1;
        //......................9876543210
        cellz = (cellz | (cellz << 10)) & 0x000f801f; //............98765..........43210
        cellz = (cellz | (cellz <<  4)) & 0x00e181c3; //........987....56......432....10
        cellz = (cellz | (cellz <<  2)) & 0x03248649; //......98..7..5..6....43..2..1..0
        cellz = (cellz | (cellz <<  2)) & 0x09249249; //....9..8..7..5..6..4..3..2..1..0
        cellz=cellz << 2;
        code=cellx | celly | cellz;
    };

    thrust::for_each(thrust::device,thrust::make_zip_iterator(x_ptr,y_ptr,z_ptr,temp_code.begin()),
    thrust::make_zip_iterator(x_ptr+size,y_ptr+size,z_ptr+size,temp_code.begin()+size),
    thrust::make_zip_function(morton_func));

@Colengms
Copy link
Collaborator

Colengms commented Feb 13, 2023

Hi @lishi8168797 . I've opened an internal issue (1746549) against VS, as this issue is with the IntelliSense parser which is shared with VS.

@Colengms Colengms added Visual Studio Inherited from Visual Studio and removed investigate: repro This issue's repro steps needs to be investigated/confirmed labels Feb 13, 2023
@Colengms Colengms removed their assignment Feb 13, 2023
@Colengms Colengms added this to the Tracking milestone Feb 13, 2023
@sean-mcmanus sean-mcmanus modified the milestones: Tracking, 1.15.0 Feb 13, 2023
@sean-mcmanus sean-mcmanus added the fixed Check the Milestone for the release in which the fix is or will be available. label Mar 8, 2023
@sean-mcmanus
Copy link
Collaborator

The fix is available with 1.15.0 (pre-release): https://github.com/microsoft/vscode-cpptools/releases/tag/v1.15.0

@lishi8168797
Copy link
Author

The fix is available with 1.15.0 (pre-release): https://github.com/microsoft/vscode-cpptools/releases/tag/v1.15.0

It works well ! Thank you very much !

@github-actions github-actions bot locked and limited conversation to collaborators Jun 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Feature: CUDA fixed Check the Milestone for the release in which the fix is or will be available. Language Service Visual Studio Inherited from Visual Studio
Projects
None yet
Development

No branches or pull requests

4 participants