Skip to content

Commit dfc02e8

Browse files
committed
refactor(example): the CUDA rule package moves into the mcpplibs namespace
The rule is content this ecosystem wrote rather than anyone's upstream, so `mcpplibs` is its namespace by the same rule the rest of the index follows, and the module follows the namespace: `mcpplibs.rules.cuda`. It also makes the package publishable. The index entry for it points at this same directory inside an mcpp release tarball — the shape `grpcgen` already uses — and a descriptor's identity has to match the manifest it points at, so a package that stays in an `example` namespace can only ever be copied into the index rather than referenced there. Measured: `mcpp run` and `mcpp run --no-accel` both print 12 24 36 48 after a clean rebuild.
1 parent 49c4ebc commit dfc02e8

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import std;
22
import mcpp;
3-
import example.rules.cuda;
3+
import mcpplibs.rules.cuda;
44

55
// Everything the rule needs is in the manifest: the architectures in
66
// `[build] accel`, the device sources in the constrained glob, the toolkit
@@ -12,10 +12,10 @@ import example.rules.cuda;
1212
// is how the alternate route is measured without editing the manifest.
1313
int main() {
1414
mcpp::rerun_if_env_changed("MCPP_EXAMPLE_CUDA_ROUTE");
15-
example::rules::cuda::options opt;
15+
mcpplibs::rules::cuda::options opt;
1616
opt.includes = { "include" };
1717
if (const char* r = std::getenv("MCPP_EXAMPLE_CUDA_ROUTE"); r && *r)
18-
opt.which = std::string_view(r) == "nvcc" ? example::rules::cuda::route::nvcc
19-
: example::rules::cuda::route::clang;
20-
return example::rules::cuda::compile(opt) ? 0 : 1;
18+
opt.which = std::string_view(r) == "nvcc" ? mcpplibs::rules::cuda::route::nvcc
19+
: mcpplibs::rules::cuda::route::clang;
20+
return mcpplibs::rules::cuda::compile(opt) ? 0 : 1;
2121
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rules-cuda"
3-
namespace = "example"
3+
namespace = "mcpplibs"
44
version = "0.1.0"
55
description = "Compile CUDA device translation units: clang -x cuda by default, nvcc as the alternate route (role = object)"
66
license = "Apache-2.0"

examples/09-cuda-kernel/rules-cuda/src/rules-cuda.cppm

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ module;
4040
#include <dlfcn.h>
4141
#endif
4242

43-
export module example.rules.cuda;
43+
export module mcpplibs.rules.cuda;
4444

4545
import std;
4646
import mcpp;
4747

48-
export namespace example::rules::cuda {
48+
export namespace mcpplibs::rules::cuda {
4949

5050
enum class route { automatic, clang, nvcc };
5151

@@ -175,7 +175,7 @@ inline std::optional<toolkit> find_toolkit() {
175175
t.driver_dir = xpkg("libcuda-host-link");
176176
if (t.nvcc_root.empty() || t.cudart_root.empty()) {
177177
std::println(std::cerr,
178-
"example.rules.cuda: the toolkit is not declared.\n"
178+
"mcpplibs.rules.cuda: the toolkit is not declared.\n"
179179
" Name it under [xlings.workspace] and mcpp provisions it on first use:\n"
180180
" \"xim:cuda-nvcc\" = \"12.9.86\"\n"
181181
" \"xim:cuda-cudart\" = \"12.9.79\"\n"
@@ -399,15 +399,15 @@ inline std::vector<edge> plan(std::span<const std::string> sources, options opt
399399
std::vector<edge> out;
400400
const std::string root = mcpp::manifest_dir();
401401
if (root.empty()) {
402-
std::println(std::cerr, "example.rules.cuda: no mcpp build context -- this runs from build.mcpp");
402+
std::println(std::cerr, "mcpplibs.rules.cuda: no mcpp build context -- this runs from build.mcpp");
403403
return out;
404404
}
405405
const auto tg = parse_target(mcpp::accel());
406406
if (!tg.present || tg.archs.empty()) {
407407
// C19: a device build that names no device is refused HERE, not at
408408
// run time as `no kernel image is available for execution`.
409409
std::println(std::cerr,
410-
"example.rules.cuda: [build] accel names no CUDA architecture (accel = \"{}\").\n"
410+
"mcpplibs.rules.cuda: [build] accel names no CUDA architecture (accel = \"{}\").\n"
411411
" Write e.g. accel = \"cuda12.9+{{sm_89}} ptx>=89\" -- the set a build compiles\n"
412412
" for is a decision, and the machine's own hardware is a poor default for it.",
413413
mcpp::accel());
@@ -424,7 +424,7 @@ inline std::vector<edge> plan(std::span<const std::string> sources, options opt
424424
if (r == route::clang) {
425425
driver_cc = tcdir + "/bin/clang++";
426426
if (!std::filesystem::exists(driver_cc)) {
427-
std::println(std::cerr, "example.rules.cuda: the clang route needs the toolchain's clang++ at {}", driver_cc);
427+
std::println(std::cerr, "mcpplibs.rules.cuda: the clang route needs the toolchain's clang++ at {}", driver_cc);
428428
return out;
429429
}
430430
front = { driver_cc, "-x", "cuda", "-std=c++17", "-O2", "-fPIC",
@@ -436,7 +436,7 @@ inline std::vector<edge> plan(std::span<const std::string> sources, options opt
436436
if (!std::filesystem::exists(tk->nvcc_root + "/bin/" + tool))
437437
mcpp::warning(std::format("the toolkit payload has no {}; clang invokes it "
438438
"after generating PTX", tool).c_str());
439-
std::println("example.rules.cuda: clang route -- {} (toolkit {})", driver_cc, tk->nvcc_root);
439+
std::println("mcpplibs.rules.cuda: clang route -- {} (toolkit {})", driver_cc, tk->nvcc_root);
440440
} else {
441441
// nvcc drives the toolchain's own compiler, and refuses one newer than
442442
// the bound its header states. Read the bound; if exceeded, pass the
@@ -449,7 +449,7 @@ inline std::vector<edge> plan(std::span<const std::string> sources, options opt
449449
// a GCC toolchain; with an LLVM toolchain the clang route is the
450450
// one to take, and it is the default.
451451
std::println(std::cerr,
452-
"example.rules.cuda: the nvcc route needs a GCC host compiler; this project's "
452+
"mcpplibs.rules.cuda: the nvcc route needs a GCC host compiler; this project's "
453453
"toolchain is LLVM, whose clang uses libc++ and nvcc refuses it. Use the clang "
454454
"route (the default for an LLVM toolchain) or set [toolchain] to a gcc payload.");
455455
return out;
@@ -461,7 +461,7 @@ inline std::vector<edge> plan(std::span<const std::string> sources, options opt
461461
if (major_of(tg.version) < 13
462462
&& libc_declares_c23_pi_math(mcpp::toolchain_sysroot())) {
463463
std::println(std::cerr,
464-
"example.rules.cuda: toolkit {} redeclares the C23 functions cospi, sinpi and "
464+
"mcpplibs.rules.cuda: toolkit {} redeclares the C23 functions cospi, sinpi and "
465465
"rsqrt for the host without `noexcept`, and the C library this build compiles "
466466
"against declares them with it; nvcc's front end refuses the pair.\n"
467467
" Name a 13.x toolkit, whose headers leave them to the C library:\n"
@@ -496,7 +496,7 @@ inline std::vector<edge> plan(std::span<const std::string> sources, options opt
496496
driver_cc).c_str());
497497
} else {
498498
std::println(std::cerr,
499-
"example.rules.cuda: nvcc {} accepts gcc <= {} ({}), and this project's "
499+
"mcpplibs.rules.cuda: nvcc {} accepts gcc <= {} ({}), and this project's "
500500
"toolchain is gcc {}.\n"
501501
" Declare a gcc payload within the bound and the rule drives that one:\n"
502502
" [xlings.workspace]\n"
@@ -536,7 +536,7 @@ inline std::vector<edge> plan(std::span<const std::string> sources, options opt
536536
"nvcc cannot reach its own back-end: it invokes '{}' by name and that name "
537537
"does not resolve on the search path it states. On the 13.x line install "
538538
"xim:libnvvm beside xim:cuda-nvcc.", *missing).c_str());
539-
std::println("example.rules.cuda: nvcc route -- {} with -ccbin {}", tk->nvcc(), driver_cc);
539+
std::println("mcpplibs.rules.cuda: nvcc route -- {} with -ccbin {}", tk->nvcc(), driver_cc);
540540
}
541541

542542
// The link line gets its directories from here, not from the manifest: the
@@ -590,4 +590,4 @@ inline bool compile(options opt = {}) {
590590
return submit(edges);
591591
}
592592

593-
} // namespace example::rules::cuda
593+
} // namespace mcpplibs::rules::cuda

0 commit comments

Comments
 (0)