<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body smarttemplateinserted="true">
Hi Richard,<br>
<br>
as file names are concerned, I didn't found any information how
clang-tidy decides in which language the file is written. I made an
experiment and renamed simple Hello World program hello.cpp to
hello.frog and then run:<br>
<br>
`clang-tidy hello.frog --`<br>
<br>
with the Error while processing result. But then I found, that when
I invoke<br>
<br>
`clang-tidy hello.frog -- -xc++`<br>
<br>
everything works fine. So it means, that clang-tidy doesn't support
cuda files. Below is simple cuda program listing:<br>
<br>
```<br>
// simple_add.cu<br>
<br>
#include <algorithm><br>
#include <cmath><br>
#include <iostream><br>
#include <memory><br>
<br>
<br>
__global__<br>
void add(float *x, const float *y, int n) {<br>
int index = blockIdx.x * blockDim.x + threadIdx.x;<br>
<br>
// stride for grid size loop, so the kernel can be run with less
threads then<br>
// the sample size<br>
int stride = blockDim.x * gridDim.x;<br>
<br>
for (int i = index; i < n; i += stride) {<br>
x[i] = y[i] + x[i];<br>
}<br>
}<br>
<br>
int main(int argc, char** argv) {<br>
const int N = 1 << 20;<br>
<br>
const float val_x = 1.0f;<br>
const float val_y = 2.0f;<br>
// host memory initialization<br>
std::unique_ptr<float[]> x{new float[N]};<br>
std::unique_ptr<float[]> y{new float[N]};<br>
std::fill(x.get(), x.get() + N, val_x);<br>
std::fill(y.get(), y.get() + N, val_y);<br>
<br>
// device memory initialization<br>
float *d_x, *d_y;<br>
cudaMalloc((void**)&d_x, N * sizeof(float));<br>
cudaMalloc((void**)&d_y, N * sizeof(float));<br>
<br>
// copy to device<br>
cudaMemcpy(d_x, x.get(), N * sizeof(float),
cudaMemcpyHostToDevice);<br>
cudaMemcpy(d_y, y.get(), N * sizeof(float),
cudaMemcpyHostToDevice);<br>
<br>
// invoke the kernell<br>
const int blockSize = 256;<br>
const int numBlocks = (N + blockSize - 1) / blockSize;<br>
add<<<numBlocks, blockSize>>>(d_x, d_y, N);<br>
<br>
// copy out data from device<br>
cudaMemcpy(x.get(), d_x, N * sizeof(float),
cudaMemcpyDeviceToHost);<br>
<br>
// check output validity<br>
const float mean = val_x + val_y;<br>
float max_error = std::fabs(*std::max_element(x.get(), x.get() +
100,<br>
[](const float &a, const float &b) { return
std::fabs(a - mean) < std::fabs(b - mean); }) - mean);<br>
std::cout << "Max error: " << max_error <<
std::endl;<br>
<br>
// free device memory<br>
cudaFree(d_x);<br>
cudaFree(d_y);<br>
<br>
return 0;<br>
}<br>
```<br>
<br>
It can be compiled by nvcc:<br>
`nvcc -o simple_add -std=c++11 simple_add.cu`<br>
or by clang:<br>
`clang-tidy simple_add.cu -- clang++ -o simple_add simple_add.cu
-std=c++11 -L/usr/local/cuda/lib64 -lcudart_static -ldl -lrt
-pthread`<br>
<br>
but clang-tidy issued by<br>
`clang-tidy simple_add.cu -- nvcc -o simple_add -std=c++11`
simple_add.cu<br>
or<br>
`clang-tidy simple_add.cu -- clang++ -o simple_add -std=c++11
-L/usr/local/cuda/lib64 -lcudart_static -ldl -lrt -pthread
simple_add.cu`<br>
reports "Error while processing simple_add.cu."<br>
<br>
As can be seen from the above, clang can compile CUDA but clang-tidy
doesn't handle it. Is there any chance to support CUDA in clang-tidy
in near future?<br>
<br>
Versions of used software:<br>
Ubuntu 16.04<br>
clang 6.0.1 with libstdc++ + cuda 8.0<br>
gcc 5.4.0 with cuda 9.2<br>
<br>
Jakub<br>
<br>
<div id="smartTemplate4-quoteHeader">-----Original Message-----<br>
Subject: Re: [cfe-dev] clang-tidy and CUDA<br>
Sent: Wednesday, 4, 7. 2018 11:44<br>
From: <a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
To: <a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a></div>
<blockquote type="cite"
cite="mid:E1fa6OC-0002pA-I7@shell.xmission.com">
<pre wrap="">[Please reply *only* to the list and do not include my email directly
in the To: or Cc: of your reply; otherwise I will not see your reply.
Thanks.]
In article <a class="moz-txt-link-rfc2396E" href="mailto:a8b5d138-3a78-de72-181a-5271fec64a47@eyen.eu"><a8b5d138-3a78-de72-181a-5271fec64a47@eyen.eu></a>,
Jakub Klener via cfe-dev <a class="moz-txt-link-rfc2396E" href="mailto:cfe-dev@lists.llvm.org"><cfe-dev@lists.llvm.org></a> writes:
</pre>
<blockquote type="cite">
<pre wrap="">is it somehow possible to specify source file extension for clang-tidy,
can it for example parse ".cu" files? Is there some support for CUDA in
clang-tidy? I ran it on my CUDA source file (which I have to rename to
".cc" file because otherwise clang-tidy could not find it), specified
-D__CUDACC__, and it found error: unknown type
name '__host__' [clang-diagnostic-error].
</pre>
</blockquote>
<pre wrap="">
Are you using a compilation database or a command-line?
Either way, more information about exactly how you are invoking
clang-tidy is needed. AFAIK, clang-tidy doesn't care about the actual
filename.
</pre>
</blockquote>
<div class="moz-signature">
<pre>* Jakub Klener
* Eyen SE
* Pocernicka 272/96
* 108 00 Prague
* Czech Republic
* <a class="moz-txt-link-freetext" href="http://www.eyen.eu/">http://www.eyen.eu/</a></pre>
</div>
</body>
</html>