logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Jihye KimHistory
(5/5)

660 Answers

Hire Me
expert
StatAnalytica ExpertMathematics
(5/5)

731 Answers

Hire Me
expert
Umar AkbarScience
(/5)

642 Answers

Hire Me
expert
StatAnalytica ExpertBusiness
(5/5)

534 Answers

Hire Me
Python Programming
(5/5)

This assignment is based on one-bit and two-bit branch predictors. To simulate instructions and whether branches will occur or not, the provided methods

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Branch Prediction in Python

This assignment is based on one-bit and two-bit branch predictors. To simulate instructions and whether branches will occur or not, the provided methods next_branch_outcome_random

and next_branch_outcome_loop will be used. These methods will simulate a completely random prediction outcome and a set of outcomes that would more closely resemble a series of loops. A return of True represents taking a branch, and a False represents not taking a branch.

The class Predictor represents the predictor. It is best practice to set the initial state to 0.

In [ ]: from random import paretovariate from random import random

def next_branch_outcome_loop(): alpha = 2

outcome = paretovariate(alpha) outcome = outcome > 2

return outcome

def next_branch_outcome_random():

outcome = random() outcome = outcome > 0.5 return outcome

 

class Predictor:

def     init  (self):

self.state = 0

 

def next_predict(self):

"""

Use this method to return the prediction based off of the current state.

"""

raise NotImplementedError("Implement this method")

def incorrect_predict(self):

"""

Use this method to set the next state if an incorrect predict occurred. (self.state = next_state)

"""

raise NotImplementedError("Implement this method")

 

def correct_predict(self):

"""

Use this method to set the next state if an incorrect predict occurred. (self.state = next_state)””

raise NotImplementedError("Implement this method")

 

Part 1 - One Bit Predictor

Complete the OneBitPredictor class by implementing the next_predict, incorrect_predict, and correct_predict methods. This instantiation will be used to compute the prediction accu-

racy. Use the next_predict method of the class to predict the next branch state. If the predict is incorrect, use the incorrect_predict method to set the next state. If the predict is correct, use the correct_predict method to set the next state.

In [ ]: class OneBitPredictor(Predictor):

def next_predict(self):

# YOUR CODE HERE

raise NotImplementedError()

def incorrect_predict(self):

# YOUR CODE HERE

raise NotImplementedError()

def correct_predict(self):

# YOUR CODE HERE

raise NotImplementedError()

Part 1.1 - Random Branch Prediction

Use the next_branch_outcome_random method to generate branch outcomes. Use the previously implemented methods to compute a prediction rate.

 

In [ ]: # YOUR CODE HERE

raise NotImplementedError()

Part 1.2 - Loop Branch Prediction

Use the next_branch_outcome_loop method to generate branch outcomes. Use the previously implemented methods to compute a prediction rate.

In [ ]: # YOUR CODE HERE

raise NotImplementedError()

 Part 2 - Two Bit Predictor

Complete the TwoBitPredictor class by implementing the next_predict, incorrect_predict, and correct_predict methods. This instantiation will be used to compute the prediction accu-

racy. Use the next_predict method of the class to predict the next branch state. If the predict is incorrect, use the incorrect_predict method to set the next state. If the predict is correct, use the correct_predict method to set the next state.

In [ ]: class TwoBitPredictor(Predictor):

def next_predict(self):

# YOUR CODE HERE

raise NotImplementedError()

def incorrect_predict(self):

# YOUR CODE HERE

raise NotImplementedError()

 

def correct_predict(self):

# YOUR CODE HERE

raise NotImplementedError()

Part 2.1 - Random Branch Prediction

Use the next_branch_outcome_random method to generate branch outcomes. Use the previously implemented methods to compute a prediction rate.

In [ ]: # YOUR CODE HERE

raise NotImplementedError()

Part 2.2 - Loop Branch Prediction

Use the next_branch_outcome_loop method to generate branch outcomes. Use the previously implemented methods to compute a prediction rate.

 

In [ ]: # YOUR CODE HERE

raise NotImplementedError()

 Part 3 - N-Bit Predictor

Inherit the Predictor class and implement it’s methods just like before. Now, implement an n-bit predictor that represents a higher confidence prediction.

In [ ]: # YOUR CODE HERE

raise NotImplementedError()

Part 3.1 - Random Branch Prediction

Use the next_branch_outcome_random method to generate branch outcomes. Use the previously implemented methods to compute a prediction rate.

In [ ]: # YOUR CODE HERE

raise NotImplementedError()

Part 3.2 - Loop Branch Prediction

Use the next_branch_outcome_loop method to generate branch outcomes. Use the previously implemented methods to compute a prediction rate.

In [ ]: # YOUR CODE HERE

raise NotImplementedError()

(5/5)
Attachments:

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme