首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Visual Studio社区2017 cl.exe

Visual Studio社区2017 cl.exe
EN

Stack Overflow用户
提问于 2017-03-15 03:25:51
回答 5查看 45.7K关注 0票数 22

我正在Windows系统上编译一些CUDA内核。据我所知,nvcc编译器需要使用cl.exe才能在Windows系统上编译。实现这一点的主要方法是使用Visual Studio。因此,我已经安装了free community edition。之后,我预计VC目录中会有bin目录,如this onethis one等多个其他问题中所示。然而,我需要深入几个层次才能找到

代码语言:javascript
复制
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64\cl.exe

这个特定的项目旨在制作一个可以在多个不同的Windows系统上编译和使用的程序。我真的需要将cl.exe文件嵌套在这里吗?还是我错过了这里的某种安装步骤?我期待的是一条更短的路径:

代码语言:javascript
复制
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\bin\

最终,我需要一种尽可能简单的方法,让用户能够让他们的环境找到cl.exe文件。通常,这涉及(在最高级别)设置环境变量。

EN

回答 5

Stack Overflow用户

发布于 2017-11-04 18:33:58

我在不同的上下文中遇到了这个问题(Elixir/Phoenix,Rust),但根本原因是相同的:在编译过程中找不到cl.exe

我的设置是:

已安装

  • Windows10,x64
  • Visual Studio社区2017,但仅适用于C#开发

由于某些原因,安装Visual C++ Build Tools的解决方案(如@cozzamara所建议的)不起作用。在安装过程中停止,并显示一些模糊的错误消息。我猜它不喜欢我现有的Visual Studio安装。

我是这样解决这个问题的:

在编译之前,启动Visual Studio Installer

C:\Program Files (x86)\Microsoft Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat

从这里开始,命令cl.exe起作用了。或者(更便于开发)启动应用程序'Developer Command Prompt for VS 2017‘或'x64本地工具命令提示符VS 2017’。

票数 16
EN

Stack Overflow用户

发布于 2017-03-15 03:29:59

寻找VCVARSALL.BAT --这通常是在更高的级别。如果你运行它,它会设置你的环境,这样你就可以不带路径地调用CL了。

这里的文档:https://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx

票数 9
EN

Stack Overflow用户

发布于 2018-12-04 10:02:27

我尝试了Theo的配置Visual Studio的解决方案,但这对我不起作用。我在Windows 10 CUDA工具包10.0上运行Visual Studio Community 2017。准确地说,我访问了C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build并运行了vcvarsamd64_x86.bat。因为找不到cl.exe,所以我的PyCUDA仍然无法编译。

我最终在Visual Studio 2017上创建了一个测试CUDA项目(“文件”-->“新建项目”),并在左侧选择了适当的CUDA。

然后我构建了(Ctrl+Shift+B或转到'Build'--> 'Build Solution')显示的示例(这是一个简单的向量加法,如下所示)。

代码语言:javascript
复制
#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>

cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size);

__global__ void addKernel(int *c, const int *a, const int *b)
{
    int i = threadIdx.x;
    c[i] = a[i] + b[i];
}

int main()
{
    const int arraySize = 5;
    const int a[arraySize] = { 1, 2, 3, 4, 5 };
    const int b[arraySize] = { 10, 20, 30, 40, 50 };
    int c[arraySize] = { 0 };

    // Add vectors in parallel.
    cudaError_t cudaStatus = addWithCuda(c, a, b, arraySize);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "addWithCuda failed!");
        return 1;
    }

    printf("{1,2,3,4,5} + {10,20,30,40,50} = {%d,%d,%d,%d,%d}\n",
        c[0], c[1], c[2], c[3], c[4]);

    // cudaDeviceReset must be called before exiting in order for profiling and
    // tracing tools such as Nsight and Visual Profiler to show complete traces.
    cudaStatus = cudaDeviceReset();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaDeviceReset failed!");
        return 1;
    }

    return 0;
}

// Helper function for using CUDA to add vectors in parallel.
cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size)
{
    int *dev_a = 0;
    int *dev_b = 0;
    int *dev_c = 0;
    cudaError_t cudaStatus;

    // Choose which GPU to run on, change this on a multi-GPU system.
    cudaStatus = cudaSetDevice(0);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaSetDevice failed!  Do you have a CUDA-capable GPU installed?");
        goto Error;
    }

    // Allocate GPU buffers for three vectors (two input, one output)    .
    cudaStatus = cudaMalloc((void**)&dev_c, size * sizeof(int));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
        goto Error;
    }

    cudaStatus = cudaMalloc((void**)&dev_a, size * sizeof(int));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
        goto Error;
    }

    cudaStatus = cudaMalloc((void**)&dev_b, size * sizeof(int));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
        goto Error;
    }

    // Copy input vectors from host memory to GPU buffers.
    cudaStatus = cudaMemcpy(dev_a, a, size * sizeof(int), cudaMemcpyHostToDevice);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
        goto Error;
    }

    cudaStatus = cudaMemcpy(dev_b, b, size * sizeof(int), cudaMemcpyHostToDevice);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
        goto Error;
    }

    // Launch a kernel on the GPU with one thread for each element.
    addKernel<<<1, size>>>(dev_c, dev_a, dev_b);

    // Check for any errors launching the kernel
    cudaStatus = cudaGetLastError();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "addKernel launch failed: %s\n", cudaGetErrorString(cudaStatus));
        goto Error;
    }

    // cudaDeviceSynchronize waits for the kernel to finish, and returns
    // any errors encountered during the launch.
    cudaStatus = cudaDeviceSynchronize();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching addKernel!\n", cudaStatus);
        goto Error;
    }

    // Copy output vector from GPU buffer to host memory.
    cudaStatus = cudaMemcpy(c, dev_c, size * sizeof(int), cudaMemcpyDeviceToHost);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
        goto Error;
    }

Error:
    cudaFree(dev_c);
    cudaFree(dev_a);
    cudaFree(dev_b);

    return cudaStatus;
}

当构建成功后,我查看了用于运行构建的命令,其中包含以下路径:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64。我将其添加到环境变量PATH中,现在我的PyCUDA可以工作了!(当我访问该路径时,我发现了一个cl.exe)

TL;DR

使用Visual Studio创建并构建CUDA项目。构建它。成功后,查看build命令并将其中的路径复制到PATH。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42794845

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档