Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gpuhw
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
gpuhw
Commits
7a2c46e8
Commit
7a2c46e8
authored
Mar 20, 2024
by
Ubuntu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
info
parent
2fd7188f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
218 additions
and
0 deletions
+218
-0
cpu.go
cpu.go
+41
-0
go.mod
go.mod
+1
-0
go.sum
go.sum
+2
-0
gpu.go
gpu.go
+123
-0
main.go
main.go
+19
-0
mem.go
mem.go
+32
-0
No files found.
cpu.go
0 → 100644
View file @
7a2c46e8
package
main
import
(
"fmt"
"github.com/jaypipes/ghw"
"github.com/pkg/errors"
// "github.com/pkg/errors"
// "github.com/spf13/cobra"
)
// cpuCmd represents the install command
// var cpuCmd = &cobra.Command{
// Use: "cpu",
// Short: "Show CPU information for the host system",
// RunE: showCPU,
// }
// showCPU show CPU information for the host system.
func
getCPU
()
([]
DeviceInfo
,
error
)
{
cpu
,
err
:=
ghw
.
CPU
()
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"error getting CPU info"
)
}
res
:=
make
([]
DeviceInfo
,
0
,
len
(
cpu
.
Processors
))
for
i
,
proc
:=
range
cpu
.
Processors
{
fmt
.
Printf
(
" %v
\n
"
,
proc
)
e
:=
DeviceInfo
{
Type
:
fmt
.
Sprintf
(
"proc-%d"
,
i
),
Model
:
proc
.
Model
,
Param
:
"proc.NumThreads"
,
Power
:
uint64
(
proc
.
NumThreads
),
}
res
=
append
(
res
,
e
)
}
return
res
,
nil
}
go.mod
View file @
7a2c46e8
...
@@ -5,6 +5,7 @@ go 1.22.1
...
@@ -5,6 +5,7 @@ go 1.22.1
require github.com/jaypipes/ghw v0.12.0
require github.com/jaypipes/ghw v0.12.0
require (
require (
github.com/NVIDIA/go-nvml v0.12.0-3 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
...
...
go.sum
View file @
7a2c46e8
github.com/NVIDIA/go-nvml v0.12.0-3 h1:QwfjYxEqIQVRhl8327g2Y3ZvKResPydpGSKtCIIK9jE=
github.com/NVIDIA/go-nvml v0.12.0-3/go.mod h1:SOufGc5Wql+cxrIZ8RyJwVKDYxfbs4WPkHXqadcbfvA=
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
...
...
gpu.go
0 → 100644
View file @
7a2c46e8
package
main
import
(
"fmt"
"log"
"github.com/NVIDIA/go-nvml/pkg/nvml"
)
func
getGPU
()
([]
DeviceInfo
,
error
)
{
ret
:=
nvml
.
Init
()
if
ret
!=
nvml
.
SUCCESS
{
log
.
Fatalf
(
"Unable to initialize NVML: %v"
,
nvml
.
ErrorString
(
ret
))
}
defer
func
()
{
ret
:=
nvml
.
Shutdown
()
if
ret
!=
nvml
.
SUCCESS
{
log
.
Fatalf
(
"Unable to shutdown NVML: %v"
,
nvml
.
ErrorString
(
ret
))
}
}()
count
,
ret
:=
nvml
.
DeviceGetCount
()
if
ret
!=
nvml
.
SUCCESS
{
log
.
Fatalf
(
"Unable to get device count: %v"
,
nvml
.
ErrorString
(
ret
))
}
res
:=
make
([]
DeviceInfo
,
0
,
len
(
count
))
for
i
:=
0
;
i
<
count
;
i
++
{
device
,
ret
:=
nvml
.
DeviceGetHandleByIndex
(
i
)
if
ret
!=
nvml
.
SUCCESS
{
log
.
Fatalf
(
"Unable to get device at index %d: %v"
,
i
,
nvml
.
ErrorString
(
ret
))
}
memory
,
err
:=
device
.
GetMemoryInfo
()
if
err
!=
nvml
.
SUCCESS
{
panic
(
err
)
}
// d1, _, err := device.GetDriverModel()
// if err != nvml.SUCCESS {
// //panic(err)
// }
name
,
err
:=
device
.
GetName
()
if
err
!=
nvml
.
SUCCESS
{
panic
(
err
)
}
//fmt.Printf(" %v\n", proc)
e
:=
DeviceInfo
{
Type
:
fmt
.
Sprintf
(
"GPU-%d"
,
i
),
Model
:
name
,
Param
:
"device.GetMemoryInfo()"
,
Power
:
uint64
(
device
.
GetMemoryInfo
()),
}
res
=
append
(
res
,
e
)
c
:=
uint64
(
0
)
if
v
,
ok
:=
comput
[
name
];
ok
{
c
=
v
}
e
=
DeviceInfo
{
Type
:
fmt
.
Sprintf
(
"GPU-%d"
,
i
),
Model
:
name
,
Param
:
"compute"
,
Power
:
c
,
}
res
=
append
(
res
,
e
)
}
return
res
,
nil
}
var
comput
map
[
string
]
uint64
//NVIDIA GeForce RTX 3080,
//NVIDIA GeForce RTX 3080
func
init
()
{
comput
:=
make
(
map
[
string
]
uint64
,
100
)
comput
[
"NVIDIA GeForce RTX 4090"
]
=
1
*
10000
comput
[
"NVIDIA GeForce RTX 4080SUPER"
]
=
6450
comput
[
"NVIDIA GeForce RTX 4080"
]
=
6290
comput
[
"NVIDIA GeForce RTX 4070 Ti SUPER"
]
=
5860
comput
[
"NVIDIA GeForce RTX 4070 Ti"
]
=
4840
comput
[
"NVIDIA GeForce RTX 4070 SUPER"
]
=
4680
comput
[
"NVIDIA GeForce RTX 4070"
]
=
4240
comput
[
"NVIDIA GeForce RTX 4060 Ti"
]
=
4210
comput
[
"NVIDIA GeForce RTX 4060"
]
=
2500
comput
[
"NVIDIA GeForce RTX 3090 Ti"
]
=
7960
comput
[
"NVIDIA GeForce RTX 3090"
]
=
7870
comput
[
"NVIDIA GeForce RTX 3080 Ti"
]
=
5500
comput
[
"NVIDIA GeForce RTX 3080"
]
=
5140
comput
[
"NVIDIA GeForce RTX 3070 Ti"
]
=
3480
comput
[
"NVIDIA GeForce RTX 3070"
]
=
3400
comput
[
"NVIDIA GeForce RTX 3060 Ti"
]
=
3090
comput
[
"NVIDIA GeForce RTX 3060"
]
=
3250
comput
[
"NVIDIA GeForce RTX 3050"
]
=
2240
comput
[
"NVIDIA GeForce RTX 2080 Ti"
]
=
3200
comput
[
"NVIDIA GeForce RTX 2080 SUPER"
]
=
2290
comput
[
"NVIDIA GeForce RTX 2080"
]
=
2250
comput
[
"NVIDIA GeForce RTX 2070 SUPER"
]
=
2100
comput
[
"NVIDIA GeForce RTX 2070"
]
=
1990
comput
[
"NVIDIA GeForce RTX 2060 SUPER"
]
=
1930
comput
[
"NVIDIA GeForce RTX 2060"
]
=
2370
comput
[
"NVIDIA GeForce GTX 1080 Ti"
]
=
2620
comput
[
"NVIDIA GeForce GTX 1080"
]
=
1890
comput
[
"NVIDIA GeForce GTX 1070 Ti"
]
=
1840
comput
[
"NVIDIA GeForce GTX 1070"
]
=
1640
}
//10000
main.go
View file @
7a2c46e8
...
@@ -6,6 +6,8 @@ func main() {
...
@@ -6,6 +6,8 @@ func main() {
// Initialize a new Fiber app
// Initialize a new Fiber app
app
:=
fiber
.
New
()
app
:=
fiber
.
New
()
//showMemory()
// Define a route for the GET method on the root path '/'
// Define a route for the GET method on the root path '/'
app
.
Get
(
"/hw/info"
,
func
(
c
fiber
.
Ctx
)
error
{
app
.
Get
(
"/hw/info"
,
func
(
c
fiber
.
Ctx
)
error
{
...
@@ -17,6 +19,23 @@ func main() {
...
@@ -17,6 +19,23 @@ func main() {
c
.
SendString
(
"getBlock err: "
+
err
.
Error
())
c
.
SendString
(
"getBlock err: "
+
err
.
Error
())
}
}
res
=
append
(
res
,
block
...
)
res
=
append
(
res
,
block
...
)
mem
,
err
:=
getMemory
()
if
err
!=
nil
{
c
.
SendString
(
"getMemory err: "
+
err
.
Error
())
}
res
=
append
(
res
,
mem
...
)
cpu
,
err
:=
getCPU
()
if
err
!=
nil
{
c
.
SendString
(
"getMemory err: "
+
err
.
Error
())
}
res
=
append
(
res
,
cpu
...
)
return
c
.
JSON
(
res
)
return
c
.
JSON
(
res
)
// Send a string response to the client
// Send a string response to the client
...
...
mem.go
0 → 100644
View file @
7a2c46e8
package
main
import
(
"fmt"
"github.com/jaypipes/ghw"
"github.com/pkg/errors"
)
// showMemory show memory information for the host system.
func
getMemory
()
([]
DeviceInfo
,
error
)
{
mem
,
err
:=
ghw
.
Memory
()
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"error getting memory info"
)
}
fmt
.
Println
(
mem
.
Area
.
TotalPhysicalBytes
,
mem
.
Area
.
TotalUsableBytes
)
e
:=
DeviceInfo
{
Type
:
fmt
.
Sprintf
(
"mem"
),
//Model: disk.Model,
Param
:
"mem.Area.TotalPhysicalBytes"
,
Power
:
uint64
(
mem
.
Area
.
TotalPhysicalBytes
),
}
res
:=
make
([]
DeviceInfo
,
0
,
1
)
res
=
append
(
res
,
e
)
return
res
,
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment