Skip to content
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

Backend-defined package settings #2104

Merged
merged 42 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
14f23a8
settings wip shizzle
joeyballentine Jul 21, 2023
467bdd2
Merge branch 'main' into settings-stuff
joeyballentine Jul 31, 2023
edf50fd
gpu dropdown
joeyballentine Jul 31, 2023
d8171b9
Option to enable GUI hardware acceleration (#2055)
stonerl Aug 5, 2023
3de1b90
Fixed release CI (#2059)
RunDevelopment Aug 5, 2023
c5dfb91
Bump to 0.19.1 (#2061)
RunDevelopment Aug 6, 2023
fedc6d3
Added sorting back to Image File Iterator (#2067)
theflyingzamboni Aug 7, 2023
cc33b98
fix duplicating nodes and exporting firing twice (#2068)
stonerl Aug 8, 2023
79364ac
changes to theme selection (#2060)
stonerl Aug 8, 2023
c4c1370
Mac Stuff (#2069)
stonerl Aug 8, 2023
42b1a92
Features (#2053)
RunDevelopment Aug 10, 2023
37a9f7a
Merge branch 'main' into settings-stuff
joeyballentine Aug 10, 2023
1088aef
UI changes for backend settings
joeyballentine Aug 10, 2023
b34aba4
some wip stuff
joeyballentine Aug 10, 2023
23e8b8f
Merge branch 'main' into settings-stuff
joeyballentine Aug 12, 2023
39814a2
Merge branch 'main' into settings-stuff
joeyballentine Aug 13, 2023
c12d91e
Fix setting state
joeyballentine Aug 13, 2023
918b452
fix some typing and stuff
joeyballentine Aug 13, 2023
fd92811
use immer
joeyballentine Aug 13, 2023
2f128d6
some changes
joeyballentine Aug 14, 2023
bdfef91
Merge branch 'main' into settings-stuff
joeyballentine Aug 15, 2023
5ff35f1
wip
joeyballentine Aug 16, 2023
aec8004
Merge remote-tracking branch 'chaiNNer-org/main' into settings-stuff
joeyballentine Aug 16, 2023
1adf5b2
refactor execution settings
joeyballentine Aug 16, 2023
3aa64a1
Update backend/src/api.py
joeyballentine Aug 17, 2023
c62727c
wip
joeyballentine Aug 18, 2023
ffae6e7
Merge branch 'main' into settings-stuff
joeyballentine Aug 18, 2023
61d1a44
refactor stuff
joeyballentine Aug 18, 2023
efdcb79
fix cache stuff
joeyballentine Aug 19, 2023
a4ea53a
ncnn settings
joeyballentine Aug 19, 2023
0bdc9e7
cleanup
joeyballentine Aug 19, 2023
9df57da
lint
joeyballentine Aug 19, 2023
786059f
remove unnecessary typevar
joeyballentine Aug 21, 2023
8a04fb7
remove TODO
joeyballentine Aug 21, 2023
ab99030
Some PR suggestions
joeyballentine Aug 21, 2023
9c706c7
...
joeyballentine Aug 21, 2023
dd4d471
Merge remote-tracking branch 'chaiNNer-org/main' into settings-stuff
joeyballentine Aug 21, 2023
c43c590
linting
joeyballentine Aug 21, 2023
055670f
Require icon and color
RunDevelopment Aug 22, 2023
e8ba63c
More settings (#2137)
RunDevelopment Aug 25, 2023
cf8d559
Merge branch 'main' into settings-stuff
RunDevelopment Aug 25, 2023
19b1995
Merge branch 'main' into settings-stuff
joeyballentine Aug 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ncnn settings
  • Loading branch information
joeyballentine committed Aug 19, 2023
commit a4ea53a96e3f5c6a9237fd6c0a587f7e837202e1
4 changes: 1 addition & 3 deletions backend/src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
NewType,
Optional,
Tuple,
Type,
TypedDict,
TypeVar,
cast,
)

from sanic.log import logger
Expand All @@ -33,7 +31,7 @@
from nodes.base_input import BaseInput
from nodes.base_output import BaseOutput
from nodes.group import Group, GroupId, NestedGroup, NestedIdGroup
from nodes.utils.exec_options import PackageExecutionOptions, get_execution_options
from nodes.utils.exec_options import get_execution_options

KB = 1024**1
MB = 1024**2
Expand Down
10 changes: 4 additions & 6 deletions backend/src/nodes/impl/ncnn/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
from .model import NcnnModelWrapper


def create_ncnn_net(
model: NcnnModelWrapper, exec_options: ExecutionOptions
) -> ncnn.Net:
def create_ncnn_net(model: NcnnModelWrapper, gpu_index: int) -> ncnn.Net:
net = ncnn.Net()

if model.fp == "fp16":
Expand All @@ -33,7 +31,7 @@ def create_ncnn_net(
if use_gpu:
# Use vulkan compute
net.opt.use_vulkan_compute = True
net.set_vulkan_device(exec_options.ncnn_gpu_index)
net.set_vulkan_device(gpu_index)

# Load model param and bin
if use_gpu:
Expand All @@ -56,9 +54,9 @@ def create_ncnn_net(
__session_cache: WeakKeyDictionary[NcnnModelWrapper, ncnn.Net] = WeakKeyDictionary()


def get_ncnn_net(model: NcnnModelWrapper, exec_options: ExecutionOptions) -> ncnn.Net:
def get_ncnn_net(model: NcnnModelWrapper, gpu_index: int) -> ncnn.Net:
cached = __session_cache.get(model)
if cached is None:
cached = create_ncnn_net(model, exec_options)
cached = create_ncnn_net(model, gpu_index)
__session_cache[model] = cached
return cached
23 changes: 1 addition & 22 deletions backend/src/packages/chaiNNer_ncnn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sanic.log import logger

from api import MB, Dependency, DropdownSetting, add_package
from api import MB, Dependency, add_package
from system import is_arm_mac, is_mac

general = "NCNN uses .bin/.param models to upscale images."
Expand Down Expand Up @@ -39,27 +39,6 @@
color="#ED64A6",
)

if not is_arm_mac:
gpu_list = []
try:
from ncnn_vulkan import ncnn

for i in range(ncnn.get_gpu_count()):
gpu_list.append(ncnn.get_gpu_info(i).device_name())
except:
gpu_list.append("cpu")

package.add_setting(
DropdownSetting(
label="NCNN GPU",
key="gpu",
description="Which GPU to use for NCNN. This is only relevant if you have multiple GPUs.",
options=[{"label": x, "value": str(i)} for i, x in enumerate(gpu_list)],
default="0",
disabled=len(gpu_list) <= 1,
)
)

ncnn_category = package.add_category(
name="NCNN",
description="Nodes for using the NCNN Neural Network Framework with images.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
from nodes.impl.upscale.tiler import MaxTileSize
from nodes.properties.inputs import ImageInput, NcnnModelInput, TileSizeDropdown
from nodes.properties.outputs import ImageOutput
from nodes.utils.exec_options import get_execution_options
from nodes.utils.utils import get_h_w_c
from system import is_mac

from ...settings import get_settings
from .. import processing_group


Expand Down Expand Up @@ -66,12 +66,12 @@ def upscale_impl(
output_name: str,
tile_size: TileSize,
):
exec_options = get_execution_options()
net = get_ncnn_net(model, exec_options)
settings = get_settings()
net = get_ncnn_net(model, settings.gpu_index)
# Try/except block to catch errors
try:
if use_gpu:
vkdev = ncnn.get_gpu_device(exec_options.ncnn_gpu_index)
vkdev = ncnn.get_gpu_device(settings.gpu_index)

def estimate_gpu():
if is_mac:
Expand Down
46 changes: 46 additions & 0 deletions backend/src/packages/chaiNNer_ncnn/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from dataclasses import dataclass

try:
from ncnn_vulkan import ncnn

use_gpu = True
except ImportError:
from ncnn import ncnn

use_gpu = False

from api import DropdownSetting
from system import is_arm_mac

from . import package

if not is_arm_mac and use_gpu:
try:
gpu_list = []
for i in range(ncnn.get_gpu_count()):
gpu_list.append(ncnn.get_gpu_info(i).device_name())

package.add_setting(
DropdownSetting(
label="GPU",
key="gpu_index",
description="Which GPU to use for NCNN. This is only relevant if you have multiple GPUs.",
options=[{"label": x, "value": str(i)} for i, x in enumerate(gpu_list)],
default="0",
disabled=len(gpu_list) <= 1,
)
)
except:
pass


@dataclass
class NcnnSettings:
gpu_index: int


def get_settings() -> NcnnSettings:
raw = package.get_execution_settings()
return NcnnSettings(
gpu_index=int(raw.get("gpu_index", 0)),
)