Add Support for Private source engines
Private source engines must be located on Github. All test branches must come from the same repo as stated in the config. Repo must have an openbench.yml file that produces artifacts for the workers. Basic name scheme: windows-avx2-pext, linux-avx512-pext, ... Desired artifacts can be set in the engine config under ['build']['artifacts'] Server must have a private key, housed in credentials.enginename. Client must have a private key, housed in credentials.enginename. enginename is lowercase and with spaces removed. Private engines cannot build their NNUE files directly into them. They must therefore support being run from the CMD line, with additional options. Namely: ./engine "setoption name EvalFile value path/to/file" "bench" "quit".
This commit is contained in:
1 parent
7324bb1dc1
commit
c02e0782b6
5 files changed
+296
-112
No files matched your search
+19
-19
@@ -25,7 +25,7 @@ REQUIRE_LOGIN_TO_VIEW = False
|
||||
OPENBENCH_CONFIG = {
|
||||
|
||||
# Server Client version control
|
||||
'client_version' : '5',
|
||||
'client_version' : '6',
|
||||
|
||||
# Generic Error Messages useful to those setting up their own instance
|
||||
'error' : {
|
||||
@@ -114,7 +114,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : 'src',
|
||||
'compilers' : ['clang', 'gcc'],
|
||||
'cpuflags' : ['AVX2', 'AVX', 'FMA', 'POPCNT', 'SSE2', 'SSE'],
|
||||
'cpuflags' : ['__AVX2__', '__FMA__', '__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
@@ -140,7 +140,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : 'src',
|
||||
'compilers' : ['g++'],
|
||||
'cpuflags' : ['POPCNT'],
|
||||
'cpuflags' : ['__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
@@ -166,7 +166,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : 'src',
|
||||
'compilers' : ['gcc'],
|
||||
'cpuflags' : ['POPCNT'],
|
||||
'cpuflags' : ['__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
@@ -192,7 +192,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : 'src',
|
||||
'compilers' : ['clang', 'gcc'],
|
||||
'cpuflags' : ['POPCNT'],
|
||||
'cpuflags' : ['__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
@@ -218,7 +218,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : 'src',
|
||||
'compilers' : ['g++'],
|
||||
'cpuflags' : ['POPCNT'],
|
||||
'cpuflags' : ['__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
@@ -244,7 +244,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : '',
|
||||
'compilers' : ['cargo>=1.41.0'],
|
||||
'cpuflags' : ['POPCNT'],
|
||||
'cpuflags' : ['__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
@@ -270,7 +270,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : 'src',
|
||||
'compilers' : ['g++'],
|
||||
'cpuflags' : ['POPCNT'],
|
||||
'cpuflags' : ['__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
@@ -296,7 +296,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : '',
|
||||
'compilers' : ['clang++', 'g++'],
|
||||
'cpuflags' : ['POPCNT'],
|
||||
'cpuflags' : ['__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
@@ -322,7 +322,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : 'src',
|
||||
'compilers' : ['g++'],
|
||||
'cpuflags' : ['POPCNT'],
|
||||
'cpuflags' : ['__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
@@ -348,7 +348,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : 'src',
|
||||
'compilers' : ['gcc', 'clang'],
|
||||
'cpuflags' : ['POPCNT'],
|
||||
'cpuflags' : ['__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
@@ -374,7 +374,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : 'build',
|
||||
'compilers' : ['g++>=9.0.0'],
|
||||
'cpuflags' : ['AVX2', 'AVX', 'FMA', 'POPCNT', 'SSE2', 'SSE'],
|
||||
'cpuflags' : ['__AVX2__', '__FMA__', '__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
@@ -400,7 +400,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : 'src_files',
|
||||
'compilers' : ['g++'],
|
||||
'cpuflags' : ['AVX2', 'AVX', 'FMA', 'POPCNT', 'SSE2', 'SSE'],
|
||||
'cpuflags' : ['__AVX2__', '__FMA__', '__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
@@ -426,7 +426,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : '',
|
||||
'compilers' : ['g++'],
|
||||
'cpuflags' : ['POPCNT'],
|
||||
'cpuflags' : ['__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
@@ -452,7 +452,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : 'src',
|
||||
'compilers' : ['g++'],
|
||||
'cpuflags' : ['POPCNT'],
|
||||
'cpuflags' : ['__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
@@ -478,7 +478,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : 'src',
|
||||
'compilers' : ['gcc'],
|
||||
'cpuflags' : ['AVX2', 'AVX', 'FMA', 'POPCNT', 'SSE2', 'SSE'],
|
||||
'cpuflags' : ['__AVX2__', '__FMA__', '__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
@@ -504,7 +504,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : '',
|
||||
'compilers' : ['go'],
|
||||
'cpuflags' : ['AVX', 'POPCNT'],
|
||||
'cpuflags' : ['__AVX__', '__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
@@ -530,7 +530,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : '',
|
||||
'compilers': ['cargo>=1.57.0'],
|
||||
'cpuflags' : ['AVX2', 'AVX', 'FMA', 'POPCNT', 'SSE2', 'SSE'],
|
||||
'cpuflags' : ['__AVX2__', '__FMA__', '__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
@@ -556,7 +556,7 @@ OPENBENCH_CONFIG = {
|
||||
'build' : {
|
||||
'path' : '',
|
||||
'compilers' : ['g++'],
|
||||
'cpuflags' : ['POPCNT'],
|
||||
'cpuflags' : ['__POPCNT__'],
|
||||
},
|
||||
|
||||
'testmodes' : [
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
import re, django
|
||||
import OpenBench.utils, OpenBench.stats, OpenBench.models
|
||||
import OpenBench.config, OpenBench.utils, OpenBench.stats, OpenBench.models
|
||||
|
||||
|
||||
def oneDigitPrecision(value):
|
||||
@@ -51,14 +51,20 @@ def gitDiffLink(test):
|
||||
base = test['base']['source']
|
||||
devsha = test['dev']['sha']
|
||||
basesha = test['base']['sha']
|
||||
engine = test['engine']
|
||||
|
||||
else:
|
||||
dev = test.dev.source
|
||||
base = test.base.source
|
||||
devsha = test.dev.sha
|
||||
basesha = test.base.sha
|
||||
engine = test.engine
|
||||
|
||||
if OpenBench.config.OPENBENCH_CONFIG['engines'][engine]['private']:
|
||||
repo = OpenBench.config.OPENBENCH_CONFIG['engines'][engine]['source']
|
||||
else:
|
||||
repo = OpenBench.utils.pathjoin(*dev.split('/')[:-2])
|
||||
|
||||
repo = OpenBench.utils.pathjoin(*dev.split('/')[:-2])
|
||||
return OpenBench.utils.pathjoin(repo, 'compare',
|
||||
'{0}...{1}'.format(basesha[:8], devsha[:8]))
|
||||
|
||||
|
||||
+119
-34
@@ -148,55 +148,136 @@ def getEngine(source, name, sha, bench):
|
||||
if engine.first() != None: return engine.first()
|
||||
return Engine.objects.create(name=name, source=source, sha=sha, bench=bench)
|
||||
|
||||
def getBranch(request, errors, name):
|
||||
|
||||
branch = request.POST['{0}branch'.format(name)]
|
||||
def read_git_credentials(request):
|
||||
|
||||
engine = request.POST['enginename'].replace(' ', '').lower()
|
||||
fname = 'credentials.%s' % (engine)
|
||||
|
||||
if os.path.exists(fname):
|
||||
with open(fname) as fin:
|
||||
return { 'Authorization' : 'token %s' % fin.readlines()[0].rstrip() }
|
||||
|
||||
def requests_illegal_fork(request):
|
||||
|
||||
# Strip trailing '/'s for sanity
|
||||
engine = OPENBENCH_CONFIG['engines'][request.POST['enginename']]
|
||||
eng_src = engine['source'].rstrip('/')
|
||||
tar_src = request.POST['source'].rstrip('/')
|
||||
|
||||
# Illegal if sources do not match for Private engines
|
||||
return engine['private'] and eng_src != tar_src
|
||||
|
||||
def determine_bench(request, field, message):
|
||||
|
||||
# Use the provided bench if possible
|
||||
try: return int(request.POST['{0}bench'.format(field)])
|
||||
except: pass
|
||||
|
||||
# Fallback to try to parse the Bench from the commit
|
||||
try:
|
||||
benches = re.findall('(?:BENCH|NODES)[ :=]+([0-9,]+)', message, re.IGNORECASE)
|
||||
return int(benches[-1].replace(',', ''))
|
||||
except: return None
|
||||
|
||||
def collect_github_info(request, errors, field):
|
||||
|
||||
# Get branch name, whether it is a commit SHA, and the API path for it
|
||||
branch = request.POST['{0}branch'.format(field)]
|
||||
bysha = bool(re.search('[0-9a-fA-F]{40}', branch))
|
||||
url = 'commits' if bysha else 'branches'
|
||||
|
||||
repo = request.POST['source']
|
||||
target = repo.replace('github.com', 'api.github.com/repos')
|
||||
target = pathjoin(target, url, branch).rstrip('/')
|
||||
# All API requests will share this common path. Some engines are private.
|
||||
base = request.POST['source'].replace('github.com', 'api.github.com/repos')
|
||||
private = OPENBENCH_CONFIG['engines'][request.POST['enginename']]['private']
|
||||
headers = {}
|
||||
|
||||
# Avoid leaking our credentials to other sites
|
||||
if not target.startswith('https://api.github.com/'):
|
||||
## Step 1: Verify the target of the API requests
|
||||
## [A] We will not attempt to reach any sit other than api.github.com
|
||||
## [B] Private engines may only use their main repo for sources of tests
|
||||
## [C] Determine which, if any, credentials we want to pass along
|
||||
|
||||
# Private engines must have a token stored in credentials.enginename
|
||||
if private and not (headers := read_git_credentials(request)):
|
||||
errors.append('Server does not have access tokens for this engine')
|
||||
return (None, None, None, None)
|
||||
|
||||
# Do not allow private engines to use forked repos ( We don't have a token! )
|
||||
if requests_illegal_fork(request):
|
||||
errors.append('Forked Repositories are not allowed for Private engines')
|
||||
return (None, None, None, None)
|
||||
|
||||
# Avoid leaking our credentials to other websites
|
||||
if not base.startswith('https://api.github.com/'):
|
||||
errors.append('OpenBench may only reach Github\'s API')
|
||||
return (None, None, None, None)
|
||||
|
||||
# Check for a (User, Token) credentials file
|
||||
if os.path.exists('credentials'):
|
||||
with open('credentials') as fin:
|
||||
user, token = fin.readlines()[0].rstrip().split()
|
||||
auth = requests.auth.HTTPBasicAuth(user, token)
|
||||
else: auth = None
|
||||
## Step 2: Connect to the Github API for the given Branch or Commit SHA.
|
||||
## [A] We will attempt to parse the most recent commit message for a
|
||||
## bench, unless one was supplied.
|
||||
## [B] We will translate any branch name into a commit SHA for later use,
|
||||
## so we may compare branches and generate diff URLs
|
||||
## [C] If the engine is public, we will construct the URL to download the
|
||||
## source code from Github into a .zip file.
|
||||
## [D] If the engine is private, we will carry onto Step 3.
|
||||
|
||||
try: # Fetch data from the Github API
|
||||
data = requests.get(target, auth=auth).json()
|
||||
path = 'commits' if bysha else 'branches'
|
||||
url = pathjoin(base, path, branch).rstrip('/')
|
||||
data = requests.get(url, headers=headers).json()
|
||||
data = data if bysha else data['commit']
|
||||
|
||||
except: # Unable to connect for whatever reason
|
||||
lookup = 'Commit Sha' if bysha else 'Branch'
|
||||
errors.append('{0} {1} could not be found'.format(lookup, branch))
|
||||
path = 'Commit Sha' if bysha else 'Branch'
|
||||
errors.append('{0} {1} could not be found'.format(path, branch))
|
||||
return (None, None, None, None)
|
||||
|
||||
treeurl = data['commit']['tree']['sha'] + '.zip'
|
||||
source = pathjoin(repo, 'archive', treeurl).rstrip('/')
|
||||
|
||||
try: # Use the provided Bench if there is one
|
||||
bench = int(request.POST['{0}bench'.format(name)])
|
||||
return (source, branch, data['sha'], bench)
|
||||
except: pass
|
||||
|
||||
try: # Fallback to try to parse the Bench from the commit
|
||||
message = data['commit']['message']
|
||||
benches = re.findall('(?:BENCH|NODES)[ :=]+([0-9,]+)', message, re.IGNORECASE)
|
||||
bench = int(benches[-1].replace(',', ''))
|
||||
return (source, branch, data['sha'], bench)
|
||||
|
||||
except: # Neither method found a viable Bench
|
||||
errors.append('Unable to parse a Bench for {0}'.format(branch))
|
||||
# Extract the bench from the web form, or from the commit message
|
||||
if not (bench := determine_bench(request, field, data['commit']['message'])):
|
||||
errors.append('Unable to parse a Bench for %s' % (branch))
|
||||
return (None, None, None, None)
|
||||
|
||||
# Public Engines: Construct the .zip download and return everything
|
||||
if not OPENBENCH_CONFIG['engines'][request.POST['enginename']]['private']:
|
||||
treeurl = data['commit']['tree']['sha'] + '.zip'
|
||||
source = pathjoin(request.POST['source'], 'archive', treeurl).rstrip('/')
|
||||
return (source, branch, data['sha'], bench)
|
||||
|
||||
## Step 3: Construct the URL for the API request to list all Artifacts
|
||||
## [A] OpenBench artifacts are always run via a file named openbench.yml
|
||||
## [B] These should contain combinations for windows/linux, avx2/avx512, popcnt/pext
|
||||
## [C] If those artifacts do not exist, we cannot create the test.
|
||||
|
||||
try: # Fetch the run id for the openbench workflow for this comment
|
||||
url = pathjoin(base, 'actions', 'workflows', 'openbench.yml', 'runs').rstrip('/')
|
||||
url += '?head_sha=%s' % (data['sha'])
|
||||
run_id = requests.get(url=url, headers=headers).json()['workflow_runs'][0]['id']
|
||||
|
||||
except: # Unable to determine this for whatever reason
|
||||
errors.append('Failed to idenftify the run_id associated with the OpenBench workflow')
|
||||
return (None, None, None, None)
|
||||
|
||||
try: # Fetch the artifact list for the run_id we determined above
|
||||
url = pathjoin(base, 'actions', 'runs', str(run_id), 'artifacts').rstrip('/')
|
||||
artifacts = requests.get(url=url, headers=headers).json()['artifacts']
|
||||
|
||||
except: # Unable to fetch the list of artifacts for whatever reason
|
||||
errors.append('Failed to get the Artifact List for run_id = %d' % (run_id))
|
||||
return (None, None, None, None)
|
||||
|
||||
# Verify that all of the artifacts exist and are not expired
|
||||
available = [ f['name'] for f in artifacts if f['expired'] == False ]
|
||||
required = OPENBENCH_CONFIG['engines'][request.POST['enginename']]['build']['artifacts']
|
||||
|
||||
# Flag any and all missing artifacts
|
||||
for name in required:
|
||||
if '%s-%s' % (data['sha'], name) not in available:
|
||||
errors.append('Missing Artifact (%s)' % (name))
|
||||
|
||||
# Return the API endpoint for artifacts, along with the usual rest
|
||||
return (url, branch, data['sha'], bench)
|
||||
|
||||
|
||||
def verifyNewTest(request):
|
||||
|
||||
errors = []
|
||||
@@ -259,8 +340,8 @@ def createNewTest(request):
|
||||
errors = verifyNewTest(request)
|
||||
if errors != []: return None, errors
|
||||
|
||||
devinfo = getBranch(request, errors, 'dev')
|
||||
baseinfo = getBranch(request, errors, 'base')
|
||||
devinfo = collect_github_info(request, errors, 'dev')
|
||||
baseinfo = collect_github_info(request, errors, 'base')
|
||||
if errors != []: return None, errors
|
||||
|
||||
test = Test()
|
||||
@@ -442,6 +523,10 @@ def workload_to_dictionary(test, result, machine):
|
||||
|
||||
'result' : { 'id' : result.id },
|
||||
|
||||
'engine' : {
|
||||
'private' : OPENBENCH_CONFIG['engines'][test.engine]['private']
|
||||
},
|
||||
|
||||
'test' : {
|
||||
|
||||
'id' : test.id,
|
||||
|
||||
@@ -639,6 +639,7 @@ def clientGetBuildInfo(request):
|
||||
data = {}
|
||||
for engine, config in OpenBench.config.OPENBENCH_CONFIG['engines'].items():
|
||||
data[engine] = config['build']
|
||||
data[engine]['private'] = config['private']
|
||||
return HttpResponse(json.dumps(data))
|
||||
|
||||
@csrf_exempt
|
||||
|
||||
Reference in new issue
Block a user