Skip to content

Commit ccf0d69

Browse files
committedSep 22, 2015
Augmented CudaHostAction to carry device-side triple.
Differential Revision: http://reviews.llvm.org/D12893 llvm-svn: 248298
1 parent 2325675 commit ccf0d69

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed
 

‎clang/include/clang/Driver/Action.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,16 @@ class CudaDeviceAction : public Action {
160160
class CudaHostAction : public Action {
161161
virtual void anchor();
162162
ActionList DeviceActions;
163+
const char *DeviceTriple;
163164

164165
public:
165-
CudaHostAction(std::unique_ptr<Action> Input,
166-
const ActionList &DeviceActions);
166+
CudaHostAction(std::unique_ptr<Action> Input, const ActionList &DeviceActions,
167+
const char *DeviceTriple);
167168
~CudaHostAction() override;
168169

169170
ActionList &getDeviceActions() { return DeviceActions; }
170171
const ActionList &getDeviceActions() const { return DeviceActions; }
172+
const char *getDeviceTriple() const { return DeviceTriple; }
171173

172174
static bool classof(const Action *A) { return A->getKind() == CudaHostClass; }
173175
};

‎clang/lib/Driver/Action.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ CudaDeviceAction::CudaDeviceAction(std::unique_ptr<Action> Input,
6666
void CudaHostAction::anchor() {}
6767

6868
CudaHostAction::CudaHostAction(std::unique_ptr<Action> Input,
69-
const ActionList &DeviceActions)
70-
: Action(CudaHostClass, std::move(Input)), DeviceActions(DeviceActions) {}
69+
const ActionList &DeviceActions,
70+
const char *DeviceTriple)
71+
: Action(CudaHostClass, std::move(Input)), DeviceActions(DeviceActions),
72+
DeviceTriple(DeviceTriple) {}
7173

7274
CudaHostAction::~CudaHostAction() {
7375
for (auto &DA : DeviceActions)

‎clang/lib/Driver/Driver.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,13 +1246,18 @@ static std::unique_ptr<Action>
12461246
buildCudaActions(const Driver &D, const ToolChain &TC, DerivedArgList &Args,
12471247
const Arg *InputArg, std::unique_ptr<Action> HostAction,
12481248
ActionList &Actions) {
1249+
// Figure out which NVPTX triple to use for device-side compilation based on
1250+
// whether host is 64-bit.
1251+
const char *DeviceTriple = TC.getTriple().isArch64Bit()
1252+
? "nvptx64-nvidia-cuda"
1253+
: "nvptx-nvidia-cuda";
12491254
Arg *PartialCompilationArg = Args.getLastArg(options::OPT_cuda_host_only,
12501255
options::OPT_cuda_device_only);
12511256
// Host-only compilation case.
12521257
if (PartialCompilationArg &&
12531258
PartialCompilationArg->getOption().matches(options::OPT_cuda_host_only))
12541259
return std::unique_ptr<Action>(
1255-
new CudaHostAction(std::move(HostAction), {}));
1260+
new CudaHostAction(std::move(HostAction), {}, DeviceTriple));
12561261

12571262
// Collect all cuda_gpu_arch parameters, removing duplicates.
12581263
SmallVector<const char *, 4> GpuArchList;
@@ -1290,12 +1295,6 @@ buildCudaActions(const Driver &D, const ToolChain &TC, DerivedArgList &Args,
12901295
}
12911296
}
12921297

1293-
// Figure out which NVPTX triple to use for device-side compilation based on
1294-
// whether host is 64-bit.
1295-
const char *DeviceTriple = TC.getTriple().isArch64Bit()
1296-
? "nvptx64-nvidia-cuda"
1297-
: "nvptx-nvidia-cuda";
1298-
12991298
// Figure out what to do with device actions -- pass them as inputs to the
13001299
// host action or run each of them independently.
13011300
bool DeviceOnlyCompilation = PartialCompilationArg != nullptr;
@@ -1331,7 +1330,7 @@ buildCudaActions(const Driver &D, const ToolChain &TC, DerivedArgList &Args,
13311330
// Return a new host action that incorporates original host action and all
13321331
// device actions.
13331332
return std::unique_ptr<Action>(
1334-
new CudaHostAction(std::move(HostAction), DeviceActions));
1333+
new CudaHostAction(std::move(HostAction), DeviceActions, DeviceTriple));
13351334
}
13361335

13371336
void Driver::BuildActions(const ToolChain &TC, DerivedArgList &Args,

0 commit comments

Comments
 (0)
Please sign in to comment.