| 52 | } |
| 53 | |
| 54 | Status LocalExecutable::ValidateExecutionOptions( |
| 55 | const ExecutableRunOptions& run_options, const Backend& backend) { |
| 56 | if (run_options.stream() != nullptr) { |
| 57 | if (!run_options.stream()->ok()) { |
| 58 | return InvalidArgument("stream is uninitialized or in an error state"); |
| 59 | } |
| 60 | |
| 61 | // Check stream matches service platform. |
| 62 | const se::Platform* stream_platform = |
| 63 | run_options.stream()->parent()->platform(); |
| 64 | if (stream_platform != backend_->platform()) { |
| 65 | return InvalidArgument( |
| 66 | "stream is for platform %s, but service targets platform %s", |
| 67 | stream_platform->Name(), backend_->platform()->Name()); |
| 68 | } |
| 69 | |
| 70 | // Cannot specify device_ordinal with a stream. The stream determines these |
| 71 | // values. |
| 72 | if (run_options.device_ordinal() != -1) { |
| 73 | return InvalidArgument( |
| 74 | "cannot set both device ordinal and stream options in " |
| 75 | "ExecutableRunOptions; the stream determines the device ordinal"); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // Verify that the device the executable was built for is equivalent |
| 80 | // to the device it will run on. |
| 81 | int run_device_ordinal = run_options.device_ordinal(); |
| 82 | if (run_device_ordinal == -1) { |
| 83 | run_device_ordinal = run_options.stream() != nullptr |
| 84 | ? run_options.stream()->parent()->device_ordinal() |
| 85 | : backend_->default_device_ordinal(); |
| 86 | } |
| 87 | TF_ASSIGN_OR_RETURN(bool devices_equivalent, |
| 88 | backend_->devices_equivalent( |
| 89 | run_device_ordinal, build_options_.device_ordinal())); |
| 90 | if (!devices_equivalent) { |
| 91 | TF_ASSIGN_OR_RETURN(se::StreamExecutor * run_executor, |
| 92 | backend_->stream_executor(run_device_ordinal)); |
| 93 | TF_ASSIGN_OR_RETURN(se::StreamExecutor * build_executor, |
| 94 | backend_->stream_executor(build_device_ordinal())); |
| 95 | return InvalidArgument( |
| 96 | "executable is built for device %s of type \"%s\"; cannot run it on " |
| 97 | "device %s of type \"%s\"", |
| 98 | backend_->device_name(build_device_ordinal()), |
| 99 | build_executor->GetDeviceDescription().name(), |
| 100 | backend_->device_name(run_device_ordinal), |
| 101 | run_executor->GetDeviceDescription().name()); |
| 102 | } |
| 103 | |
| 104 | if (!run_options.allocator()) { |
| 105 | return InvalidArgument("an allocator must be provided to ExecuteLocally"); |
| 106 | } |
| 107 | |
| 108 | if (run_options.allocator()->platform() != backend.platform()) { |
| 109 | return InvalidArgument( |
| 110 | "allocator platform (%s) does not match service platform (%s)", |
| 111 | run_options.allocator()->platform()->Name(), |
nothing calls this directly
no test coverage detected