| 1 |
import os,shutil |
| 2 |
import sys |
| 3 |
|
| 4 |
import struct |
| 5 |
import os |
| 6 |
from sys import platform |
| 7 |
|
| 8 |
class GenSource2Bin(object): |
| 9 |
def __init__(self, component='codec'): |
| 10 |
self.fromdir = './Binary' |
| 11 |
|
| 12 |
def iga_compile(self): |
| 13 |
for filename in os.listdir('./Source'): |
| 14 |
fp = os.path.join('./Source', filename) |
| 15 |
fileext = os.path.splitext(filename)[1] |
| 16 |
if os.path.isfile(fp) and 'cpp' in fileext: |
| 17 |
command = 'cmc /c /Qxcm -Qxcm_jit_target=gen11lp ' |
| 18 |
command += fp |
| 19 |
command += ' -mCM_emit_common_isa -mCM_no_input_reorder -mCM_jit_option="-nocompaction" ' |
| 20 |
os.system(command) |
| 21 |
|
| 22 |
print("Compiled %s" % fp); |
| 23 |
|
| 24 |
def deleteFile(self): |
| 25 |
for filename in os.listdir('./'): |
| 26 |
fp = os.path.join('./', filename) |
| 27 |
fileext = os.path.splitext(filename)[1] |
| 28 |
if os.path.isfile(fp) and 'asm' in fileext: |
| 29 |
os.remove(fp) |
| 30 |
|
| 31 |
if os.path.isfile(fp) and 'dat' in fileext: |
| 32 |
os.remove(fp) |
| 33 |
|
| 34 |
if os.path.isfile(fp) and 'visaasm' in fileext: |
| 35 |
os.remove(fp) |
| 36 |
|
| 37 |
if os.path.isfile(fp) and 'isa' in fileext: |
| 38 |
os.remove(fp) |
| 39 |
|
| 40 |
def join(self): |
| 41 |
isExists=os.path.exists("Binary") |
| 42 |
if not isExists: |
| 43 |
os.mkdir("Binary") |
| 44 |
|
| 45 |
shutil.copy('downscale_kernel_genx_0.dat', 'Binary/DS4x_Frame.krn') |
| 46 |
shutil.copy('downscale_kernel_genx_1.dat', 'Binary/DS2x_Frame.krn') |
| 47 |
shutil.copy('hme_kernel_genx_0.dat', 'Binary/HME_P.krn') |
| 48 |
shutil.copy('hme_kernel_genx_1.dat', 'Binary/HME_B.krn') |
| 49 |
shutil.copy('hme_kernel_genx_2.dat', 'Binary/HME_VDENC.krn') |
| 50 |
shutil.copy('downscale_convert_kernel_genx_0.dat', 'Binary/DS_Convert.krn') |
| 51 |
|
| 52 |
output = open('commonkernel.krn', 'wb') |
| 53 |
|
| 54 |
bytes = struct.pack('i', 6) |
| 55 |
output.write(bytes) |
| 56 |
|
| 57 |
count = 64 |
| 58 |
bytes = struct.pack('i', count) |
| 59 |
output.write(bytes) |
| 60 |
|
| 61 |
filepath = os.path.join('./Binary', 'DS4x_Frame.krn') |
| 62 |
count += os.path.getsize(filepath) |
| 63 |
count1 = ((count + 63) >> 6) << 6 |
| 64 |
byteremain1 = count1 - count |
| 65 |
|
| 66 |
bytes = struct.pack('i', count1) |
| 67 |
output.write(bytes) |
| 68 |
|
| 69 |
filepath = os.path.join('./Binary', 'DS2x_Frame.krn') |
| 70 |
count1 += os.path.getsize(filepath) |
| 71 |
count2 = ((count1 + 63) >> 6) << 6 |
| 72 |
byteremain2 = count2 - count1 |
| 73 |
|
| 74 |
bytes = struct.pack('i', count2) |
| 75 |
output.write(bytes) |
| 76 |
|
| 77 |
filepath = os.path.join('./Binary', 'HME_P.krn') |
| 78 |
count2 += os.path.getsize(filepath) |
| 79 |
count3 = ((count2 + 63) >> 6) << 6 |
| 80 |
byteremain3 = count3 - count2 |
| 81 |
|
| 82 |
bytes = struct.pack('i', count3) |
| 83 |
output.write(bytes) |
| 84 |
|
| 85 |
filepath = os.path.join('./Binary', 'HME_B.krn') |
| 86 |
count3 += os.path.getsize(filepath) |
| 87 |
count4 = ((count3 + 63) >> 6) << 6 |
| 88 |
byteremain4 = count4 - count3 |
| 89 |
|
| 90 |
bytes = struct.pack('i', count4) |
| 91 |
output.write(bytes) |
| 92 |
|
| 93 |
filepath = os.path.join('./Binary', 'HME_VDENC.krn') |
| 94 |
count4 += os.path.getsize(filepath) |
| 95 |
count5 = ((count4 + 63) >> 6) << 6 |
| 96 |
byteremain5 = count5 - count4 |
| 97 |
|
| 98 |
bytes = struct.pack('i', count5) |
| 99 |
output.write(bytes) |
| 100 |
|
| 101 |
filepath = os.path.join('./Binary', 'DS_Convert.krn') |
| 102 |
count5 += os.path.getsize(filepath) |
| 103 |
count6 = ((count5 + 63) >> 6) << 6 |
| 104 |
byteremain6 = count6 - count5 |
| 105 |
|
| 106 |
zerofill = chr(0)*36 |
| 107 |
output.write(zerofill.encode(encoding = "utf-8")); |
| 108 |
|
| 109 |
filepath = os.path.join('./Binary', 'DS4x_Frame.krn') |
| 110 |
fileobj = open(filepath, 'rb') |
| 111 |
|
| 112 |
while 1: |
| 113 |
filebytes = fileobj.read() |
| 114 |
|
| 115 |
if not filebytes: |
| 116 |
byteremain = count1 - os.path.getsize(filepath) |
| 117 |
zerofill = chr(0)*byteremain1 |
| 118 |
output.write(zerofill.encode(encoding = "utf-8")) |
| 119 |
break |
| 120 |
|
| 121 |
output.write(filebytes) |
| 122 |
fileobj.close() |
| 123 |
|
| 124 |
filepath = os.path.join('./Binary', 'DS2x_Frame.krn') |
| 125 |
fileobj = open(filepath, 'rb') |
| 126 |
|
| 127 |
while 1: |
| 128 |
filebytes = fileobj.read() |
| 129 |
|
| 130 |
if not filebytes: |
| 131 |
zerofill = chr(0)*byteremain2 |
| 132 |
output.write(zerofill.encode(encoding = "utf-8")) |
| 133 |
break |
| 134 |
|
| 135 |
output.write(filebytes) |
| 136 |
fileobj.close() |
| 137 |
|
| 138 |
filepath = os.path.join('./Binary', 'HME_P.krn') |
| 139 |
fileobj = open(filepath, 'rb') |
| 140 |
|
| 141 |
while 1: |
| 142 |
filebytes = fileobj.read() |
| 143 |
|
| 144 |
if not filebytes: |
| 145 |
zerofill = chr(0)*byteremain3 |
| 146 |
output.write(zerofill.encode(encoding = "utf-8")) |
| 147 |
break |
| 148 |
|
| 149 |
output.write(filebytes) |
| 150 |
fileobj.close() |
| 151 |
|
| 152 |
filepath = os.path.join('./Binary', 'HME_B.krn') |
| 153 |
fileobj = open(filepath, 'rb') |
| 154 |
|
| 155 |
while 1: |
| 156 |
filebytes = fileobj.read() |
| 157 |
|
| 158 |
if not filebytes: |
| 159 |
zerofill = chr(0)*byteremain4 |
| 160 |
output.write(zerofill.encode(encoding = "utf-8")) |
| 161 |
break |
| 162 |
|
| 163 |
output.write(filebytes) |
| 164 |
fileobj.close() |
| 165 |
|
| 166 |
filepath = os.path.join('./Binary', 'HME_VDENC.krn') |
| 167 |
fileobj = open(filepath, 'rb') |
| 168 |
|
| 169 |
while 1: |
| 170 |
filebytes = fileobj.read() |
| 171 |
|
| 172 |
if not filebytes: |
| 173 |
zerofill = chr(0)*byteremain5 |
| 174 |
output.write(zerofill.encode(encoding = "utf-8")) |
| 175 |
break |
| 176 |
|
| 177 |
output.write(filebytes) |
| 178 |
fileobj.close() |
| 179 |
|
| 180 |
filepath = os.path.join('./Binary', 'DS_Convert.krn') |
| 181 |
fileobj = open(filepath, 'rb') |
| 182 |
|
| 183 |
while 1: |
| 184 |
filebytes = fileobj.read() |
| 185 |
|
| 186 |
if not filebytes: |
| 187 |
zerofill = chr(0)*128 |
| 188 |
output.write(zerofill.encode(encoding = "utf-8")) |
| 189 |
break |
| 190 |
|
| 191 |
output.write(filebytes) |
| 192 |
fileobj.close() |
| 193 |
|
| 194 |
output.close() |
| 195 |
print ("Completed kernel merge") |
| 196 |
|
| 197 |
def main(): |
| 198 |
|
| 199 |
k2s = GenSource2Bin() |
| 200 |
|
| 201 |
k2s.iga_compile() |
| 202 |
k2s.join() |
| 203 |
k2s.deleteFile() |
| 204 |
|
| 205 |
if __name__=='__main__': |
| 206 |
main() |