Skip to content
This repository was archived by the owner on Feb 9, 2020. It is now read-only.

Commit 498311b

Browse files
authored
Merge pull request #1 from termoshtt/nvptx
Enable nvptx64-nvidia-cuda target
2 parents 2532056 + ae61c97 commit 498311b

File tree

15 files changed

+563
-7
lines changed

15 files changed

+563
-7
lines changed

Diff for: .gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
url = https://github.com/rust-lang/rust-installer.git
1111
[submodule "src/liblibc"]
1212
path = src/liblibc
13-
url = https://github.com/rust-lang/libc.git
13+
url = https://github.com/termoshtt/libc.git
1414
[submodule "src/doc/nomicon"]
1515
path = src/doc/nomicon
1616
url = https://github.com/rust-lang-nursery/nomicon.git

Diff for: config.toml

+449
Large diffs are not rendered by default.

Diff for: src/liballoc_system/lib.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#![feature(core_intrinsics)]
1919
#![feature(staged_api)]
2020
#![feature(rustc_attrs)]
21-
#![cfg_attr(any(unix, target_os = "cloudabi", target_os = "redox"), feature(libc))]
21+
#![cfg_attr(any(unix, target_os = "cuda", target_os = "cloudabi", target_os = "redox"), feature(libc))]
2222
#![rustc_alloc_kind = "lib"]
2323

2424
// The minimum alignment guaranteed by the architecture. This value is used to
@@ -35,6 +35,7 @@ const MIN_ALIGN: usize = 8;
3535
#[cfg(all(any(target_arch = "x86_64",
3636
target_arch = "aarch64",
3737
target_arch = "mips64",
38+
target_arch = "nvptx64",
3839
target_arch = "s390x",
3940
target_arch = "sparc64")))]
4041
#[allow(dead_code)]
@@ -349,3 +350,25 @@ mod platform {
349350
}
350351
}
351352
}
353+
354+
#[cfg(target_os = "cuda")]
355+
mod platform {
356+
extern crate libc;
357+
358+
use core::alloc::{GlobalAlloc, Layout};
359+
use System;
360+
361+
#[stable(feature = "alloc_system_type", since = "1.28.0")]
362+
unsafe impl GlobalAlloc for System {
363+
#[inline]
364+
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
365+
libc::malloc(layout.size()) as _
366+
}
367+
368+
#[inline]
369+
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
370+
libc::free(ptr as *mut libc::c_void);
371+
}
372+
}
373+
374+
}

Diff for: src/liblibc

Diff for: src/libpanic_abort/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub unsafe extern fn __rust_start_panic(_payload: usize) -> u32 {
6363

6464
#[cfg(any(target_os = "redox",
6565
windows,
66+
target_os = "cuda",
6667
all(target_arch = "wasm32", not(target_os = "emscripten"))))]
6768
unsafe fn abort() -> ! {
6869
core::intrinsics::abort();

Diff for: src/libpanic_unwind/cuda.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use alloc::boxed::Box;
12+
use core::any::Any;
13+
use core::intrinsics;
14+
15+
pub fn payload() -> *mut u8 {
16+
0 as *mut u8
17+
}
18+
19+
pub unsafe fn cleanup(_ptr: *mut u8) -> Box<Any + Send> {
20+
intrinsics::abort()
21+
}
22+
23+
pub unsafe fn panic(_data: Box<Any + Send>) -> u32 {
24+
intrinsics::abort()
25+
}

Diff for: src/libpanic_unwind/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ mod imp;
8686
#[path = "wasm32.rs"]
8787
mod imp;
8888

89+
#[cfg(target_os = "cuda")]
90+
#[path = "cuda.rs"]
91+
mod imp;
92+
8993
mod dwarf;
9094
mod windows;
9195

Diff for: src/librustc_target/spec/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ supported_targets! {
361361
("wasm32-unknown-unknown", wasm32_unknown_unknown),
362362
("wasm32-experimental-emscripten", wasm32_experimental_emscripten),
363363

364+
("nvptx64-nvidia-cuda", nvptx64_nvidia_cuda),
365+
364366
("thumbv6m-none-eabi", thumbv6m_none_eabi),
365367
("thumbv7m-none-eabi", thumbv7m_none_eabi),
366368
("thumbv7em-none-eabi", thumbv7em_none_eabi),

Diff for: src/librustc_target/spec/nvptx64_nvidia_cuda.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// Copied from wasm32-unknown-unknown
2+
3+
use super::{LinkerFlavor, Target, TargetOptions, PanicStrategy};
4+
5+
pub fn target() -> Result<Target, String> {
6+
let opts = TargetOptions {
7+
cpu: "sm_50".to_string(),
8+
linker: None,
9+
dynamic_linking: true,
10+
only_cdylib: true,
11+
executables: false,
12+
exe_suffix: ".ptx".to_string(),
13+
dll_prefix: "".to_string(),
14+
dll_suffix: ".ptx".to_string(),
15+
singlethread: true,
16+
obj_is_bitcode: true,
17+
panic_strategy: PanicStrategy::Abort,
18+
.. Default::default()
19+
};
20+
Ok(Target {
21+
llvm_target: "nvptx64-nvidia-cuda".to_string(),
22+
target_endian: "little".to_string(),
23+
target_pointer_width: "64".to_string(),
24+
target_c_int_width: "32".to_string(),
25+
target_env: "".to_string(),
26+
target_os: "cuda".to_string(),
27+
target_vendor: "nvidia".to_string(),
28+
data_layout: "e-i64:64-i128:128-v16:16-v32:32-n16:32:64".to_string(),
29+
arch: "nvptx64".to_string(),
30+
linker_flavor: LinkerFlavor::Gcc,
31+
options: opts,
32+
})
33+
}
34+

Diff for: src/libstd/env.rs

+5
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,11 @@ mod arch {
973973
pub const ARCH: &'static str = "wasm32";
974974
}
975975

976+
#[cfg(target_arch = "nvptx64")]
977+
mod arch {
978+
pub const ARCH: &'static str = "nvptx64";
979+
}
980+
976981
#[cfg(test)]
977982
mod tests {
978983
use super::*;

Diff for: src/libstd/os/linux/raw.rs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub use self::arch::{off_t, ino_t, nlink_t, blksize_t, blkcnt_t, stat, time_t};
3636
target_arch = "powerpc",
3737
target_arch = "arm",
3838
target_arch = "asmjs",
39+
target_arch = "nvptx64",
3940
target_arch = "wasm32"))]
4041
mod arch {
4142
use os::raw::{c_long, c_short, c_uint};

Diff for: src/libstd/sys/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ cfg_if! {
4848
} else if #[cfg(target_arch = "wasm32")] {
4949
mod wasm;
5050
pub use self::wasm::*;
51+
} else if #[cfg(target_os = "cuda")] {
52+
mod wasm; // FIXME Use same one
53+
pub use self::wasm::*;
5154
} else {
5255
compile_error!("libstd doesn't compile for this platform yet");
5356
}
@@ -62,7 +65,7 @@ cfg_if! {
6265
if #[cfg(any(unix, target_os = "redox"))] {
6366
// On unix we'll document what's already available
6467
pub use self::ext as unix_ext;
65-
} else if #[cfg(any(target_os = "cloudabi", target_arch = "wasm32"))] {
68+
} else if #[cfg(any(target_os = "cloudabi", target_os = "cuda", target_arch = "wasm32"))] {
6669
// On CloudABI and wasm right now the module below doesn't compile
6770
// (missing things in `libc` which is empty) so just omit everything
6871
// with an empty module
@@ -81,7 +84,7 @@ cfg_if! {
8184
if #[cfg(windows)] {
8285
// On windows we'll just be documenting what's already available
8386
pub use self::ext as windows_ext;
84-
} else if #[cfg(any(target_os = "cloudabi", target_arch = "wasm32"))] {
87+
} else if #[cfg(any(target_os = "cloudabi", target_os = "cuda", target_arch = "wasm32"))] {
8588
// On CloudABI and wasm right now the shim below doesn't compile, so
8689
// just omit it
8790
#[unstable(issue = "0", feature = "std_internals")]

Diff for: src/libstd/sys_common/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub mod bytestring;
5656
pub mod process;
5757

5858
cfg_if! {
59-
if #[cfg(any(target_os = "cloudabi", target_os = "l4re", target_os = "redox"))] {
59+
if #[cfg(any(target_os = "cloudabi", target_os = "l4re", target_os = "redox", target_os = "cuda"))] {
6060
pub use sys::net;
6161
} else if #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] {
6262
pub use sys::net;

Diff for: src/libtest/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ fn use_color(opts: &TestOpts) -> bool {
979979
}
980980
}
981981

982-
#[cfg(any(target_os = "cloudabi", target_os = "redox",
982+
#[cfg(any(target_os = "cloudabi", target_os = "redox", target_os = "cuda",
983983
all(target_arch = "wasm32", not(target_os = "emscripten"))))]
984984
fn stdout_isatty() -> bool {
985985
// FIXME: Implement isatty on Redox
@@ -1207,6 +1207,12 @@ fn get_concurrency() -> usize {
12071207
1
12081208
}
12091209

1210+
#[cfg(target_os = "cuda")]
1211+
fn num_cpus() -> usize {
1212+
// FIXME: Should return number of CUDA cores?
1213+
1
1214+
}
1215+
12101216
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
12111217
fn num_cpus() -> usize {
12121218
1

Diff for: src/libunwind/libunwind.rs

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ pub const unwinder_private_data_size: usize = 2;
7171
#[cfg(target_os = "emscripten")]
7272
pub const unwinder_private_data_size: usize = 20;
7373

74+
#[cfg(target_os = "cuda")]
75+
pub const unwinder_private_data_size: usize = 0;
76+
7477
#[repr(C)]
7578
pub struct _Unwind_Exception {
7679
pub exception_class: _Unwind_Exception_Class,

0 commit comments

Comments
 (0)