Встроенные функции CUDA не определены в соответствии с Intellisense Visual Studio.

У меня возникает ошибка компиляции в Visual Studio 2017 со следующим кодом CUDA (инструментарий версии 9.0):

__global__ void increment_atomic(int *g) {
// which thread is this?
int i = blockIdx.x *blockDim.x + threadIdx.x;

// each thread to increment consecutive element, wrapping at ARRAY_SIZE
i = i % ARRAY_SIZE;
atomicAdd(& g[i], 1);}

функция atomicAdd не распознается как идентификатор. основываясь на предложении, которое я обнаружил, я также проверяю параметр CUDA C/C++ --> Device, который установлен следующим образом: введите здесь описание изображения

Я также пытаюсь использовать calculate_20, sm_21, но безрезультатно. Есть идеи о правильной настройке VS?


person OPMendeavor    schedule 18.09.2017    source источник
comment
это фактическая ошибка сборки или просто проблема с интеллектом?   -  person Robert Crovella    schedule 19.09.2017
comment
Ты прав! Вчера было поздно, и в цикле попыток устранить следующую ошибку не удалось:   -  person OPMendeavor    schedule 19.09.2017
comment
Я отправил комментарий до его завершения! Я говорю, что ошибка была фактически только intellisense. Сборка кода сегодня утром не дает ошибок компиляции, и код работает отлично. Задача решена ;)   -  person OPMendeavor    schedule 19.09.2017
comment
@RobertCrovella: у меня два вопроса. Есть ли способ удалить такие блики IntelliSense, чтобы выиграть несколько часов ночью :)? Можете ли вы ответить на вопрос таким образом, чтобы пометить его как решенный?   -  person OPMendeavor    schedule 19.09.2017
comment
Есть множество вопросов о взаимодействии между CUDA и VS Intellisense, если вы хотите поискать идеи. Должно быть легко избавиться от обозначений на панели вывода ошибок, переключившись с Build + Intellisense на просто Build. Однако избавиться от красных подчеркиваний может быть сложнее, а в некоторых случаях вообще невозможно. Обычный совет — игнорировать красные подчеркивания, исходящие от кода CUDA, если только они не создают ошибку сборки. Что касается этого кода, ошибка IntelliSense не помешает вам создать правильный код с использованием atomicAdd.   -  person Robert Crovella    schedule 19.09.2017


Ответы (2)


Правильный способ исправить это — добавить встроенные вызовы туда, где IntelliSense сможет их найти, как показано ниже. Это имеет дополнительное преимущество, заключающееся в том, что вы получаете всплывающую справку об использовании и разрешенных параметрах функций.

В основном коде

#ifdef __INTELLISENSE__
    #include "intellisense_cuda_intrinsics.h"
#endif

включаемый файл intellisense_cida_intrinsics.h

#pragma once


#ifdef __INTELLISENSE__

#include <cuda.h>
#include "cuda_runtime.h"
#include "device_launch_parameters.h"


//    Reverse the bit order of a 32 bit unsigned integer. 
__device__ unsigned int __brev(unsigned int  x) {};

//Reverse the bit order of a 64 bit unsigned integer.
__device__ unsigned long long int __brevll(unsigned long long int x) {};


//Return selected bytes from two 32 bit unsigned integers.
__device__ unsigned int __byte_perm(unsigned int  x, unsigned int  y, unsigned int  s) {};


//Return the number of consecutive high - order zero bits in a 32 bit integer.
__device__ int __clz(int  x) {};


//Count the number of consecutive high - order zero bits in a 64 bit integer.
__device__ int __clzll(long long int x) {};


//Find the position of the least significant bit set to 1 in a 32 bit integer.
__device__ int __ffs(int  x) {};


//Find the position of the least significant bit set to 1 in a 64 bit integer.Concatenate hi : lo, shift left by shift & 31 bits, return the most significant 32 bits.
__device__ int __ffsll(long long int x) {};


//Concatenate hi : lo, shift left by shift & 31 bits, return the most significant 32 bits.
__device__ unsigned int __funnelshift_l(unsigned int  lo, unsigned int  hi, unsigned int  shift) {};


//Concatenate hi : lo, shift left by min(shift, 32) bits, return the most significant 32 bits.
__device__ unsigned int __funnelshift_lc(unsigned int  lo, unsigned int  hi, unsigned int  shift) {};


//Concatenate hi : lo, shift right by shift & 31 bits, return the least significant 32 bits.
__device__ unsigned int __funnelshift_r(unsigned int  lo, unsigned int  hi, unsigned int  shift) {};


//Concatenate hi : lo, shift right by min(shift, 32) bits, return the least significant 32 bits.
__device__ unsigned int __funnelshift_rc(unsigned int  lo, unsigned int  hi, unsigned int  shift) {};


//Compute average of signed input arguments, avoiding overflow in the intermediate sum.
__device__ int __hadd(int, int) {};


//Calculate the least significant 32 bits of the product of the least significant 24 bits of two integers.
__device__ int __mul24(int  x, int  y) {};


//Calculate the most significant 64 bits of the product of the two 64 bit integers.
__device__ long long int __mul64hi(long long int x, long long int y) {};


//Calculate the most significant 32 bits of the product of the two 32 bit integers.
__device__ int __mulhi(int  x, int  y) {};


//Count the number of bits that are set to 1 in a 32 bit integer.
__device__ int __popc(unsigned int  x) {};


//Count the number of bits that are set to 1 in a 64 bit integer.
__device__ int __popcll(unsigned long long int x) {};


//Compute rounded average of signed input arguments, avoiding overflow in the intermediate sum.
__device__ int __rhadd(int, int) {};


//Calculate | x − y | +z, the sum of absolute difference.
__device__ unsigned int __sad(int  x, int  y, unsigned int  z) {};


//Compute average of unsigned input arguments, avoiding overflow in the intermediate sum.
__device__ unsigned int __uhadd(unsigned int, unsigned int) {};


//Calculate the least significant 32 bits of the product of the least significant 24 bits of two unsigned integers.
__device__ unsigned int __umul24(unsigned int  x, unsigned int  y) {};


//Calculate the most significant 64 bits of the product of the two 64 unsigned bit integers.
__device__ unsigned long long int __umul64hi(unsigned long long int x, unsigned long long int y) {};


//Calculate the most significant 32 bits of the product of the two 32 bit unsigned integers.
__device__ unsigned int __umulhi(unsigned int  x, unsigned int  y) {};


//Compute rounded average of unsigned input arguments, avoiding overflow in the intermediate sum.
__device__ unsigned int __urhadd(unsigned int, unsigned int) {};


//Calculate | x − y | +z, the sum of absolute difference.
__device__ unsigned int __usad(unsigned int  x, unsigned int  y, unsigned int  z) {};

//////////////////////////////////////////////////////
//atomic functions

int atomicAdd(int* address, int val) {};
unsigned int atomicAdd(unsigned int* address, unsigned int val) {};
unsigned long long int atomicAdd(unsigned long long int* address, unsigned long long int val) {};
float atomicAdd(float* address, float val) {};
double atomicAdd(double* address, double val) {};

typedef int __half2;
typedef short __half;
__half2 atomicAdd(__half2* address, __half2 val) {};
__half atomicAdd(__half* address, __half val) {};

int atomicSub(int* address, int val) {};
unsigned int atomicSub(unsigned int* address, unsigned int val) {};

int atomicExch(int* address, int val) {};
unsigned int atomicExch(unsigned int* address, unsigned int val) {};
unsigned long long int atomicExch(unsigned long long int* address, unsigned long long int val) {};
float atomicExch(float* address, float val) {};

int atomicMin(int* address, int val) {};
unsigned int atomicMin(unsigned int* address, unsigned int val) {};
unsigned long long int atomicMin(unsigned long long int* address, unsigned long long int val) {};

int atomicMax(int* address, int val) {};
unsigned int atomicMax(unsigned int* address, unsigned int val) {};
unsigned long long int atomicMax(unsigned long long int* address, unsigned long long int val) {};

unsigned int atomicInc(unsigned int* address, unsigned int val) {};

unsigned int atomicDec(unsigned int* address, unsigned int val) {};

int atomicCAS(int* address, int compare, int val) {};
unsigned int atomicCAS(unsigned int* address, unsigned int compare, unsigned int val) {};
unsigned long long int atomicCAS(unsigned long long int* address,
    unsigned long long int compare,
    unsigned long long int val) {};
unsigned short int atomicCAS(unsigned short int* address,
    unsigned short int compare,
    unsigned short int val) {};

int atomicAnd(int* address, int val) {};
unsigned int atomicAnd(unsigned int* address,
    unsigned int val) {};
unsigned long long int atomicAnd(unsigned long long int* address,
    unsigned long long int val) {};

int atomicOr(int* address, int val) {};
unsigned int atomicOr(unsigned int* address,
    unsigned int val) {};
unsigned long long int atomicOr(unsigned long long int* address,
    unsigned long long int val) {};

int atomicXor(int* address, int val) {};
unsigned int atomicXor(unsigned int* address, unsigned int val) {};
unsigned long long int atomicXor(unsigned long long int* address, unsigned long long int val) {};

template <typename T>
unsigned int __match_any_sync(unsigned mask, T value) {};
template <typename T>
unsigned int __match_all_sync(unsigned mask, T value, int* pred) {};

template <typename T>
T __shfl_sync(unsigned mask, T var, int srcLane, int width = warpSize) {};
template <typename T>
T __shfl_up_sync(unsigned mask, T var, unsigned int delta, int width = warpSize) {};
template <typename T>
T __shfl_down_sync(unsigned mask, T var, unsigned int delta, int width = warpSize) {};
template <typename T>
T __shfl_xor_sync(unsigned mask, T var, int laneMask, int width = warpSize) {};
#endif

Обратите внимание, что я не включил все возможные встроенные функции, но вы можете просто скопировать и вставить их из CUDA документация по c(++) и математическая документация.

Также обратите внимание, что устаревшие методы исключены из приведенного выше списка по умолчанию.

person Johan    schedule 27.09.2019

Согласно комментарию Роберта Кровеллы выше, это просто проблема с интеллектом, которая подчеркивает несуществующую ошибку. Компиляция и последующий запуск кода не дают ошибок.

person OPMendeavor    schedule 20.09.2017
comment
Спасибо за добавление ответа на ваш вопрос. Пожалуйста, не забудьте вернуться через несколько дней и принять свой ответ, чтобы вопрос выпал из списка без ответа для тега CUDA. - person talonmies; 20.09.2017