file-type

Basic-Manim项目教程:测试更新Manim动画引擎功能

ZIP文件

下载需积分: 9 | 21.1MB | 更新于2025-09-03 | 17 浏览量 | 0 下载量 举报 收藏
download 立即下载
根据提供的文件信息,我们可以提炼出以下知识点: 1. **Manim动画引擎**: - Manim是一个由3b1b(Grant Sanderson)创建的开源动画引擎,它专门用于制作教育视频,尤其在数学和科学领域中使用,可以创建具有数学公式的动画。 - Manim的特点包括高度定制和精确控制动画的每一个细节,使得创建复杂的动画和解释复杂的概念变得可行。 2. **Basic-Manim项目**: - Basic-Manim是一个专门用于测试和更新基本Manim功能的项目。 - 该项目可能是一个独立的分支或者版本,专注于维护和改进核心动画功能,确保Manim能够稳定运行,并且满足用户的基本需求。 - 它基于特定的Manim版本,即manim-19Dec19-3b1b,表明这是一个相对稳定的版本,可能与其他版本的Manim相比有不同的特性和改进。 3. **Windows 10安装指南**: - 安装Manim需要操作系统支持,文件中提到了Windows 10,意味着该指南是针对Windows 10用户设计的。 - 用户首先需要下载基本Manim的文件,接着解压缩到指定的工作目录。 4. **系统准备和环境安装**: - 在安装Manim之前,系统需要进行一定的准备,这可能包括安装一些必要的系统组件或依赖。 - 使用Anaconda进行安装,Anaconda是一个流行的Python分发版,它集成了许多科学计算相关的库和工具,非常适合用于科学计算和数据分析项目。 - 创建一个专门的Conda环境(称为'manim'),可以避免与其他项目或Python版本发生依赖冲突,确保环境的整洁和项目的独立性。 5. **Conda环境的创建与配置**: - 使用`conda create -n manim python=3.8`命令创建一个新的Conda环境,指定Python版本为3.8,这样做是为了确保软件包的兼容性和稳定性。 - 通过`conda activate manim`命令激活新创建的环境,此时用户应在命令提示符看到环境名前缀。 - 在激活的环境中安装必要的Python软件包,比如numpy、tqdm、scipy、pillow、pycairo、pydub、pyreadline等,这些软件包支持Manim的运行并提供额外的功能。 6. **Manim的Python软件包安装**: - `pip`是Python的包管理工具,用于安装、卸载和管理Python包。在manim环境中使用pip安装上述软件包,是确保Manim可以访问到这些必要依赖的步骤。 - 安装过程中,用户可能需要按照特定的顺序安装某些软件包,以避免依赖问题。 7. **可能存在的额外步骤**: - 文件中提到"其他必要时",意味着可能还有其他步骤或安装细节未在文件中详细说明,用户可能需要根据实际情况或错误信息进行额外的操作或问题解决。 通过以上知识点的介绍,可以较为全面地了解Basic-Manim项目以及如何在Windows 10系统上准备环境并安装Manim。这些知识对于想要开始使用Manim制作动画的用户来说是非常宝贵的,可以帮助他们避免一些常见的安装和配置问题。

相关推荐

filetype

ERROR [browser] ❌ Failed to create new browser session: BrowserType.launch: Target page, context or browser has been closed Browser logs: <launching> C:\Users\小白\AppData\Local\ms-playwright\chromium-1179\chrome-win\chrome.exe --disable-field-trial-config --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AcceptCHFrame,AutoExpandDetailsElement,AvoidUnnecessaryBeforeUnloadCheckSync,CertificateTransparencyComponentUpdater,DestroyProfileOnBrowserClose,DialMediaRouteProvider,ExtensionManifestV2Disabled,GlobalMediaControls,HttpsUpgrades,ImprovedCookieControls,LazyFrameLoading,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --force-color-profile=srgb --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --unsafely-disable-devtools-self-xss-warnings --enable-automation --no-sandbox --disable-session-crashed-bubble --hide-scrollbars --disable-focus-on-load --no-default-browser-check --no-startup-window --enable-logging=stderr --disable-desktop-notifications --disable-sync --disable-infobars --disable-features=Translate,AcceptCHFrame,OptimizationHints,ProcessPerSiteUpToMainFrameThreshold,InterestFeedContentSuggestions,BackForwardCache,LazyFrameLoading,PrivacySandboxSettings4,AutofillServerCommunication,CertificateTransparencyComponentUpdater,DestroyProfileOnBrowserClose,CrashReporting,OverscrollHistoryNavigation,InfiniteSessionRestore --export-tagged-pdf --disable-blink-features=AutomationControlled --window-position=-8,0 --allow-legacy-extension-manifests --allow-pre-commit-input --hide-crash-restore-bubble --disable-print-preview --ash-no-nudges --silent-debugger-extension-api --install-autogenerated-theme=0,0,0 --disable-external-intent-requests --enable-features=NetworkService --disable-datasaver-prompt --disable-breakpad --log-level=2 --safebrowsing-disable-auto-update --disable-search-engine-choice-screen --disable-window-activation --disable-speech-synthesis-api --disable-prompt-on-repost --metrics-recording-only --remote-debugging-port=9242 --simulate-outdated-no-au="Tue, 31 Dec 2099 23:59:59 GMT" --disable-hang-monitor --suppress-message-center-popups --generate-pdf-document-outline --noerrdialogs --disable-client-side-phishing-detection --window-size=1280,1100 --disable-speech-api --disable-domain-reliability --no-pings --user-data-dir=C:\Users\小白\AppData\Local\Temp\playwright_chromiumdev_profile-ho8MPo --remote-debugging-pipe --no-startup-window <launched> pid=18764 [pid=18764][err] [18764:9348:0710/001816.024:WARNING:chrome\browser\signin\account_consistency_mode_manager.cc:73] Desktop Identity Consistency cannot be enabled as no OAuth client ID and client secret have been configured. [pid=18764][err] [18764:9348:0710/001816.043:WARNING:chrome\browser\chrome_browser_main_win.cc:863] Command line too long for RegisterApplicationRestart: --allow-legacy-extensio --allow-pre-commit-input --disable-back-forward-cache --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-blink-features=AutomationControlled --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --disable-default-apps --disable-desktop-notifications --disable-dev-shm-usage --disable-extensions --disable-features=Translate,AcceptCHFrame,OptimizationHints,ProcessPerSiteUpToMainFrameThreshold,InterestFeedContentSuggestions,BackForwardCache,LazyFrameLoading,PrivacySandboxSettings4,AutofillServerCommunication,CertificateTransparencyComponentUpdater,DestroyProfileOnBrowserClose,CrashReporting,OverscrollHistoryNavigation,InfiniteSessionRestore --disable-field-trial-config --disable-focus-on-load --disable-hang-monitor --disable-infobars --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-search-engine-choice-screen --disable-session-crashed-bubble --disable-sync --enable-automation --enable-logging=stderr --export-tagged-pdf --force-color-profile=srgb --hide-scrollbars --metrics-recording-only --no-default-browser-check --no-first-run --no-sandbox --no-service-autorun --no-startup-window --password-store=basic --unsafely-disable-devtools-self-xss-warnings --use-mock-keychain --window-position=-8,0 --restore-last-session --restart [pid=18764] <process did exit: exitCode=0, signal=null> [pid=18764] starting temporary directories cleanup Call log: - <launching> C:\Users\小白\AppData\Local\ms-playwright\chromium-1179\chrome-win\chrome.exe --disable-field-trial-config --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AcceptCHFrame,AutoExpandDetailsElement,AvoidUnnecessaryBeforeUnloadCheckSync,CertificateTransparencyComponentUpdater,DestroyProfileOnBrowserClose,DialMediaRouteProvider,ExtensionManifestV2Disabled,GlobalMediaControls,HttpsUpgrades,ImprovedCookieControls,LazyFrameLoading,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --force-color-profile=srgb --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --unsafely-disable-devtools-self-xss-warnings --enable-automation --no-sandbox --disable-session-crashed-bubble --hide-scrollbars --disable-focus-on-load --no-default-browser-check --no-startup-window --enable-logging=stderr --disable-desktop-notifications --disable-sync --disable-infobars --disable-features=Translate,AcceptCHFrame,OptimizationHints,ProcessPerSiteUpToMainFrameThreshold,InterestFeedContentSuggestions,BackForwardCache,LazyFrameLoading,PrivacySandboxSettings4,AutofillServerCommunication,CertificateTransparencyComponentUpdater,DestroyProfileOnBrowserClose,CrashReporting,OverscrollHistoryNavigation,InfiniteSessionRestore --export-tagged-pdf --disable-blink-features=AutomationControlled --window-position=-8,0 --allow-legacy-extension-manifests --allow-pre-commit-input --hide-crash-restore-bubble --disable-print-preview --ash-no-nudges --silent-debugger-extension-api --install-autogenerated-theme=0,0,0 --disable-external-intent-requests --enable-features=NetworkService --disable-datasaver-prompt --disable-breakpad --log-level=2 --safebrowsing-disable-auto-update --disable-search-engine-choice-screen --disable-window-activation --disable-speech-synthesis-api --disable-prompt-on-repost --metrics-recording-only --remote-debugging-port=9242 --simulate-outdated-no-au="Tue, 31 Dec 2099 23:59:59 GMT" --disable-hang-monitor --suppress-message-center-popups --generate-pdf-document-outline --noerrdialogs --disable-client-side-phishing-detection --window-size=1280,1100 --disable-speech-api --disable-domain-reliability --no-pings --user-data-dir=C:\Users\小白\AppData\Local\Temp\playwright_chromiumdev_profile-ho8MPo --remote-debugging-pipe --no-startup-window - <launched> pid=18764 - [pid=18764][err] [18764:9348:0710/001816.024:WARNING:chrome\browser\signin\account_consistency_mode_manager.cc:73] Desktop Identity Consistency cannot be enabled as no OAuth client ID and client secret have been configured. - [pid=18764][err] [18764:9348:0710/001816.043:WARNING:chrome\browser\chrome_browser_main_win.cc:863] Command line too long for RegisterApplicationRestart: --allow-legacy-extensio --allow-pre-commit-input --disable-back-forward-cache --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-blink-features=AutomationControlled --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --disable-default-apps --disable-desktop-notifications --disable-dev-shm-usage --disable-extensions --disable-features=Translate,AcceptCHFrame,OptimizationHints,ProcessPerSiteUpToMainFrameThreshold,InterestFeedContentSuggestions,BackForwardCache,LazyFrameLoading,PrivacySandboxSettings4,AutofillServerCommunication,CertificateTransparencyComponentUpdater,DestroyProfileOnBrowserClose,CrashReporting,OverscrollHistoryNavigation,InfiniteSessionRestore --disable-field-trial-config --disable-focus-on-load --disable-hang-monitor --disable-infobars --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-search-engine-choice-screen --disable-session-crashed-bubble --disable-sync --enable-automation --enable-logging=stderr --export-tagged-pdf --force-color-profile=srgb --hide-scrollbars --metrics-recording-only --no-default-browser-check --no-first-run --no-sandbox --no-service-autorun --no-startup-window --password-store=basic --unsafely-disable-devtools-self-xss-warnings --use-mock-keychain --window-position=-8,0 --restore-last-session --restart - [pid=18764] <process did exit: exitCode=0, signal=null> - [pid=18764] starting temporary directories cleanup (did the browser process quit?)

filetype

#### emulator_gen.py #### # Created by Lorenzo Lagostina in 10/10/2022 # # The program allows to automatically write the vhdl description of the top entity of the emulator architecture # If the decoder or Quantum Emulator Process do not yet exist for the desired parameters, it creates them import sys import os import math from QEP_gen import QEP_gen from dec_gen import dec_gen from mux_gen import mux_gen def emulator_gen(qubit_number, windowing_order, cu_sharing_order, qimm_parallelism): N = int(qubit_number) W = int(windowing_order) S = int(cu_sharing_order) Q = int(qimm_parallelism) #Argument correctness chack if W > N-1 or S > N-W-1: print('ILLEGAL windowing order\n') exit(-1) # Creates missing components QPEFile = '../QPE/QEP_N_' + qubit_number +'_W_' + windowing_order + '_S_' + cu_sharing_order + '.vhd' if not(os.path.exists(QPEFile)): QEP_gen(qubit_number=qubit_number,windowing_order=windowing_order,cu_sharing_order=cu_sharing_order) decFile = '../basic_blocks/decoders/src/state_decoder_N_' + qubit_number + '.vhd' if not(os.path.exists(decFile)): dec_gen(qubit_number=qubit_number) muxFile = '../basic_blocks/multiplexers/src/multiplexer_' + str(2**Q) + '_1.vhd' if not(os.path.exists(muxFile)): mux_gen(str(2**Q)) ##### Header and entity # entityName = 'EMULATOR_N_' + qubit_number +'_W_' + windowing_order + '_S_' + cu_sharing_order + '_Q_' + qimm_parallelism fileOutName = '../emulator/src/' + entityName + '.vhd' fileOut = open(fileOutName, 'w') newLine = 'LIBRARY IEEE;\nUSE IEEE.STD_LOGIC_1164.ALL;\n\nENTITY ' + entityName + ' IS\nGENERIC( K : INTEGER := 20 );\nPORT (\n' fileOut.write(newLine) newLine = '\t' + entityName + '_IN_FROM_MCU : IN STD_LOGIC_VECTOR (1 DOWNTO 0);\n' fileOut.write(newLine) newLine = '\t' + entityName + '_IN_CLK : IN STD_LOGIC;\n' fileOut.write(newLine) newLine = '\t' + entityName + '_IN_RSTN : IN STD_LOGIC;\n' fileOut.write(newLine) newLine = '\t' + entityName + '_OUT_TO_MCU : OUT STD_LOGIC_VECTOR (1 DOWNTO 0);\n' fileOut.write(newLine) newLine = '\t' + entityName + '_IN_OUT_BUS : INOUT STD_LOGIC_VECTOR (K-1 DOWNTO 0)\n' fileOut.write(newLine) newLine = ');\nEND ENTITY;\n' fileOut.write(newLine) # ##### ##### Begin architecture and declare components # newLine = 'ARCHITECTURE generated OF ' + entityName + ' IS\n' fileOut.write(newLine) # QPE control newLine = 'COMPONENT QPE_control IS\n' fileOut.write(newLine) newLine = 'PORT (\n QPE_CONTROL_IN_FROM_MCU : IN STD_LOGIC_VECTOR (1 DOWNTO 0);\n QPE_CONTROL_IN_ACK : IN STD_LOGIC;\n QPE_CONTROL_IN_COMPLETED : IN STD_LOGIC;\n QPE_CONTROL_IN_GATE_COMP : IN STD_LOGIC;\n QPE_CONTROL_IN_CLK : IN STD_LOGIC;\n QPE_CONTROL_IN_RSTN : IN STD_LOGIC;\n QPE_CONTROL_OUT_TO_MCU : OUT STD_LOGIC_VECTOR (1 DOWNTO 0);\n QPE_CONTROL_OUT_CLR_ALL : OUT STD_LOGIC;\n QPE_CONTROL_OUT_SAVE_QUBIT_NUMB : OUT STD_LOGIC;\n QPE_CONTROL_OUT_SAMPLE_INSTR : OUT STD_LOGIC;\n QPE_CONTROL_OUT_SAMPLE_SIN_COS : OUT STD_LOGIC;\n QPE_CONTROL_OUT_SAVE_SIN_COS : OUT STD_LOGIC;\n QPE_CONTROL_OUT_EN_RES_CNT : OUT STD_LOGIC;\n QPE_CONTROL_OUT_EN_OUT_BUF : OUT STD_LOGIC;\n QPE_CONTROL_OUT_MCU_ACK_TOGGLE : OUT STD_LOGIC;\nQPE_CONTROL_OUT_EN_QEP_DONE : OUT STD_LOGIC\n );\n' fileOut.write(newLine) newLine = 'END COMPONENT;\n' fileOut.write(newLine) # Counter newLine = 'COMPONENT counter IS\n' fileOut.write(newLine) newLine = 'GENERIC (N : NATURAL := 32);\nPORT (\nCOUNTER_IN_EN : IN STD_LOGIC;\nCOUNTER_IN_CLR : IN STD_LOGIC;\nCOUNTER_IN_CLK : IN STD_LOGIC;\nCOUNTER_OUT_DATA : OUT STD_LOGIC_VECTOR(N-1 DOWNTO 0)\n);\n' fileOut.write(newLine) newLine = 'END COMPONENT;' fileOut.write(newLine) #register newLine = 'COMPONENT n_bit_register IS\n generic (n_bit: INTEGER);\n port (REG_IN_DATA: IN STD_LOGIC_VECTOR(n_bit - 1 DOWNTO 0);\n REG_IN_CLK, REG_IN_CLEAR, REG_IN_ENABLE: IN STD_LOGIC;\n REG_OUT_DATA: OUT STD_LOGIC_VECTOR(n_bit - 1 DOWNTO 0));\nEND COMPONENT;\n' fileOut.write(newLine) #Component mux_2_1 newLine = 'COMPONENT multiplexer_2_1 IS\n GENERIC (K : INTEGER := 20);\n PORT (\n MUX_2_1_IN_0 : IN STD_LOGIC_VECTOR (K-1 DOWNTO 0);\n MUX_2_1_IN_1 : IN STD_LOGIC_VECTOR (K-1 DOWNTO 0);\n MUX_2_1_IN_SEL : IN STD_LOGIC_VECTOR (0 DOWNTO 0);\n MUX_2_1_OUT_RES : OUT STD_LOGIC_VECTOR (K-1 DOWNTO 0));\nEND COMPONENT;\n' fileOut.write(newLine) #Component mux_2**Q_1 newLine = 'COMPONENT multiplexer_' + str(2**Q) + '_1 IS\n GENERIC (K : INTEGER := 20);\n PORT (\n' fileOut.write(newLine) for input_ind in range(2**Q): newLine = '\t\tMUX_' + str(2**Q) + '_1_IN_' + str(input_ind) + ' : IN STD_LOGIC_VECTOR (K-1 DOWNTO 0);\n' fileOut.write(newLine) newLine = ' MUX_' + str(2**Q) + '_1_IN_SEL : IN STD_LOGIC_VECTOR (' + str(Q-1) + ' DOWNTO 0);\n MUX_' + str(2**Q) + '_1_OUT_RES : OUT STD_LOGIC_VECTOR (K-1 DOWNTO 0));\nEND COMPONENT;\n' fileOut.write(newLine) # decoder decName = 'STATE_DECODER_N_' + qubit_number newLine = 'COMPONENT state_decoder_N_' + qubit_number + ' IS\n PORT (\n ' + decName + '_IN_QTGT : IN STD_LOGIC_VECTOR( ' + str(math.ceil(math.log2(N))-1) + ' DOWNTO 0);\n ' + decName + '_IN_QCTRL : IN STD_LOGIC_VECTOR( ' + str(math.ceil(math.log2(N))-1) + ' DOWNTO 0);\n ' + decName + '_IN_OPCODE : IN STD_LOGIC_VECTOR (3 DOWNTO 0);\n ' + decName + '_IN_SAVE_QBIT_NUMBER : IN STD_LOGIC;\n ' + decName + '_IN_CLEAR : IN STD_LOGIC;\n ' + decName + '_IN_CLK : IN STD_LOGIC;\n ' + decName + '_OUT_MASK_FIRST : OUT STD_LOGIC; \n' + decName + '_OUT_CTRL_MASK : OUT STD_LOGIC_VECTOR ( ' + str((2**N)-1) + ' DOWNTO 0)\n );\n END COMPONENT;\n' fileOut.write(newLine) # QEP QEPName = 'QEP_N_' + qubit_number +'_W_' + windowing_order + '_S_' + cu_sharing_order newLine = 'COMPONENT ' + QEPName + ' IS \n GENERIC (K : INTEGER := 20);\n PORT (\n' fileOut.write(newLine) newLine = '\t\t' + QEPName + '_IN_START : IN STD_LOGIC;\n\t\t' + QEPName + '_IN_QTGT : IN STD_LOGIC_VECTOR (' + str(math.ceil(math.log2(N))-1) +' DOWNTO 0); \n' fileOut.write(newLine) newLine = '\t\t' + QEPName + '_IN_CTRL_MASK : IN STD_LOGIC_VECTOR(' + str((2**N)-1) +' DOWNTO 0);\n\t\t'+ QEPName + '_IN_OPCODE : IN STD_LOGIC_VECTOR(3 DOWNTO 0);\n' fileOut.write(newLine) newLine = '\t\t' + QEPName + '_IN_SIN : IN STD_LOGIC_VECTOR(K-1 DOWNTO 0);\n\t\t' + QEPName + '_IN_COS : IN STD_LOGIC_VECTOR(K-1 DOWNTO 0);\n' fileOut.write(newLine) if W > 0: newLine ='\t\t' + QEPName + '_IN_WIN_SEL : IN STD_LOGIC_VECTOR (' + str(W-1) + ' DOWNTO 0);\n' fileOut.write(newLine) newLine = '\t\t' + QEPName + '_IN_OUT_STATE_SEL : IN STD_LOGIC_VECTOR(' + str(N-1) + ' DOWNTO 0);\n\t\t' + QEPName + '_IN_REAL_IMAG_SEL : IN STD_LOGIC_VECTOR (0 DOWNTO 0);\n' fileOut.write(newLine) newLine = '\t\t' + QEPName + '_IN_CLK : IN STD_LOGIC;\n\t\t' + QEPName + '_IN_CLEAR : IN STD_LOGIC;\n\t\t' + QEPName + '_IN_MASK_FIRST_COEFF : IN STD_LOGIC;\n\t\t' + QEPName + '_IN_ENABLE_STATE_UPDATE : IN STD_LOGIC;\n' fileOut.write(newLine) newLine = '\t\t' + QEPName + '_OUT_DONE : OUT STD_LOGIC;\n' fileOut.write(newLine) newLine = '\t\t' + QEPName + '_OUT_DATA : OUT STD_LOGIC_VECTOR (K-1 DOWNTO 0));\nEND COMPONENT\n;' fileOut.write(newLine) # ##### ##### Signal declaration # #QPE control newLine = 'SIGNAL FROM_QPE_CTRL_EN_QEP_DONE, GATE_COMPLETE, FETCH_INSTRUCTION, TO_QPE_CTRL_ACK, TO_QPE_CTRL_COMPLETE, FROM_QPE_CTRL_SAMPLE_SIN_COS, FROM_QPE_CTRL_SAVE_SIN_COS, FROM_QPE_CTRL_CLEAR, FROM_QPE_CTRL_SAMPLE_INSTR, FROM_QPE_CTRL_SAVE_QBIT_NUMB, FROM_QPE_CTRL_EN_RES_CNT : STD_LOGIC;\n' fileOut.write(newLine) #Sin cos addresses newLine = 'SIGNAL FROM_TRIG_ADD_SIN_COS_ADD : STD_LOGIC_VECTOR(' + qimm_parallelism + ' DOWNTO 0);\n' fileOut.write(newLine) newLine = 'SIGNAL FROM_DEC_MASK_FIRST : STD_LOGIC;\n' fileOut.write(newLine) newLine = 'SIGNAL FROM_DEC_QIMM : STD_LOGIC_VECTOR(' + str(Q-1) + ' DOWNTO 0);\n' fileOut.write(newLine) newLine = 'SIGNAL FROM_TRIG_UNIT_SIN, FROM_TRIG_UNIT_COS, FROM_FETCH_SIN_COS : STD_LOGIC_VECTOR (K-1 DOWNTO 0);' fileOut.write(newLine) newLine = 'SIGNAL ROW_SEL_SIN_COS, ENABLE_SIN_DEC, ENABLE_COS_DEC : STD_LOGIC_VECTOR( ' + str((2**Q)-1) + ' DOWNTO 0);\n' fileOut.write(newLine) #FROM_SIN_REG newLine = 'SIGNAL ' for sig_ind in range(2**Q): newLine += 'FROM_SIN_REG_' + str(sig_ind) if sig_ind != (2**Q)-1: newLine += ',' newLine += ': STD_LOGIC_VECTOR(K-1 DOWNTO 0);\n' fileOut.write(newLine) #FROM_COS_REG newLine = 'SIGNAL ' for sig_ind in range(2**Q): newLine += 'FROM_COS_REG_' + str(sig_ind) if sig_ind != (2**Q)-1: newLine += ',' newLine += ': STD_LOGIC_VECTOR(K-1 DOWNTO 0);\n' fileOut.write(newLine) newLine = 'SIGNAL ENABLE_SIN_REG, ENABLE_COS_REG : STD_LOGIC;\n' fileOut.write(newLine) newLine = 'SIGNAL FROM_FETCH_INSTR : STD_LOGIC_VECTOR(' + str(Q + 3 + 2*(math.ceil(math.log2(N)))) + ' DOWNTO 0);' fileOut.write(newLine) newLine = 'SIGNAL CTRL_MASK : STD_LOGIC_VECTOR ( ' + str((2**N)-1) + ' DOWNTO 0);\n' fileOut.write(newLine) newLine = 'SIGNAL OPCODE : STD_LOGIC_VECTOR (3 DOWNTO 0);\n' fileOut.write(newLine) newLine = 'SIGNAL QTGT, QCTRL : STD_LOGIC_VECTOR (' + str(math.ceil(math.log2(N)) -1 ) + ' DOWNTO 0);\n' fileOut.write(newLine) newLine = 'SIGNAL FROM_QEP_DONE, QEP_DONE_ENABLED, TO_QEP_START, TO_QEP_START_PIPE :STD_LOGIC;\n' fileOut.write(newLine) if W > 0: newLine = 'SIGNAL FROM_WIN_CNT_TC : STD_LOGIC;\n' fileOut.write(newLine) newLine = 'SIGNAL WINDOW_SELECTOR : STD_LOGIC_VECTOR( ' + str(W-1) + ' DOWNTO 0);\n' fileOut.write(newLine) newLine = 'SIGNAL RESULT_SELECTOR : STD_LOGIC_VECTOR(' + str(N) + ' DOWNTO 0);\n' fileOut.write(newLine) newLine = 'SIGNAL BUFFER_IN, BUFFER_OUT, RESULT : STD_LOGIC_VECTOR(K-1 DOWNTO 0);\n' fileOut.write(newLine) newLine = 'SIGNAL OUT_BUF_EN, MCU_ACK_TOGGLE : STD_LOGIC;\n' fileOut.write(newLine) # ##### ##### Begin and connections # newLine = 'BEGIN\n' fileOut.write(newLine) # QPE control newLine = 'QPE_CTRL: QPE_control PORT MAP(\n QPE_CONTROL_IN_FROM_MCU => ' + entityName + '_IN_FROM_MCU ,\n QPE_CONTROL_IN_ACK => TO_QPE_CTRL_ACK ,\n QPE_CONTROL_IN_COMPLETED => TO_QPE_CTRL_COMPLETE , \n QPE_CONTROL_IN_GATE_COMP => GATE_COMPLETE,\n QPE_CONTROL_IN_CLK => ' + entityName + '_IN_CLK ,\n QPE_CONTROL_IN_RSTN => ' + entityName + '_IN_RSTN,\n QPE_CONTROL_OUT_TO_MCU => ' + entityName + '_OUT_TO_MCU ,\n QPE_CONTROL_OUT_CLR_ALL => FROM_QPE_CTRL_CLEAR ,\n QPE_CONTROL_OUT_SAVE_QUBIT_NUMB => FROM_QPE_CTRL_SAVE_QBIT_NUMB ,\n QPE_CONTROL_OUT_SAMPLE_INSTR => FROM_QPE_CTRL_SAMPLE_INSTR ,\n QPE_CONTROL_OUT_SAMPLE_SIN_COS => FROM_QPE_CTRL_SAMPLE_SIN_COS ,\n QPE_CONTROL_OUT_SAVE_SIN_COS => FROM_QPE_CTRL_SAVE_SIN_COS ,\n QPE_CONTROL_OUT_EN_RES_CNT => FROM_QPE_CTRL_EN_RES_CNT,\n QPE_CONTROL_OUT_EN_OUT_BUF => OUT_BUF_EN,\n QPE_CONTROL_OUT_MCU_ACK_TOGGLE => MCU_ACK_TOGGLE,\nQPE_CONTROL_OUT_EN_QEP_DONE => FROM_QPE_CTRL_EN_QEP_DONE);\n' fileOut.write(newLine) # Trig counter newLine = 'CNT_TRIG_ADD : counter GENERIC MAP (' + str(Q+1) + ')\nPORT MAP (\nCOUNTER_IN_EN => FROM_QPE_CTRL_SAVE_SIN_COS ,\nCOUNTER_IN_CLR => FROM_QPE_CTRL_CLEAR,\nCOUNTER_IN_CLK => ' + entityName + '_IN_CLK,\nCOUNTER_OUT_DATA => FROM_TRIG_ADD_SIN_COS_ADD);\n' fileOut.write(newLine) ##### Trigronometric address selector # newLine = 'ENABLE_SIN_REG <= FROM_QPE_CTRL_SAVE_SIN_COS AND ( NOT FROM_TRIG_ADD_SIN_COS_ADD(0) );\n' fileOut.write(newLine) newLine = 'ENABLE_COS_REG <= FROM_QPE_CTRL_SAVE_SIN_COS AND FROM_TRIG_ADD_SIN_COS_ADD(0);\n' fileOut.write(newLine) #newLine = 'MUX_TRIG_ADD_SELECTION : multiplexer_2_1 GENERIC MAP (K => ' + qimm_parallelism + ')\n PORT MAP (\n\t\t MUX_2_1_IN_0 => FROM_DEC_QIMM ,\n\t\t MUX_2_1_IN_1 => FROM_TRIG_ADD_SIN_COS_ADD(' + qimm_parallelism + ' DOWNTO 1) ,\n\t\t\t\t MUX_2_1_IN_SEL => FROM_QPE_CTRL_SAVE_SIN_COS ,\n MUX_2_1_OUT_RES => SEL_TRIG_ADD\n );\n' #fileOut.write(newLine) newLine = 'ROW_SEL_SIN_COS <= \n' fileOut.write(newLine) for sin_cos_index in range(2**Q): newLine = '\"' + '{0:b}'.format(2**sin_cos_index).zfill(2**Q) + '\" WHEN FROM_TRIG_ADD_SIN_COS_ADD( ' + qimm_parallelism + ' DOWNTO 1) = \"' + '{0:b}'.format(sin_cos_index).zfill(Q) + '\" ELSE\n' fileOut.write(newLine) newLine = '(OTHERS => \'0\');\n' fileOut.write(newLine) for sin_cos_ind in range(2**Q): newLine = 'ENABLE_SIN_DEC(' + str(sin_cos_ind) + ') <= ENABLE_SIN_REG AND ROW_SEL_SIN_COS(' + str(sin_cos_ind) + ');\n' fileOut.write(newLine) newLine = 'ENABLE_COS_DEC(' + str(sin_cos_ind) + ') <= ENABLE_COS_REG AND ROW_SEL_SIN_COS(' + str(sin_cos_ind) + ');\n' fileOut.write(newLine) # ##### # Sin Cos regs for reg_ind in range(2**Q): newLine = 'SIN_REG_' + str(reg_ind) + ' : n_bit_register\nGENERIC MAP (K)\nPORT MAP(\n REG_IN_DATA => FROM_FETCH_SIN_COS ,\n REG_IN_ENABLE => ENABLE_SIN_DEC(' + str(reg_ind) + ') ,\n REG_IN_CLEAR => FROM_QPE_CTRL_CLEAR ,\n REG_IN_CLK => ' + entityName + '_IN_CLK ,\n REG_OUT_DATA => FROM_SIN_REG_' + str(reg_ind) + ');\n' fileOut.write(newLine) newLine = 'COS_REG_' + str(reg_ind) + ' : n_bit_register\nGENERIC MAP (K)\nPORT MAP(\n REG_IN_DATA => FROM_FETCH_SIN_COS ,\n REG_IN_ENABLE => ENABLE_COS_DEC(' + str(reg_ind) + ') ,\n REG_IN_CLEAR => FROM_QPE_CTRL_CLEAR ,\n REG_IN_CLK => ' + entityName + '_IN_CLK ,\n REG_OUT_DATA => FROM_COS_REG_' + str(reg_ind) + ');\n' fileOut.write(newLine) ##### Sin Cos selection mux # newLine = 'SIN_SELECTION : multiplexer_' + str(2**Q) + '_1 GENERIC MAP (K)\n PORT MAP (\n' fileOut.write(newLine) for sin_cos_ind in range(2**Q): newLine = '\t\t MUX_' + str(2**Q) + '_1_IN_' + str(sin_cos_ind) + ' => FROM_SIN_REG_' + str(sin_cos_ind) + ' ,\n' fileOut.write(newLine) newLine ='\t\t\t\t MUX_' + str(2**Q) + '_1_IN_SEL => FROM_DEC_QIMM ,\n MUX_' + str(2**Q) + '_1_OUT_RES => FROM_TRIG_UNIT_SIN\n );\n' fileOut.write(newLine) newLine = 'COS_SELECTION : multiplexer_' + str(2**Q) + '_1 GENERIC MAP (K)\n PORT MAP (\n' fileOut.write(newLine) for sin_cos_ind in range(2**Q): newLine = '\t\t MUX_' + str(2**Q) + '_1_IN_' + str(sin_cos_ind) + ' => FROM_COS_REG_' + str(sin_cos_ind) + ' ,\n' fileOut.write(newLine) newLine ='\t\t\t\t MUX_' + str(2**Q) + '_1_IN_SEL => FROM_DEC_QIMM ,\n MUX_' + str(2**Q) + '_1_OUT_RES => FROM_TRIG_UNIT_COS\n );\n' fileOut.write(newLine) # ##### ##### Fetch registers # newLine = 'BUFFER_IN <= ' + entityName + '_IN_OUT_BUS;\n' fileOut.write(newLine) newLine = 'REG_FETCH_SIN_COS : n_bit_register\nGENERIC MAP (K)\nPORT MAP(\n REG_IN_DATA => BUFFER_IN ,\n REG_IN_ENABLE => FROM_QPE_CTRL_SAMPLE_SIN_COS ,\n REG_IN_CLEAR => FROM_QPE_CTRL_CLEAR ,\n REG_IN_CLK => ' + entityName + '_IN_CLK ,\n REG_OUT_DATA => FROM_FETCH_SIN_COS);\n' fileOut.write(newLine) newLine = 'FETCH_INSTRUCTION <= FROM_QPE_CTRL_SAMPLE_INSTR;\n' fileOut.write(newLine) newLine = 'TO_QPE_CTRL_ACK <= FROM_QPE_CTRL_SAMPLE_SIN_COS OR FETCH_INSTRUCTION;\n' fileOut.write(newLine) newLine = 'REG_FETCH_INSTR : n_bit_register\nGENERIC MAP (' + str(Q + 4 + 2*(math.ceil(math.log2(N)))) + ')\nPORT MAP(\n REG_IN_DATA => BUFFER_IN(' + str(Q + 3 + 2*(math.ceil(math.log2(N)))) + ' DOWNTO 0) ,\n REG_IN_ENABLE => FETCH_INSTRUCTION ,\n REG_IN_CLEAR => FROM_QPE_CTRL_CLEAR ,\n REG_IN_CLK => ' + entityName + '_IN_CLK ,\n REG_OUT_DATA => FROM_FETCH_INSTR);\n' fileOut.write(newLine) # ##### ##### Decoding stage # newLine = 'DEC_STAGE : state_decoder_N_' + qubit_number + ' \n PORT MAP (\n ' + decName + '_IN_QTGT => QTGT,\n ' + decName + '_IN_QCTRL => FROM_FETCH_INSTR( ' + str(Q + math.ceil(math.log2(N))-1) + ' DOWNTO ' + str(Q) + '),\n ' + decName + '_IN_OPCODE => FROM_FETCH_INSTR(' + str(Q + 3 + 2*math.ceil(math.log2(N))) + ' DOWNTO ' + str(Q + 2*math.ceil(math.log2(N))) + '),\n ' + decName + '_IN_SAVE_QBIT_NUMBER => FROM_QPE_CTRL_SAVE_QBIT_NUMB,\n ' + decName + '_IN_CLEAR => FROM_QPE_CTRL_CLEAR,\n ' + decName + '_IN_CLK => ' + entityName + '_IN_CLK,\n ' + decName + '_OUT_MASK_FIRST => FROM_DEC_MASK_FIRST, \n' + decName + '_OUT_CTRL_MASK => CTRL_MASK\n );\n' fileOut.write(newLine) newLine = 'FROM_DEC_QIMM <= FROM_FETCH_INSTR (' + str(Q-1) + ' DOWNTO 0);\n' fileOut.write(newLine) newLine = 'OPCODE <= FROM_FETCH_INSTR(' + str(Q + 3 + 2*(math.ceil(math.log2(N)))) + ' DOWNTO ' + str(Q + 2*(math.ceil(math.log2(N)))) + ');\n' fileOut.write(newLine) newLine = 'QTGT <= FROM_FETCH_INSTR(' + str(Q -1 + 2*(math.ceil(math.log2(N)))) + ' DOWNTO ' + str(Q + (math.ceil(math.log2(N)))) + ');\n' fileOut.write(newLine) #newLine = 'QTGT <= FROM_FETCH_INSTR(' + str(Q -1 + (math.ceil(math.log2(N)))) + ' DOWNTO ' + str(Q) + ');\n' #fileOut.write(newLine) # ##### ##### Enable qep done # newLine = 'QEP_DONE_ENABLED <= FROM_QPE_CTRL_EN_QEP_DONE AND FROM_QEP_DONE;\n' fileOut.write(newLine) # ##### ##### Window selection cnt # if W > 0: newLine = 'CNT_WIN_SEL : counter GENERIC MAP (' + str(W) + ')\nPORT MAP (\nCOUNTER_IN_EN => QEP_DONE_ENABLED ,\nCOUNTER_IN_CLR => FROM_QPE_CTRL_CLEAR,\nCOUNTER_IN_CLK => ' + entityName + '_IN_CLK,\nCOUNTER_OUT_DATA => WINDOW_SELECTOR);\n' fileOut.write(newLine) newLine = 'FROM_WIN_CNT_TC <= \'1\' WHEN WINDOW_SELECTOR = \"' + '{0:b}'.format((2**W)-1).zfill(W) + '\" ELSE \'0\';\n' fileOut.write(newLine) newLine = 'GATE_COMPLETE <= FROM_WIN_CNT_TC AND FROM_QEP_DONE AND QEP_DONE_ENABLED;\n' fileOut.write(newLine) else : newLine = 'GATE_COMPLETE <= QEP_DONE_ENABLED;\n' fileOut.write(newLine) # ##### ##### Results counter # newLine = 'CNT_RES_SEL : counter GENERIC MAP (' + str(N+1) + ')\nPORT MAP (\nCOUNTER_IN_EN => FROM_QPE_CTRL_EN_RES_CNT ,\nCOUNTER_IN_CLR => FROM_QPE_CTRL_CLEAR,\nCOUNTER_IN_CLK => ' + entityName + '_IN_CLK,\nCOUNTER_OUT_DATA => RESULT_SELECTOR);\n' fileOut.write(newLine) newLine = 'TO_QPE_CTRL_COMPLETE <= \'1\' WHEN RESULT_SELECTOR = \"' + '{0:b}'.format((2**(N+1))-1).zfill(N+1) + '\" ELSE \'0\';\n' fileOut.write(newLine) # ##### ##### QEP # newLine = 'TO_QEP_START_PIPE <= FETCH_INSTRUCTION AND NOT FROM_QPE_CTRL_SAVE_QBIT_NUMB;\n' fileOut.write(newLine) newLine = 'REG_START_PIPE : n_bit_register\nGENERIC MAP (1)\nPORT MAP(\n REG_IN_DATA(0) => TO_QEP_START_PIPE ,\n REG_IN_ENABLE => \'1\' ,\n REG_IN_CLEAR => FROM_QPE_CTRL_CLEAR ,\n REG_IN_CLK => ' + entityName + '_IN_CLK ,\n REG_OUT_DATA(0) => TO_QEP_START);\n' fileOut.write(newLine) newLine = 'QEP_UNIT : ' + QEPName + ' \n GENERIC MAP (K)\n PORT MAP (\n' fileOut.write(newLine) newLine = '\t\t' + QEPName + '_IN_START => TO_QEP_START,\n\t\t' + QEPName + '_IN_QTGT => QTGT, \n' fileOut.write(newLine) newLine = '\t\t' + QEPName + '_IN_CTRL_MASK => CTRL_MASK,\n\t\t'+ QEPName + '_IN_OPCODE => OPCODE,\n' fileOut.write(newLine) newLine = '\t\t' + QEPName + '_IN_SIN => FROM_TRIG_UNIT_SIN,\n\t\t' + QEPName + '_IN_COS => FROM_TRIG_UNIT_COS ,\n' fileOut.write(newLine) if W > 0: newLine ='\t\t' + QEPName + '_IN_WIN_SEL => WINDOW_SELECTOR ,\n' fileOut.write(newLine) newLine = '\t\t' + QEPName + '_IN_OUT_STATE_SEL => RESULT_SELECTOR(' + str(N) + ' DOWNTO 1) ,\n\t\t' + QEPName + '_IN_REAL_IMAG_SEL => RESULT_SELECTOR(0 DOWNTO 0),\n' fileOut.write(newLine) newLine = '\t\t' + QEPName + '_IN_CLK => ' + entityName + '_IN_CLK,\n\t\t' + QEPName + '_IN_CLEAR => FROM_QPE_CTRL_CLEAR,\n\t\t' + QEPName + '_IN_MASK_FIRST_COEFF => FROM_DEC_MASK_FIRST,\n\t\t' + QEPName + '_IN_ENABLE_STATE_UPDATE => FROM_QPE_CTRL_EN_QEP_DONE,\n' fileOut.write(newLine) newLine = '\t\t' + QEPName + '_OUT_DONE => FROM_QEP_DONE,\n' fileOut.write(newLine) newLine = '\t\t' + QEPName + '_OUT_DATA => RESULT);\n' fileOut.write(newLine) newLine = 'BUFFER_OUT <= RESULT WHEN OUT_BUF_EN = \'1\' ELSE (OTHERS => \'Z\');\n' fileOut.write(newLine) # ##### newLine = '' + entityName + '_IN_OUT_BUS <= BUFFER_OUT;\n' fileOut.write(newLine) # ##### newLine = 'END generated;\n' fileOut.write(newLine) emulator_gen(sys.argv[1], sys.argv[2],sys.argv[3], sys.argv[4])

filetype

/* 3966 * Notes on Program-Order guarantees on SMP systems. 3967 * 3968 * MIGRATION 3969 * 3970 * The basic program-order guarantee on SMP systems is that when a task [t] 3971 * migrates, all its activity on its old CPU [c0] happens-before any subsequent 3972 * execution on its new CPU [c1]. 3973 * 3974 * For migration (of runnable tasks) this is provided by the following means: 3975 * 3976 * A) UNLOCK of the rq(c0)->lock scheduling out task t 3977 * B) migration for t is required to synchronize *both* rq(c0)->lock and 3978 * rq(c1)->lock (if not at the same time, then in that order). 3979 * C) LOCK of the rq(c1)->lock scheduling in task 3980 * 3981 * Release/acquire chaining guarantees that B happens after A and C after B. 3982 * Note: the CPU doing B need not be c0 or c1 3983 * 3984 * Example: 3985 * 3986 * CPU0 CPU1 CPU2 3987 * 3988 * LOCK rq(0)->lock 3989 * sched-out X 3990 * sched-in Y 3991 * UNLOCK rq(0)->lock 3992 * 3993 * LOCK rq(0)->lock // orders against CPU0 3994 * dequeue X 3995 * UNLOCK rq(0)->lock 3996 * 3997 * LOCK rq(1)->lock 3998 * enqueue X 3999 * UNLOCK rq(1)->lock 4000 * 4001 * LOCK rq(1)->lock // orders against CPU2 4002 * sched-out Z 4003 * sched-in X 4004 * UNLOCK rq(1)->lock 4005 * 4006 * 4007 * BLOCKING -- aka. SLEEP + WAKEUP 4008 * 4009 * For blocking we (obviously) need to provide the same guarantee as for 4010 * migration. However the means are completely different as there is no lock 4011 * chain to provide order. Instead we do: 4012 * 4013 * 1) smp_store_release(X->on_cpu, 0) -- finish_task() 4014 * 2) smp_cond_load_acquire(!X->on_cpu) -- try_to_wake_up() 4015 * 4016 * Example: 4017 * 4018 * CPU0 (schedule) CPU1 (try_to_wake_up) CPU2 (schedule) 4019 * 4020 * LOCK rq(0)->lock LOCK X->pi_lock 4021 * dequeue X 4022 * sched-out X 4023 * smp_store_release(X->on_cpu, 0); 4024 * 4025 * smp_cond_load_acquire(&X->on_cpu, !VAL); 4026 * X->state = WAKING 4027 * set_task_cpu(X,2) 4028 * 4029 * LOCK rq(2)->lock 4030 * enqueue X 4031 * X->state = RUNNING 4032 * UNLOCK rq(2)->lock 4033 * 4034 * LOCK rq(2)->lock // orders against CPU1 4035 * sched-out Z 4036 * sched-in X 4037 * UNLOCK rq(2)->lock 4038 * 4039 * UNLOCK X->pi_lock 4040 * UNLOCK rq(0)->lock 4041 * 4042 * 4043 * However, for wakeups there is a second guarantee we must provide, namely we 4044 * must ensure that CONDITION=1 done by the caller can not be reordered with 4045 * accesses to the task state; see try_to_wake_up() and set_current_state(). 4046 */ 4047 4048 /** 4049 * try_to_wake_up - wake up a thread 4050 * @p: the thread to be awakened 4051 * @state: the mask of task states that can be woken 4052 * @wake_flags: wake modifier flags (WF_*) 4053 * 4054 * Conceptually does: 4055 * 4056 * If (@state & @p->state) @p->state = TASK_RUNNING. 4057 * 4058 * If the task was not queued/runnable, also place it back on a runqueue. 4059 * 4060 * This function is atomic against schedule() which would dequeue the task. 4061 * 4062 * It issues a full memory barrier before accessing @p->state, see the comment 4063 * with set_current_state(). 4064 * 4065 * Uses p->pi_lock to serialize against concurrent wake-ups. 4066 * 4067 * Relies on p->pi_lock stabilizing: 4068 * - p->sched_class 4069 * - p->cpus_ptr 4070 * - p->sched_task_group 4071 * in order to do migration, see its use of select_task_rq()/set_task_cpu(). 4072 * 4073 * Tries really hard to only take one task_rq(p)->lock for performance. 4074 * Takes rq->lock in: 4075 * - ttwu_runnable() -- old rq, unavoidable, see comment there; 4076 * - ttwu_queue() -- new rq, for enqueue of the task; 4077 * - psi_ttwu_dequeue() -- much sadness :-( accounting will kill us. 4078 * 4079 * As a consequence we race really badly with just about everything. See the 4080 * many memory barriers and their comments for details. 4081 * 4082 * Return: %true if @p->state changes (an actual wakeup was done), 4083 * %false otherwise. 4084 */ 4085 static int 4086 try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) 4087 { 4088 unsigned long flags; 4089 int cpu, success = 0; 4090 4091 preempt_disable(); 4092 if (p == current) { 4093 /* 4094 * We're waking current, this means 'p->on_rq' and 'task_cpu(p) 4095 * == smp_processor_id()'. Together this means we can special 4096 * case the whole 'p->on_rq && ttwu_runnable()' case below 4097 * without taking any locks. 4098 * 4099 * In particular: 4100 * - we rely on Program-Order guarantees for all the ordering, 4101 * - we're serialized against set_special_state() by virtue of 4102 * it disabling IRQs (this allows not taking ->pi_lock). 4103 */ 4104 if (!ttwu_state_match(p, state, &success)) 4105 goto out; 4106 4107 trace_sched_waking(p); 4108 WRITE_ONCE(p->__state, TASK_RUNNING); 4109 trace_sched_wakeup(p); 4110 goto out; 4111 } 4112 4113 /* 4114 * If we are going to wake up a thread waiting for CONDITION we 4115 * need to ensure that CONDITION=1 done by the caller can not be 4116 * reordered with p->state check below. This pairs with smp_store_mb() 4117 * in set_current_state() that the waiting thread does. 4118 */ 4119 raw_spin_lock_irqsave(&p->pi_lock, flags); 4120 smp_mb__after_spinlock(); 4121 if (!ttwu_state_match(p, state, &success)) 4122 goto unlock; 4123 4124 #ifdef CONFIG_FREEZER 4125 /* 4126 * If we're going to wake up a thread which may be frozen, then 4127 * we can only do so if we have an active CPU which is capable of 4128 * running it. This may not be the case when resuming from suspend, 4129 * as the secondary CPUs may not yet be back online. See __thaw_task() 4130 * for the actual wakeup. 4131 */ 4132 if (unlikely(frozen_or_skipped(p)) && 4133 !cpumask_intersects(cpu_active_mask, task_cpu_possible_mask(p))) 4134 goto unlock; 4135 #endif 4136 4137 trace_sched_waking(p); 4138 4139 /* 4140 * Ensure we load p->on_rq _after_ p->state, otherwise it would 4141 * be possible to, falsely, observe p->on_rq == 0 and get stuck 4142 * in smp_cond_load_acquire() below. 4143 * 4144 * sched_ttwu_pending() try_to_wake_up() 4145 * STORE p->on_rq = 1 LOAD p->state 4146 * UNLOCK rq->lock 4147 * 4148 * __schedule() (switch to task 'p') 4149 * LOCK rq->lock smp_rmb(); 4150 * smp_mb__after_spinlock(); 4151 * UNLOCK rq->lock 4152 * 4153 * [task p] 4154 * STORE p->state = UNINTERRUPTIBLE LOAD p->on_rq 4155 * 4156 * Pairs with the LOCK+smp_mb__after_spinlock() on rq->lock in 4157 * __schedule(). See the comment for smp_mb__after_spinlock(). 4158 * 4159 * A similar smb_rmb() lives in try_invoke_on_locked_down_task(). 4160 */ 4161 smp_rmb(); 4162 if (READ_ONCE(p->on_rq) && ttwu_runnable(p, wake_flags)) 4163 goto unlock; 4164 4165 if (READ_ONCE(p->__state) & TASK_UNINTERRUPTIBLE) 4166 trace_sched_blocked_reason(p); 4167 4168 #ifdef CONFIG_SMP 4169 /* 4170 * Ensure we load p->on_cpu _after_ p->on_rq, otherwise it would be 4171 * possible to, falsely, observe p->on_cpu == 0. 4172 * 4173 * One must be running (->on_cpu == 1) in order to remove oneself 4174 * from the runqueue. 4175 * 4176 * __schedule() (switch to task 'p') try_to_wake_up() 4177 * STORE p->on_cpu = 1 LOAD p->on_rq 4178 * UNLOCK rq->lock 4179 * 4180 * __schedule() (put 'p' to sleep) 4181 * LOCK rq->lock smp_rmb(); 4182 * smp_mb__after_spinlock(); 4183 * STORE p->on_rq = 0 LOAD p->on_cpu 4184 * 4185 * Pairs with the LOCK+smp_mb__after_spinlock() on rq->lock in 4186 * __schedule(). See the comment for smp_mb__after_spinlock(). 4187 * 4188 * Form a control-dep-acquire with p->on_rq == 0 above, to ensure 4189 * schedule()'s deactivate_task() has 'happened' and p will no longer 4190 * care about it's own p->state. See the comment in __schedule(). 4191 */ 4192 smp_acquire__after_ctrl_dep(); 4193 4194 /* 4195 * We're doing the wakeup (@success == 1), they did a dequeue (p->on_rq 4196 * == 0), which means we need to do an enqueue, change p->state to 4197 * TASK_WAKING such that we can unlock p->pi_lock before doing the 4198 * enqueue, such as ttwu_queue_wakelist(). 4199 */ 4200 WRITE_ONCE(p->__state, TASK_WAKING); 4201 4202 /* 4203 * If the owning (remote) CPU is still in the middle of schedule() with 4204 * this task as prev, considering queueing p on the remote CPUs wake_list 4205 * which potentially sends an IPI instead of spinning on p->on_cpu to 4206 * let the waker make forward progress. This is safe because IRQs are 4207 * disabled and the IPI will deliver after on_cpu is cleared. 4208 * 4209 * Ensure we load task_cpu(p) after p->on_cpu: 4210 * 4211 * set_task_cpu(p, cpu); 4212 * STORE p->cpu = @cpu 4213 * __schedule() (switch to task 'p') 4214 * LOCK rq->lock 4215 * smp_mb__after_spin_lock() smp_cond_load_acquire(&p->on_cpu) 4216 * STORE p->on_cpu = 1 LOAD p->cpu 4217 * 4218 * to ensure we observe the correct CPU on which the task is currently 4219 * scheduling. 4220 */ 4221 if (smp_load_acquire(&p->on_cpu) && 4222 ttwu_queue_wakelist(p, task_cpu(p), wake_flags)) 4223 goto unlock; 4224 4225 /* 4226 * If the owning (remote) CPU is still in the middle of schedule() with 4227 * this task as prev, wait until it's done referencing the task. 4228 * 4229 * Pairs with the smp_store_release() in finish_task(). 4230 * 4231 * This ensures that tasks getting woken will be fully ordered against 4232 * their previous state and preserve Program Order. 4233 */ 4234 smp_cond_load_acquire(&p->on_cpu, !VAL); 4235 4236 trace_android_rvh_try_to_wake_up(p); 4237 4238 cpu = select_task_rq(p, p->wake_cpu, wake_flags | WF_TTWU); 4239 if (task_cpu(p) != cpu) { 4240 if (p->in_iowait) { 4241 delayacct_blkio_end(p); 4242 atomic_dec(&task_rq(p)->nr_iowait); 4243 } 4244 4245 wake_flags |= WF_MIGRATED; 4246 psi_ttwu_dequeue(p); 4247 set_task_cpu(p, cpu); 4248 } 4249 #else 4250 cpu = task_cpu(p); 4251 #endif /* CONFIG_SMP */ 4252 4253 ttwu_queue(p, cpu, wake_flags); 4254 unlock: 4255 raw_spin_unlock_irqrestore(&p->pi_lock, flags); 4256 out: 4257 if (success) { 4258 trace_android_rvh_try_to_wake_up_success(p); 4259 ttwu_stat(p, task_cpu(p), wake_flags); 4260 } 4261 preempt_enable(); 4262 4263 return success; 4264 } 分析并给出总结解释

filetype

### dec_gen.py ### # Created by Lorenzo Lagostina in 07/10/2022 and revised by Deborah Volpe # The program allows to create a behavioral description of the ctrl_mask generation block in VHDL import sys import math def dec_gen(qubit_number): N = int(qubit_number) entityName = 'STATE_DECODER_N_' + qubit_number fileOuTName = '../basic_blocks/decoders/src/state_decoder_N_' + qubit_number + '.vhd' fileOut = open (fileOuTName, 'w') ##### Write entity # newLine = 'LIBRARY IEEE;\n USE IEEE.STD_LOGIC_1164.ALL;\n ENTITY state_decoder_N_' + qubit_number + ' IS\n PORT (\n ' + entityName + '_IN_QTGT : IN STD_LOGIC_VECTOR( ' + str(math.ceil(math.log2(N))-1) + ' DOWNTO 0);\n ' + entityName + '_IN_QCTRL : IN STD_LOGIC_VECTOR( ' + str(math.ceil(math.log2(N))-1) + ' DOWNTO 0);\n ' + entityName + '_IN_OPCODE : IN STD_LOGIC_VECTOR (3 DOWNTO 0);\n ' + entityName + '_IN_SAVE_QBIT_NUMBER : IN STD_LOGIC;\n ' + entityName + '_IN_CLEAR : IN STD_LOGIC;\n ' + entityName + '_IN_CLK : IN STD_LOGIC;\n ' + entityName + '_OUT_MASK_FIRST : OUT STD_LOGIC; \n' + entityName + '_OUT_CTRL_MASK : OUT STD_LOGIC_VECTOR ( ' + str((2**N)-1) + ' DOWNTO 0)\n );\n END ENTITY;\n' fileOut.write(newLine) # ##### ##### Begin architecture and declare components and signals # newLine = 'ARCHITECTURE generated OF state_decoder_N_' + str(N) + ' IS\n ' fileOut.write(newLine) #register newLine = 'COMPONENT n_bit_register IS\n generic (n_bit: INTEGER);\n port (REG_IN_DATA: IN STD_LOGIC_VECTOR(n_bit - 1 DOWNTO 0);\n REG_IN_CLK, REG_IN_CLEAR, REG_IN_ENABLE: IN STD_LOGIC;\n REG_OUT_DATA: OUT STD_LOGIC_VECTOR(n_bit - 1 DOWNTO 0));\nEND COMPONENT;\n' fileOut.write(newLine) newLine = 'SIGNAL TO_SAVE_BUF, FROM_SAVE_BUF : STD_LOGIC_VECTOR(0 DOWNTO 0);\n' fileOut.write(newLine) newLine = 'SIGNAL DEC_QCTRL, DEC_USED, QUBIT_USED, QUBIT_MASK, QCTRL_ENABLED_STATES : STD_LOGIC_VECTOR(' + str(N-1) + ' DOWNTO 0);\n' fileOut.write(newLine) newLine = 'SIGNAL CLR_SAVE_QUBIT, ctrl_tgt_diff : STD_LOGIC;\n' fileOut.write(newLine) newLine = 'BEGIN\n' fileOut.write(newLine) # ##### ##### Generate mask_first # newLine = '' + entityName + '_OUT_MASK_FIRST <= \'0\' WHEN ' + entityName + '_IN_OPCODE = \"0010\" OR ' + entityName + '_IN_OPCODE = \"0100\" OR ' + entityName + '_IN_OPCODE = \"0101\" OR ' + entityName + '_IN_OPCODE = \"0110\" OR ' + entityName + '_IN_OPCODE = \"0111\" OR ' + entityName + '_IN_OPCODE = \"1011\" ELSE \'1\';\n' fileOut.write(newLine) # ##### ##### Generate qctrl decoder and qubit mask # newLine = 'DEC_QCTRL <= \n' fileOut.write(newLine) for qubit_index in range(N): newLine = '\"' + '{0:b}'.format(2**qubit_index).zfill(N) + '\" WHEN ' + entityName + '_IN_QCTRL = \"' + '{0:b}'.format(qubit_index).zfill(math.ceil(math.log2(N))) + '\" ELSE\n' fileOut.write(newLine) newLine = '(OTHERS => \'0\');\n' fileOut.write(newLine) newLine = 'ctrl_tgt_diff <= \'1\' WHEN STATE_DECODER_N_' + str(N) + '_IN_QCTRL = STATE_DECODER_N_' + str(N) + '_IN_QTGT ELSE \'0\';\n' fileOut.write(newLine) newLine = 'QCTRL_ENABLED_STATES <= (OTHERS => \'1\') WHEN ctrl_tgt_diff = \'1\' ELSE DEC_QCTRL;\n' fileOut.write(newLine) newLine = 'DEC_USED <= \n' fileOut.write(newLine) for qubit_index in range(N): newLine = '\"' + '{0:b}'.format((2**(qubit_index+1))-1).zfill(N) + '\" WHEN ' + entityName + '_IN_QCTRL = \"' + '{0:b}'.format(qubit_index).zfill(math.ceil(math.log2(N))) + '\" ELSE\n' fileOut.write(newLine) newLine = '(OTHERS => \'0\');\n' fileOut.write(newLine) for qubit_index in range(N): newLine = 'QUBIT_MASK(' + str(qubit_index) + ') <= QCTRL_ENABLED_STATES(' + str(qubit_index) + ') ;\n' fileOut.write(newLine) # ##### ##### Generate registers # newLine = 'TO_SAVE_BUF(0) <= ' + entityName + '_IN_SAVE_QBIT_NUMBER;\n' fileOut.write(newLine) newLine = 'CLR_SAVE_QUBIT <= ' + entityName + '_IN_CLEAR OR FROM_SAVE_BUF(0);\n' fileOut.write(newLine) newLine = 'REG_SAVE_FLAG : n_bit_register\nGENERIC MAP (1)\nPORT MAP(\n REG_IN_DATA => TO_SAVE_BUF ,\n REG_IN_ENABLE => ' + entityName + '_IN_SAVE_QBIT_NUMBER ,\n REG_IN_CLEAR => CLR_SAVE_QUBIT ,\n REG_IN_CLK => ' + entityName + '_IN_CLK ,\n REG_OUT_DATA => FROM_SAVE_BUF);\n' fileOut.write(newLine) newLine = 'REG_SAVE_QUBIT_NUMBER : n_bit_register\nGENERIC MAP (' + str(N) + ')\nPORT MAP(\n REG_IN_DATA => DEC_USED ,\n REG_IN_ENABLE => FROM_SAVE_BUF(0) ,\n REG_IN_CLEAR => ' + entityName + '_IN_CLEAR ,\n REG_IN_CLK => ' + entityName + '_IN_CLK ,\n REG_OUT_DATA => QUBIT_USED);\n' fileOut.write(newLine) # ##### ##### Generate mask decoder # for out_index in range (2**N): if out_index == 0: newLine = entityName + '_OUT_CTRL_MASK(' + str(out_index) + ') <= ctrl_tgt_diff;\n' fileOut.write(newLine) else : signalList = [] for qubit_index in range(N): if not( (out_index & (2**qubit_index)) == 0 ): newLine = 'QUBIT_MASK(' + str(qubit_index) + ')' signalList.append(newLine) newLine = entityName + '_OUT_CTRL_MASK(' + str(out_index) + ') <= ' + ' OR '.join(signalList) + ';\n' fileOut.write(newLine) # ##### newLine = '' fileOut.write(newLine) newLine = 'END generated;' fileOut.write(newLine) dec_gen(sys.argv[1])

温暖如故
  • 粉丝: 33
上传资源 快速赚钱