@@ -74,6 +74,14 @@ func GetDeviceFromPointer(ptr unsafe.Pointer) int {
74
74
return int (cCudaPointerAttributes .device )
75
75
}
76
76
77
+ func GetDeviceAttribute (attr DeviceAttribute , device int ) int {
78
+ var res int
79
+ cRes := (* C .int )(unsafe .Pointer (& res ))
80
+ cDevice := (C .int )(device )
81
+ C .cudaDeviceGetAttribute (cRes , attr , cDevice )
82
+ return res
83
+ }
84
+
77
85
// RunOnDevice forces the provided function to run all GPU related calls within it
78
86
// on the same host thread and therefore the same GPU device.
79
87
//
@@ -84,46 +92,46 @@ func GetDeviceFromPointer(ptr unsafe.Pointer) int {
84
92
//
85
93
// As an example:
86
94
//
87
- // cr.RunOnDevice(i, func(args ...any) {
88
- // defer wg.Done()
89
- // cfg := GetDefaultMSMConfig()
90
- // stream, _ := cr.CreateStream()
91
- // for _, power := range []int{2, 3, 4, 5, 6, 7, 8, 10, 18} {
92
- // size := 1 << power
93
- //
94
- // // This will always print "Inner goroutine device: 0"
95
- // // go func () {
96
- // // device, _ := cr.GetDevice()
97
- // // fmt.Println("Inner goroutine device: ", device)
98
- // // }()
99
- // // To force the above goroutine to same device as the wrapping function:
100
- // // RunOnDevice(i, func(arg ...any) {
101
- // // device, _ := cr.GetDevice()
102
- // // fmt.Println("Inner goroutine device: ", device)
103
- // // })
104
- //
105
- // scalars := GenerateScalars(size)
106
- // points := GenerateAffinePoints(size)
107
- //
108
- // var p Projective
109
- // var out core.DeviceSlice
110
- // _, e := out.MallocAsync(p.Size(), p.Size(), stream)
111
- // assert.Equal(t, e, cr.CudaSuccess, "Allocating bytes on device for Projective results failed")
112
- // cfg.Ctx.Stream = &stream
113
- // cfg.IsAsync = true
114
- //
115
- // e = Msm(scalars, points, &cfg, out)
116
- // assert.Equal(t, e, cr.CudaSuccess, "Msm failed")
117
- //
118
- // outHost := make(core.HostSlice[Projective], 1)
119
- //
120
- // cr.SynchronizeStream(&stream)
121
- // outHost.CopyFromDevice(&out)
122
- // out.Free()
123
- // // Check with gnark-crypto
124
- // assert.True(t, testAgainstGnarkCryptoMsm(scalars, points, outHost[0]))
125
- // }
126
- // }, i)
95
+ // cr.RunOnDevice(i, func(args ...any) {
96
+ // defer wg.Done()
97
+ // cfg := GetDefaultMSMConfig()
98
+ // stream, _ := cr.CreateStream()
99
+ // for _, power := range []int{2, 3, 4, 5, 6, 7, 8, 10, 18} {
100
+ // size := 1 << power
101
+
102
+ // // This will always print "Inner goroutine device: 0"
103
+ // // go func () {
104
+ // // device, _ := cr.GetDevice()
105
+ // // fmt.Println("Inner goroutine device: ", device)
106
+ // // }()
107
+ // // To force the above goroutine to same device as the wrapping function:
108
+ // // RunOnDevice(i, func(arg ...any) {
109
+ // // device, _ := cr.GetDevice()
110
+ // // fmt.Println("Inner goroutine device: ", device)
111
+ // // })
112
+
113
+ // scalars := GenerateScalars(size)
114
+ // points := GenerateAffinePoints(size)
115
+
116
+ // var p Projective
117
+ // var out core.DeviceSlice
118
+ // _, e := out.MallocAsync(p.Size(), p.Size(), stream)
119
+ // assert.Equal(t, e, cr.CudaSuccess, "Allocating bytes on device for Projective results failed")
120
+ // cfg.Ctx.Stream = &stream
121
+ // cfg.IsAsync = true
122
+
123
+ // e = Msm(scalars, points, &cfg, out)
124
+ // assert.Equal(t, e, cr.CudaSuccess, "Msm failed")
125
+
126
+ // outHost := make(core.HostSlice[Projective], 1)
127
+
128
+ // cr.SynchronizeStream(&stream)
129
+ // outHost.CopyFromDevice(&out)
130
+ // out.Free()
131
+ // // Check with gnark-crypto
132
+ // assert.True(t, testAgainstGnarkCryptoMsm(scalars, points, outHost[0]))
133
+ // }
134
+ // }, i)
127
135
func RunOnDevice (deviceId int , funcToRun func (args ... any ), args ... any ) {
128
136
go func (id int ) {
129
137
defer runtime .UnlockOSThread ()
0 commit comments