Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support generation of nvcc -gencode flags #430

Merged
merged 4 commits into from Jun 2, 2019

Conversation

@OpportunityLiu
Copy link
Contributor

commented May 31, 2019

使用 add_cugencodes 添加 -gencode 编译选项。

Usage:

includes("add_cucodegens.lua")

add_cugencodes('compute_50') -- -gencode=arch=compute_50,code=compute_50
add_cugencodes('compute_50,sm_52') -- -gencode=arch=compute_50,code=sm_52
add_cugencodes('sm_52') -- -gencode=arch=compute_52,code=sm_52
add_cugencodes('sm_50,sm_52') -- -gencode=arch=compute_50,code=[sm_50,sm_52]
add_cugencodes('compute_50,sm_52,sm_53') -- -gencode=arch=compute_50,code=[sm_52,sm_53]
add_cugencodes('native') -- match host cuda device
@waruqi

This comment has been minimized.

Copy link
Member

commented May 31, 2019

这种作为includes的扩展辅助接口来提供,不要加到内置api里面去,内置api除了特定编译器的add_xxflags之外,其他接口都是通用的,对不同语言都有可能用到。

请在 https://github.com/xmake-io/xmake/tree/master/xmake/includes 里面添加 add_cugencode.lua文件来定义

function add_cugencode(...)
    -- TODO
    -- add_cuflags("-gencode arch=compute_" .. sm .. ",code=compute_" .. sm)
    -- add_ldflags("-gencode arch=compute_" .. sm .. ",code=compute_" .. sm)
end

使用方式:

includes("add_cugencode.lua")

target("cuda_console")
    set_kind("binary")
    add_includedirs("inc")
    add_files("src/*.cu")

    add_cugencode("sm_30", "sm_35", "sm_37", "sm_50", "sm_52", "sm_60", "sm_61", "sm_70")
    add_cugencode("compute_70")
@OpportunityLiu

This comment has been minimized.

Copy link
Contributor Author

commented Jun 1, 2019

includes 里面没有raise和warnings,连math都没有。

看其他的都是用了一个option中转的,但是对于这个好像也不太合适?

@waruqi

This comment has been minimized.

Copy link
Member

commented Jun 1, 2019

如果要使用扩展模块,可以定义rule,在自定义脚本域实现它:

add_cucodegen.lua

-- define rule
rule("cuda.add_gencode")
    before_load(function (target)
        for _, sm in ipairs(target:values("cuda.gencode")) do
            -- target:add("cuflags", "-gencode arch=compute_" .. sm .. ",code=compute_" .. sm)
            -- target:add("ldflags", "-gencode arch=compute_" .. sm .. ",code=compute_" .. sm)
        end
    end)
rule_end()

-- apply rule
add_rules("cuda.add_gencode")

-- add cuda gencode to target
--
-- e.g.
-- includes("add_cugencode.lua")
-- target("test")
--    set_kind("binary")
--    add_files("src/*.cu")
--    add_cugencode("cm_30", "sm_35")
--
function add_cugencode(...)
    add_values("cuda.gencode", ...)
end
@OpportunityLiu

This comment has been minimized.

Copy link
Contributor Author

commented Jun 1, 2019

好像要写成

function add_cugencode(...)
    -- apply rule
    add_rules("cuda.add_gencode")
    add_values("cuda.gencode", ...)
end

add_rules 写外面不管用啊

@OpportunityLiu OpportunityLiu changed the title 支持 nvcc -gencode 选项 [WIP] 支持 nvcc -gencode 选项 Jun 1, 2019

@waruqi

This comment has been minimized.

Copy link
Member

commented Jun 1, 2019

就你刚这样写好了 add_rules有做过去重处理的 没啥问题

xmake/includes/add_cugencode.lua Outdated Show resolved Hide resolved
xmake/includes/add_cugencode.lua Outdated Show resolved Hide resolved
@OpportunityLiu

This comment has been minimized.

Copy link
Contributor Author

commented Jun 1, 2019

cuda 这个模板过于复杂了吧。。。
看其他的基本都是helloworld啊

@OpportunityLiu OpportunityLiu changed the title [WIP] 支持 nvcc -gencode 选项 支持 nvcc -gencode 选项 Jun 1, 2019

@OpportunityLiu

This comment has been minimized.

Copy link
Contributor Author

commented Jun 1, 2019

在 cuda10.1 @windows 和 cuda10.1@ubuntu cuda9.2@ubuntu 测试过了

@waruqi

This comment has been minimized.

Copy link
Member

commented Jun 1, 2019

我晚上细看下 现在有点事

xmake/includes/add_cugencode.lua Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
xmake/includes/add_cugencode.lua Outdated Show resolved Hide resolved
xmake/includes/add_cugencode.lua Outdated Show resolved Hide resolved
@waruqi

This comment has been minimized.

Copy link
Member

commented Jun 1, 2019

cuda 这个模板过于复杂了吧。。。
看其他的基本都是helloworld啊

我当初只是随手从cuda的examples里面调了一个 移过来的,你觉得复杂的话,可以改进下,提供个更精简的helloworld

@OpportunityLiu

This comment has been minimized.

Copy link
Contributor Author

commented Jun 2, 2019

差不多了

@OpportunityLiu OpportunityLiu force-pushed the OpportunityLiu:dev branch from 6097729 to f60e817 Jun 2, 2019

@OpportunityLiu

This comment has been minimized.

Copy link
Contributor Author

commented Jun 2, 2019

按照命名规则是不是应该叫 add_cugencodes ?

@waruqi

This comment has been minimized.

Copy link
Member

commented Jun 2, 2019

嗯 是的 改成add_cugencodes吧

@OpportunityLiu

This comment has been minimized.

Copy link
Contributor Author

commented Jun 2, 2019

改好了

@waruqi waruqi merged commit adf7265 into xmake-io:dev Jun 2, 2019

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@waruqi

This comment has been minimized.

Copy link
Member

commented Jun 2, 2019

ok, CHANGELOGS.md 里面也更新下吧。。

@waruqi waruqi added this to the v2.2.7 milestone Jun 2, 2019

@OpportunityLiu OpportunityLiu changed the title 支持 nvcc -gencode 选项 Support generation of nvcc -gencode flags Jun 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.