Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of xmake's added support for Cuda Code compilation

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the example analysis of Cuda code compilation support added by xmake, the content is very detailed, interested friends can refer to it, hope to be helpful to you.

Recently, we have studied the compilation environment of NVIDIA Cuda Toolkit, and in xmake 2.1.10 development version, we have added support for cuda compilation environment, which can compile * .cu code directly.

After downloading and installing Cuda SDK, install it to the / Developer/NVIDIA/CUDA-x.x directory by default on macosx. The corresponding SDK directory can be found on Windows through the environment variable of CUDA_PATH, while it will be installed to / usr/local/cuda directory by default under Linux.

When xmake executes the $xmake command to compile the * .cu code, it tries to probe these default installation directories, and then tries to call the nvcc compiler to compile the cuda program directly, in most cases, just execute:

$xmake creates and compiles the Cuda project

Before I compiled it, we could create an empty cuda project through xmake, for example:

$xmake create-l cuda test$ cd test$ xmake

Create a cuda code project named test with the-l parameter, and the execution output is as follows:

[00%]: ccache compiling.release src/main.cu [100%]: linking.release test

We can also try to run the cuda program directly:

$xmake run

Next, let's take a look at the xmake.lua file of the cuda project:

-- define target

Target ("test")-set kind set_kind ("binary")-add include directories add_includedirs ("inc")-add files add_files ("src/*.cu")-generate SASS code for each SM architecture for _, sm in ipairs ({"30", "35", "37", "50", "52", "60", "61") "70"} do add_cuflags ("- gencode arch=compute_".. Sm.. "code=sm_".. Sm) add_ldflags ("- gencode arch=compute_".. Sm.. "code=sm_".. Sm) end-- generate PTX code from the highest SM architecture to guarantee forward-compatibility sm = "70" add_cuflags ("- gencode arch=compute_".. Sm.. "code=compute_".. Sm) add_ldflags ("- gencode arch=compute_".. Sm.. "code=compute_".. Sm)

Most of them are similar to the project description of cuda Candle +. The only difference is that some compilation options specific to cuda code are set through Cmax. This part of the configuration can be adjusted according to users' needs.

For more information about add_cuflags, you can read the official documentation of xmake.

Configuration of Cuda compilation environment

By default, xmake can successfully detect the Cuda SDK environment installed in the system, and users do not need to do any additional configuration operations. Of course, if you encounter a situation that cannot be detected, you can also specify the path of Cuda SDK manually:

$xmake f-- cuda_dir=/usr/local/cuda$ xmake

To tell xmake where your current Cuda SDK installation directory is.

If you want to test xmake's probe support for the current cuda environment, you can run:

$xmake l detect.sdks.find_cuda_toolchains {linkdirs = {/ Developer/NVIDIA/CUDA-9.1/lib}, bindir = / Developer/NVIDIA/CUDA-9.1/bin, includedirs = {/ Developer/NVIDIA/CUDA-9.1/include}, cudadir = / Developer/NVIDIA/CUDA-9.1}

To test the detection situation, and even help contribute the relevant detection code find_cuda_toolchains.lua to improve the xmake detection process.

Other instructions

Note: support for cuda has just been completed and has not yet been officially released. For more information about xmake's support for cuda, see issues # 158.

If you want to try this feature, you can download and install the latest version of master, or download the windows 2.1.10-dev installation package.

This is the example analysis of xmake's new support for Cuda code compilation. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report