-
Notifications
You must be signed in to change notification settings - Fork 64
Update the existing structures to support accelerator array in variation and current sections #1921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bharathappali
wants to merge
1
commit into
kruize:mvp_demo
Choose a base branch
from
bharathappali:gpu-cur-var-1
base: mvp_demo
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/com/autotune/analyzer/adapters/MultiResourceRecommendationAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.autotune.analyzer.adapters; | ||
|
|
||
| import com.autotune.analyzer.recommendations.AcceleratorRecommendationItem; | ||
| import com.autotune.analyzer.recommendations.MultiResourceRecommendation; | ||
| import com.google.gson.*; | ||
| import java.lang.reflect.Type; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Serializes MultiResourceRecommendation as array (unwraps the wrapper) | ||
| */ | ||
| public class MultiResourceRecommendationAdapter | ||
| implements JsonSerializer<MultiResourceRecommendation>, JsonDeserializer<MultiResourceRecommendation> { | ||
|
|
||
| @Override | ||
| public JsonElement serialize(MultiResourceRecommendation src, Type typeOfSrc, JsonSerializationContext context) { | ||
| return context.serialize(src.getItems()); | ||
| } | ||
|
|
||
| @Override | ||
| public MultiResourceRecommendation deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) | ||
| throws JsonParseException { | ||
| Type listType = new com.google.gson.reflect.TypeToken<List<AcceleratorRecommendationItem>>(){}.getType(); | ||
| List<AcceleratorRecommendationItem> items = context.deserialize(json, listType); | ||
| return new MultiResourceRecommendation(items); | ||
| } | ||
| } | ||
|
|
||
37 changes: 37 additions & 0 deletions
37
src/main/java/com/autotune/analyzer/recommendations/AcceleratorRecommendationItem.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.autotune.analyzer.recommendations; | ||
|
|
||
| public class AcceleratorRecommendationItem implements ResourceRecommendation { | ||
| private String model; | ||
| private String partition; | ||
| private Integer count; | ||
| private RecommendationConfigItem compute; | ||
| private RecommendationConfigItem memory; | ||
|
|
||
| public AcceleratorRecommendationItem(String model, String partition, Integer count, RecommendationConfigItem compute, RecommendationConfigItem memory) { | ||
| this.model = model; | ||
| this.partition = partition; | ||
| this.count = count; | ||
| this.compute = compute; | ||
| this.memory = memory; | ||
| } | ||
|
|
||
| public String getModel() { | ||
| return model; | ||
| } | ||
|
|
||
| public String getPartition() { | ||
| return partition; | ||
| } | ||
|
|
||
| public Integer getCount() { | ||
| return count; | ||
| } | ||
|
|
||
| public RecommendationConfigItem getCompute() { | ||
| return compute; | ||
| } | ||
|
|
||
| public RecommendationConfigItem getMemory() { | ||
| return memory; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/com/autotune/analyzer/recommendations/MultiResourceRecommendation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.autotune.analyzer.recommendations; | ||
|
|
||
| import com.autotune.analyzer.adapters.MultiResourceRecommendationAdapter; | ||
| import com.google.gson.annotations.JsonAdapter; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Represents multiple resource recommendations (Accelerators array) | ||
| * Custom adapter ensures it serializes as array, not object | ||
| */ | ||
| @JsonAdapter(MultiResourceRecommendationAdapter.class) | ||
| public final class MultiResourceRecommendation implements ResourceRecommendation { | ||
| private List<AcceleratorRecommendationItem> items; | ||
|
|
||
| public MultiResourceRecommendation() { | ||
| this.items = new ArrayList<>(); | ||
| } | ||
|
|
||
| public MultiResourceRecommendation(List<AcceleratorRecommendationItem> items) { | ||
| this.items = items; | ||
| } | ||
|
|
||
| public List<AcceleratorRecommendationItem> getItems() { | ||
| return items; | ||
| } | ||
|
|
||
| public void setItems(List<AcceleratorRecommendationItem> items) { | ||
| this.items = items; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/java/com/autotune/analyzer/recommendations/ResourceRecommendation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package com.autotune.analyzer.recommendations; | ||
|
|
||
| public interface ResourceRecommendation { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Deserialization does not guard against non-array or null JSON and may produce a MultiResourceRecommendation with a null items list.
The adapter currently assumes
jsoncan always be deserialized intoList<AcceleratorRecommendationItem>and passes that (possibly null) list to the constructor. Consider:MultiResourceRecommendationwhenjsonisnullorJsonNull.jsonis aJsonArrayand throwing a clearJsonParseExceptionotherwise.This will keep
itemsnon-null and make failures more explicit and predictable.Suggested implementation:
To compile successfully, ensure the following import is present at the top of the file (if not already there):
import java.util.Collections;If it is missing, add it alongside the other imports in this class.