-
Notifications
You must be signed in to change notification settings - Fork 26
Switch to go-nvml instead of gpu-monitoring-tools #12
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,26 @@ | ||
| // Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. | ||
| /** | ||
| # Copyright (c) NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| **/ | ||
|
|
||
| package gpuallocator | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "runtime" | ||
|
|
||
| "github.com/NVIDIA/gpu-monitoring-tools/bindings/go/nvml" | ||
| "github.com/NVIDIA/go-gpuallocator/internal/gpulib" | ||
| ) | ||
|
|
||
| // Allocator defines the primary object for allocating and freeing the | ||
|
|
@@ -45,9 +59,9 @@ func NewBestEffortAllocator() (*Allocator, error) { | |
|
|
||
| // NewAllocator creates a new Allocator using the given allocation policy | ||
| func NewAllocator(policy Policy) (*Allocator, error) { | ||
| err := nvml.Init() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error initializing NVML: %v", err) | ||
| ret := gpulib.Init() | ||
| if ret.Value() != gpulib.SUCCESS { | ||
| return nil, fmt.Errorf("error initializing NVML: %v", ret.Error()) | ||
| } | ||
|
|
||
| devices, err := NewDevices() | ||
|
|
@@ -58,8 +72,8 @@ func NewAllocator(policy Policy) (*Allocator, error) { | |
| allocator := newAllocatorFrom(devices, policy) | ||
|
|
||
| runtime.SetFinalizer(allocator, func(allocator *Allocator) { | ||
| // Explicitly ignore any errors from nvml.Shutdown(). | ||
| _ = nvml.Shutdown() | ||
| // Explicitly ignore any errors from gpulib.Shutdown(). | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renaming to |
||
| _ = gpulib.Shutdown() | ||
| }) | ||
|
|
||
| return allocator, nil | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,25 @@ | ||
| // Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. | ||
| /** | ||
| # Copyright (c) NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| **/ | ||
|
|
||
| package gpuallocator | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/NVIDIA/gpu-monitoring-tools/bindings/go/nvml" | ||
| "github.com/NVIDIA/go-gpuallocator/internal/gpulib" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment on renaming. That would mean that only the import statement changes in this file. |
||
| ) | ||
|
|
||
| type bestEffortPolicy struct{} | ||
|
|
@@ -313,41 +327,41 @@ func calculateGPUPairScore(gpu0 *Device, gpu1 *Device) int { | |
|
|
||
| for _, link := range gpu0.Links[gpu1.Index] { | ||
| switch link.Type { | ||
| case nvml.P2PLinkCrossCPU: | ||
| case gpulib.P2PLinkCrossCPU: | ||
| score += 10 | ||
| case nvml.P2PLinkSameCPU: | ||
| case gpulib.P2PLinkSameCPU: | ||
| score += 20 | ||
| case nvml.P2PLinkHostBridge: | ||
| case gpulib.P2PLinkHostBridge: | ||
| score += 30 | ||
| case nvml.P2PLinkMultiSwitch: | ||
| case gpulib.P2PLinkMultiSwitch: | ||
| score += 40 | ||
| case nvml.P2PLinkSingleSwitch: | ||
| case gpulib.P2PLinkSingleSwitch: | ||
| score += 50 | ||
| case nvml.P2PLinkSameBoard: | ||
| case gpulib.P2PLinkSameBoard: | ||
| score += 60 | ||
| case nvml.SingleNVLINKLink: | ||
| case gpulib.SingleNVLINKLink: | ||
| score += 100 | ||
| case nvml.TwoNVLINKLinks: | ||
| case gpulib.TwoNVLINKLinks: | ||
| score += 200 | ||
| case nvml.ThreeNVLINKLinks: | ||
| case gpulib.ThreeNVLINKLinks: | ||
| score += 300 | ||
| case nvml.FourNVLINKLinks: | ||
| case gpulib.FourNVLINKLinks: | ||
| score += 400 | ||
| case nvml.FiveNVLINKLinks: | ||
| case gpulib.FiveNVLINKLinks: | ||
| score += 500 | ||
| case nvml.SixNVLINKLinks: | ||
| case gpulib.SixNVLINKLinks: | ||
| score += 600 | ||
| case nvml.SevenNVLINKLinks: | ||
| case gpulib.SevenNVLINKLinks: | ||
| score += 700 | ||
| case nvml.EightNVLINKLinks: | ||
| case gpulib.EightNVLINKLinks: | ||
| score += 800 | ||
| case nvml.NineNVLINKLinks: | ||
| case gpulib.NineNVLINKLinks: | ||
| score += 900 | ||
| case nvml.TenNVLINKLinks: | ||
| case gpulib.TenNVLINKLinks: | ||
| score += 1000 | ||
| case nvml.ElevenNVLINKLinks: | ||
| case gpulib.ElevenNVLINKLinks: | ||
| score += 1100 | ||
| case nvml.TwelveNVLINKLinks: | ||
| case gpulib.TwelveNVLINKLinks: | ||
| score += 1200 | ||
| } | ||
| } | ||
|
|
||
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.
Note: if we use:
or even rename the internal package to
nvmlhere it should highlight changes not related to this renaming below.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.
I would argue we just add them to go-nvlib's nvml wrapper directly and open a separate PR there
Uh oh!
There was an error while loading. Please reload this page.
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.
Sure. That's fine too. My point is that I don't want to have changes due to the rename in the same commit as this makes things difficult to review.
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.
@klueska Your point is to not commit the
internal/gpulibhere, but to merge the functionality in there intogo-nvlib/pkg/nvml? and remove from this PR