-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: curio ffiselect: Isolate gpu calls in a subprocess (#11994)
* started * so far so good * builds and looks good * changing level of abstration. some work remains * it builds * betterment * import order * 2 * stupid linter - you can cast a nil * build commit and date * nicer * tmp and nide makefile * comments handled * oops * added debug and reg * ffiselect: change err encode to strings, fix some bugs * ffiselect: Wrap rust logs into go-log * ffiselect: Make the linter happy * verification tests * ffiselect: Fix startup --------- Co-authored-by: Łukasz Magiera <magik6k@gmail.com>
- Loading branch information
Showing
17 changed files
with
695 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,71 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/gob" | ||
"fmt" | ||
"os" | ||
"reflect" | ||
|
||
"github.com/ipfs/go-cid" | ||
"github.com/samber/lo" | ||
"github.com/urfave/cli/v2" | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/filecoin-project/lotus/lib/ffiselect" | ||
ffidirect "github.com/filecoin-project/lotus/lib/ffiselect/ffidirect" | ||
"github.com/filecoin-project/lotus/lib/must" | ||
) | ||
|
||
var ffiCmd = &cli.Command{ | ||
Name: "ffi", | ||
Hidden: true, | ||
Flags: []cli.Flag{ | ||
layersFlag, | ||
}, | ||
Action: func(cctx *cli.Context) (err error) { | ||
output := os.NewFile(uintptr(3), "out") | ||
|
||
defer func() { | ||
if r := recover(); r != nil { | ||
err = fmt.Errorf("panic: %v", r) | ||
} | ||
if err != nil { | ||
err = gob.NewEncoder(output).Encode(ffiselect.ValErr{Val: nil, Err: err.Error()}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
}() | ||
var callInfo ffiselect.FFICall | ||
if err := gob.NewDecoder(os.Stdin).Decode(&callInfo); err != nil { | ||
return xerrors.Errorf("ffi subprocess can not decode: %w", err) | ||
} | ||
|
||
args := lo.Map(callInfo.Args, func(arg any, i int) reflect.Value { | ||
return reflect.ValueOf(arg) | ||
}) | ||
|
||
resAry := reflect.ValueOf(ffidirect.FFI{}).MethodByName(callInfo.Fn).Call(args) | ||
res := lo.Map(resAry, func(res reflect.Value, i int) any { | ||
return res.Interface() | ||
}) | ||
|
||
err = gob.NewEncoder(output).Encode(ffiselect.ValErr{Val: res, Err: ""}) | ||
if err != nil { | ||
return xerrors.Errorf("ffi subprocess can not encode: %w", err) | ||
} | ||
|
||
return output.Close() | ||
}, | ||
} | ||
|
||
func ffiSelfTest() { | ||
val1, val2 := 12345678, must.One(cid.Parse("bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi")) | ||
ret1, ret2, err := ffiselect.FFISelect{}.SelfTest(val1, val2) | ||
if err != nil { | ||
panic("ffi self test failed:" + err.Error()) | ||
} | ||
if ret1 != val1 || !val2.Equals(ret2) { | ||
panic(fmt.Sprint("ffi self test failed: values do not match: ", val1, val2, ret1, ret2)) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,9 @@ | ||
package build | ||
|
||
// IsOpencl is set to the value of FFI_USE_OPENCL | ||
var IsOpencl string | ||
|
||
// Format: 8 HEX then underscore then ISO8701 date | ||
// Ex: 4c5e98f28_2024-05-17T18:42:27-04:00 | ||
// NOTE: git date for repeatabile builds. | ||
var Commit string |
This file contains 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
This file contains 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.