Packages icon indicating copy to clipboard operation
Packages copied to clipboard

CUDA support

Open PatWie opened this issue 6 years ago • 1 comments

CUDA relatively common. However, Sublime does not ship the syntax highlighting file. I currently use YAMLMacros to extend C++ by

%YAML 1.2
%TAG ! tag:yaml-macros:YAMLMacros.lib.extend:
---
!extend
_base: c++_backup.sublime-syntax2
name: C++ (Cuda)
file_extensions:
  - .cu
  - .cuh
  - cu.cc
contexts: !merge
  unique-constants: !prepend
      - match: \b(threadIdx|blockIdx|blockDim|gridDim).(x|y|z)\b
        scope: general.language.cuda.c++
      - match: \b(threadfence_system|threadfence_block|threadfence)\b
        scope: general.language.cuda.c++
      - match: \b__(syncthreads_count|syncthreads_and|syncthreads_or|syncthreads)\b
        scope: general.language.cuda.c++
      - match: \b__(shfl_down|shfl_xor|shfl_up|shfl)\b
        scope: general.language.cuda.c++
      - match: \b__(shared|restrict)__\b
        scope: general.language.cuda.c++
  operators:
      - match: <<<|>>>
        scope: kernel.language.cuda.c++

  unique-modifiers: !prepend
    - match: \b__(global|device|host|launch_bounds)__\b
      scope: device.language.cuda.c++

  unique-types: !prepend
    - match: \b(char1|uchar1|short1|ushort1|int1|uint1|long1|ulong1|float1|char2|uchar2|short2|ushort2|int2|uint2|long2|ulong2|float2|char3|uchar3|short3|ushort3|int3|uint3|long3|ulong3|float3|char4|uchar4|short4|ushort4|int4|uint4|long4|ulong4|float4|longlong1|ulonglong1|double1|longlong2|ulonglong2|double2|dim3)\b
      scope: storage.type.cuda.c++

and add the definitions:

        {
            "name": "CUDA_devices",
            "scope": "general.language.cuda.c++",
            "foreground": "var(nvidia_green)"
        },
        {
            "name": "CUDA_devices",
            "scope": "device.language.cuda.c++",
            "foreground": "var(nvidia_green)",
            "font_style": "italic"
        },
        {
            "name": "CUDA_devices",
            "scope": "kernel.language.cuda.c++",
            "foreground": "var(nvidia_green)"
        },

It kind of works Screenshot from 2019-03-28 11-32-38

Do you really want us to make pull-requests which contain definitions and additions based on some content generated by YAMLMacros?

I am happy to provide a PR if there is an elegant way to maintain it.

PatWie avatar Mar 28 '19 11:03 PatWie

When the next major version is released, I think you can use extends for this.

michaelblyons avatar Aug 19 '20 14:08 michaelblyons