XCode和CUDA入门 [英] Getting started with XCode and CUDA

查看:241
本文介绍了XCode和CUDA入门的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我能够安装CUDA,它工作正常。
然而,我不知道如何设置XCode的CUDA。和在那里的帖子似乎是真的过时,充满了缺少的链接和文件。

So far I was able to install CUDA and it works fine. However, I have no idea how to set up XCode for CUDA. And the posts out there seem to be really outdated and full of missing links and files. Also XCode seem to have changed a lot since 2009.

开始,如果我创建一个新项目,我应该选择空或外部构建系统或其他?

To begin, If I create a new project should I choose "Empty" or "External Build System" or something else?

推荐答案

我建议使用CMake:

I suggest using CMake:

1)从 http://www.cmake.org/download/

2)创建 CMakeLists.txt main.cu

CMakeLists.txt

CMakeLists.txt

cmake_minimum_required(VERSION 3.3)
project(cuda_test)
find_package(CUDA REQUIRED)
cuda_add_executable(cuda_test main.cu)

main.cu (取自 http://thrust.github.io/

#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/generate.h>
#include <thrust/sort.h>
#include <thrust/copy.h>
#include <algorithm>
#include <cstdlib>

int main()
{
  thrust::host_vector<int> h_vec(32 << 20);
  std::generate(h_vec.begin(), h_vec.end(), rand);
  thrust::device_vector<int> d_vec = h_vec;
  thrust::sort(d_vec.begin(), d_vec.end());
  thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());
  return 0;
}

3)使用CMake GUI或命令行创建一个Xcode项目(以下使用cmake命令行)

3) Use CMake GUI or command line to create a Xcode project out of the above (the following uses the cmake command line)

cmake -G Xcode

这篇关于XCode和CUDA入门的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆