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

Enable nvptx64-nvidia-cuda target #1

Merged
merged 11 commits into from
Jul 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
url = https://github.com/rust-lang/rust-installer.git
[submodule "src/liblibc"]
path = src/liblibc
url = https://github.com/rust-lang/libc.git
url = https://github.com/termoshtt/libc.git
[submodule "src/doc/nomicon"]
path = src/doc/nomicon
url = https://github.com/rust-lang-nursery/nomicon.git
Expand Down
449 changes: 449 additions & 0 deletions config.toml

Large diffs are not rendered by default.

25 changes: 24 additions & 1 deletion src/liballoc_system/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#![feature(core_intrinsics)]
#![feature(staged_api)]
#![feature(rustc_attrs)]
#![cfg_attr(any(unix, target_os = "cloudabi", target_os = "redox"), feature(libc))]
#![cfg_attr(any(unix, target_os = "cuda", target_os = "cloudabi", target_os = "redox"), feature(libc))]
#![rustc_alloc_kind = "lib"]

// The minimum alignment guaranteed by the architecture. This value is used to
Expand All @@ -35,6 +35,7 @@ const MIN_ALIGN: usize = 8;
#[cfg(all(any(target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "mips64",
target_arch = "nvptx64",
target_arch = "s390x",
target_arch = "sparc64")))]
#[allow(dead_code)]
Expand Down Expand Up @@ -349,3 +350,25 @@ mod platform {
}
}
}

#[cfg(target_os = "cuda")]
mod platform {
extern crate libc;

use core::alloc::{GlobalAlloc, Layout};
use System;

#[stable(feature = "alloc_system_type", since = "1.28.0")]
unsafe impl GlobalAlloc for System {
#[inline]
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
libc::malloc(layout.size()) as _
}

#[inline]
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
libc::free(ptr as *mut libc::c_void);
}
}

}
2 changes: 1 addition & 1 deletion src/liblibc
1 change: 1 addition & 0 deletions src/libpanic_abort/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub unsafe extern fn __rust_start_panic(_payload: usize) -> u32 {

#[cfg(any(target_os = "redox",
windows,
target_os = "cuda",
all(target_arch = "wasm32", not(target_os = "emscripten"))))]
unsafe fn abort() -> ! {
core::intrinsics::abort();
Expand Down
25 changes: 25 additions & 0 deletions src/libpanic_unwind/cuda.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use alloc::boxed::Box;
use core::any::Any;
use core::intrinsics;

pub fn payload() -> *mut u8 {
0 as *mut u8
}

pub unsafe fn cleanup(_ptr: *mut u8) -> Box<Any + Send> {
intrinsics::abort()
}

pub unsafe fn panic(_data: Box<Any + Send>) -> u32 {
intrinsics::abort()
}
4 changes: 4 additions & 0 deletions src/libpanic_unwind/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ mod imp;
#[path = "wasm32.rs"]
mod imp;

#[cfg(target_os = "cuda")]
#[path = "cuda.rs"]
mod imp;

mod dwarf;
mod windows;

Expand Down
2 changes: 2 additions & 0 deletions src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ supported_targets! {
("wasm32-unknown-unknown", wasm32_unknown_unknown),
("wasm32-experimental-emscripten", wasm32_experimental_emscripten),

("nvptx64-nvidia-cuda", nvptx64_nvidia_cuda),

("thumbv6m-none-eabi", thumbv6m_none_eabi),
("thumbv7m-none-eabi", thumbv7m_none_eabi),
("thumbv7em-none-eabi", thumbv7em_none_eabi),
Expand Down
34 changes: 34 additions & 0 deletions src/librustc_target/spec/nvptx64_nvidia_cuda.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/// Copied from wasm32-unknown-unknown

use super::{LinkerFlavor, Target, TargetOptions, PanicStrategy};

pub fn target() -> Result<Target, String> {
let opts = TargetOptions {
cpu: "sm_50".to_string(),
linker: None,
dynamic_linking: true,
only_cdylib: true,
executables: false,
exe_suffix: ".ptx".to_string(),
dll_prefix: "".to_string(),
dll_suffix: ".ptx".to_string(),
singlethread: true,
obj_is_bitcode: true,
panic_strategy: PanicStrategy::Abort,
.. Default::default()
};
Ok(Target {
llvm_target: "nvptx64-nvidia-cuda".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "64".to_string(),
target_c_int_width: "32".to_string(),
target_env: "".to_string(),
target_os: "cuda".to_string(),
target_vendor: "nvidia".to_string(),
data_layout: "e-i64:64-i128:128-v16:16-v32:32-n16:32:64".to_string(),
arch: "nvptx64".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: opts,
})
}

5 changes: 5 additions & 0 deletions src/libstd/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,11 @@ mod arch {
pub const ARCH: &'static str = "wasm32";
}

#[cfg(target_arch = "nvptx64")]
mod arch {
pub const ARCH: &'static str = "nvptx64";
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions src/libstd/os/linux/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub use self::arch::{off_t, ino_t, nlink_t, blksize_t, blkcnt_t, stat, time_t};
target_arch = "powerpc",
target_arch = "arm",
target_arch = "asmjs",
target_arch = "nvptx64",
target_arch = "wasm32"))]
mod arch {
use os::raw::{c_long, c_short, c_uint};
Expand Down
7 changes: 5 additions & 2 deletions src/libstd/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ cfg_if! {
} else if #[cfg(target_arch = "wasm32")] {
mod wasm;
pub use self::wasm::*;
} else if #[cfg(target_os = "cuda")] {
mod wasm; // FIXME Use same one
pub use self::wasm::*;
} else {
compile_error!("libstd doesn't compile for this platform yet");
}
Expand All @@ -62,7 +65,7 @@ cfg_if! {
if #[cfg(any(unix, target_os = "redox"))] {
// On unix we'll document what's already available
pub use self::ext as unix_ext;
} else if #[cfg(any(target_os = "cloudabi", target_arch = "wasm32"))] {
} else if #[cfg(any(target_os = "cloudabi", target_os = "cuda", target_arch = "wasm32"))] {
// On CloudABI and wasm right now the module below doesn't compile
// (missing things in `libc` which is empty) so just omit everything
// with an empty module
Expand All @@ -81,7 +84,7 @@ cfg_if! {
if #[cfg(windows)] {
// On windows we'll just be documenting what's already available
pub use self::ext as windows_ext;
} else if #[cfg(any(target_os = "cloudabi", target_arch = "wasm32"))] {
} else if #[cfg(any(target_os = "cloudabi", target_os = "cuda", target_arch = "wasm32"))] {
// On CloudABI and wasm right now the shim below doesn't compile, so
// just omit it
#[unstable(issue = "0", feature = "std_internals")]
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub mod bytestring;
pub mod process;

cfg_if! {
if #[cfg(any(target_os = "cloudabi", target_os = "l4re", target_os = "redox"))] {
if #[cfg(any(target_os = "cloudabi", target_os = "l4re", target_os = "redox", target_os = "cuda"))] {
pub use sys::net;
} else if #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] {
pub use sys::net;
Expand Down
8 changes: 7 additions & 1 deletion src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ fn use_color(opts: &TestOpts) -> bool {
}
}

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

#[cfg(target_os = "cuda")]
fn num_cpus() -> usize {
// FIXME: Should return number of CUDA cores?
1
}

#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
fn num_cpus() -> usize {
1
Expand Down
3 changes: 3 additions & 0 deletions src/libunwind/libunwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ pub const unwinder_private_data_size: usize = 2;
#[cfg(target_os = "emscripten")]
pub const unwinder_private_data_size: usize = 20;

#[cfg(target_os = "cuda")]
pub const unwinder_private_data_size: usize = 0;

#[repr(C)]
pub struct _Unwind_Exception {
pub exception_class: _Unwind_Exception_Class,
Expand Down