Skip to content

Commit

Permalink
Provide PTXLinker with fallback to internal target-cpu
Browse files Browse the repository at this point in the history
  • Loading branch information
denzp committed Jan 29, 2019
1 parent 899d936 commit 3f62445
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ci/docker/test-various/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
xz-utils

# FIXME: build the `ptx-linker` instead.
RUN curl -sL https://github.com/denzp/rust-ptx-linker/releases/download/v0.9.0-alpha.1/rust-ptx-linker.linux64.tar.gz | \
RUN curl -sL https://github.com/denzp/rust-ptx-linker/releases/download/v0.9.0-alpha.2/rust-ptx-linker.linux64.tar.gz | \
tar -xzvC /usr/bin

RUN curl -sL https://nodejs.org/dist/v9.2.0/node-v9.2.0-linux-x64.tar.xz | \
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_codegen_ssa/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,12 @@ impl<'a> Linker for PtxLinker<'a> {
}

fn finalize(&mut self) -> Command {
// Provide the linker with fallback to internal `target-cpu`.
self.cmd.arg("--fallback-arch").arg(match self.sess.opts.cg.target_cpu {
Some(ref s) => s,
None => &self.sess.target.target.options.cpu
});

::std::mem::replace(&mut self.cmd, Command::new(""))
}

Expand Down
7 changes: 5 additions & 2 deletions src/test/run-make/nvptx-binary-crate/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

ifeq ($(TARGET),nvptx64-nvidia-cuda)
all:
$(RUSTC) main.rs -Clink-arg=--arch=sm_60 --crate-type="bin" -O --target $(TARGET)
FileCheck main.rs --input-file $(TMPDIR)/main.ptx
$(RUSTC) main.rs --crate-type="bin" --target $(TARGET) -O -C link-arg=--arch=sm_60 -o $(TMPDIR)/main.link_arg.ptx
$(RUSTC) main.rs --crate-type="bin" --target $(TARGET) -O -C target-cpu=sm_60 -o $(TMPDIR)/main.target_cpu.ptx

FileCheck main.rs --input-file $(TMPDIR)/main.link_arg.ptx
FileCheck main.rs --input-file $(TMPDIR)/main.target_cpu.ptx
else
all:
endif
2 changes: 1 addition & 1 deletion src/test/run-make/nvptx-dylib-crate/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extern crate dep;

// Verify the default CUDA arch.
// CHECK: .target sm_20
// CHECK: .target sm_30
// CHECK: .address_size 64

// Make sure declarations are there.
Expand Down

0 comments on commit 3f62445

Please sign in to comment.