Adds a "gpu_mode_candidates" opt for restricting allowed modes#2229
Adds a "gpu_mode_candidates" opt for restricting allowed modes#2229jmacnak wants to merge 2 commits intogoogle:mainfrom
Conversation
... as this is no longer needed now that the GpuMode enum from google@82b7702 google@827906f is used. Bug: b/489817289 Test: build
... and restructures the --gpu_mode=auto selection flow to be
1. get initial candidates
2. filter candidates based on requirements
3. select best remaining candidates
This also has the benefit of allowing the launcher to provide more
explicit messaging on a per requirement basis.
Bug: b/489817289
Test: bazel run //cuttlefish/package:cvd -- \
create \
--host_substitutions=all
Test: bazel run //cuttlefish/package:cvd -- \
create \
--host_substitutions=all \
--gpu_mode=gfxstream
Test: bazel run //cuttlefish/package:cvd -- \
create \
--host_substitutions=all \
--gpu_mode=gfxstream_guest_angle
Test: bazel run //cuttlefish/package:cvd -- \
create \
--host_substitutions=all \
--gpu_mode=gfxstream_guest_angle_host_swiftshader
Test: bazel run //cuttlefish/package:cvd -- \
create \
--host_substitutions=all \
--gpu_mode=guest_swiftshader
Test: <edit android-info.txt in android repo>
bazel run //cuttlefish/package:cvd -- \
create \
--host_substitutions=all
<observe changed candidates>
| AUTO = 0; | ||
| CUSTOM = 1; | ||
| DRM_VIRGL = 2; | ||
| GFXSTREAM = 3; | ||
| GFXSTREAM_GUEST_ANGLE = 4; | ||
| GFXSTREAM_GUEST_ANGLE_HOST_LAVAPIPE = 5; | ||
| GFXSTREAM_GUEST_ANGLE_HOST_SWIFTSHADER = 6; | ||
| GUEST_SWIFTSHADER = 7; | ||
| NONE = 8; |
There was a problem hiding this comment.
nit: proto enums should be prefixed with the enum name, i.e. GPU_MODE_AUTO:
| bool GpuModeRequirementsMet(const CommonState& common, const GpuMode gpu_mode) { | ||
| const auto requirements_it = kGpuModeRequirements.find(gpu_mode); | ||
| CHECK(requirements_it != kGpuModeRequirements.end()) | ||
| << "Failed to find requirements for mode " << GpuModeString(gpu_mode); |
There was a problem hiding this comment.
It would be convenient to define an AbseilStringify implementation for this enum so that CHECK and LOG can report it directly.
A format_as function would also allow using it with CF_EXPECTF.
| RequirementWithReason{ | ||
| .func = HostIsNotArm, | ||
| .success_explanation = "The host is not ARM64.", | ||
| .failure_explanation = | ||
| "The host is ARM64. Not enabling Gfxstream on ARM64 " | ||
| "until vhost-user-gpu " | ||
| "has been more thoroughly tested. Please explicitly " | ||
| "use " | ||
| "--gpu_mode=gfxstream or " | ||
| "--gpu_mode=gfxstream_guest_angle to enable " | ||
| "for now.", | ||
| }, |
There was a problem hiding this comment.
Some of these RequirementWithReason instances look duplicated between multiple GpuModes. Is it possible to declare these as named constants and reuse them between multiple std::vector<RequirementWithReason>s?
It might also make it easier to follow if the func implementations are defined closer to the RequirementWithReason instantiations. Alternatively they could also be replaced with anonymous functions if the RequirementWithReason instantiations are deduplicated anyway.
In case there are initialization order issues, it might be more reliable to define functions to return these values, e.g.
RequirementWithReason GuestSupportsGfxstream() {
return RequirementWithReason {
.func = [](const CommonState& common) {
return common.guest_config.gfxstream_supported;
},
.success_explanation = "The guest supports Gfxstream.",
.failure_explanation = "...",
};
}| } | ||
|
|
||
| bool IsLikelySoftwareRenderer(const std::string& renderer) { | ||
| const std::string lower_renderer = ToLower(renderer); |
| std::string success_explanation; | ||
| std::string failure_explanation; |
There was a problem hiding this comment.
Can these be std::string_views since they're all being initialized to constants?
| #else | ||
| const GpuMode gpu_mode = | ||
| SelectGpuMode(gpu_mode_arg, vmm, guest_config, graphics_availability); | ||
| SelectGpuMode(gpu_mode, vmm, guest_config, graphics_availability); |
There was a problem hiding this comment.
Should this be SelectGpuMode(gpu_mode_arg, ...? This is the statement that declares the gpu_mode variable.
| {config::DeviceType::Minidroid, DeviceType::Minidroid}, | ||
| {config::DeviceType::Go, DeviceType::Go}}; | ||
|
|
||
| static const std::unordered_map<config::GpuMode, GpuMode> kGpuModeMap = { |
There was a problem hiding this comment.
Can this use absl::NoDestructor or be dynamically allocated?
See the style guide section on Static and Global Variables
Note that references are not objects, and thus they are not subject to the constraints on destructibility. The constraint on dynamic initialization still applies, though. In particular, a function-local static reference of the form
static T& t = *new T;is allowed.
The *new ... strategy might be easier within function scope.
| std::string failure_explanation; | ||
| }; | ||
|
|
||
| const std::unordered_map<GpuMode, std::vector<RequirementWithReason>> |
There was a problem hiding this comment.
Can this use absl::NoDestructor or be dynamically allocated?
See the style guide section on Static and Global Variables
Note that references are not objects, and thus they are not subject to the constraints on destructibility. The constraint on dynamic initialization still applies, though. In particular, a function-local static reference of the form
static T& t = *new T;is allowed.
| CHECK(requirements_it != kGpuModeRequirements.end()) | ||
| << "Failed to find requirements for mode " << GpuModeString(gpu_mode); |
There was a problem hiding this comment.
I'm personally in favor of using Results even to cover "should never happen" cases related to implementation errors, but it's possible to make the case either way. For CHECK:
- "Should never happen" intent is clearer.
- Function signatures are simpler.
For Result:
- Captures the call stack via
CF_EXPECTchains without needing to capture it viagdb. - Gives callers the opportunity to do their own cleanup, rather than
abort-ing immediately.
| CHECK(json_candidates.isArray()) | ||
| << "Unexpected type for 'gpu_mode_candidates'."; |
There was a problem hiding this comment.
Same concern as other comment on CHECK.
... and restructures the --gpu_mode=auto selection flow to be
This also has the benefit of allowing the launcher to provide more explicit messaging on a per requirement basis.
Bug: b/489817289
Test: cvd create
Test: cvd create --gpu_mode=gfxstream
Test: cvd create --gpu_mode=gfxstream_guest_angle
Test: cvd create --gpu_mode=gfxstream_guest_angle_host_swiftshader