Dydaktyka
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Ćwiczenia 9, grupa cz. 14-16, 4 maja 2023 ###### tags: `SYK23` `ćwiczenia` `pwit` ## Deklaracje Gotowość rozwiązania zadania należy wyrazić poprzez postawienie X w odpowiedniej kolumnie! Jeśli pożądasz zreferować dane zadanie (co najwyżej jedno!) w trakcie dyskusji oznacz je znakiem ==X== na żółtym tle. **UWAGA: Tabelkę wolno edytować tylko wtedy, gdy jest na zielonym tle!** :::danger | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | | ----------------------:| ----- | --- | --- | --- | --- | --- | --- | --- | --- | Mikołaj Balwicki | | | | | | | | | | Wojciech Bogucki | X | X | X | | X | X | | | | Mateusz Cerulewicz | X | X | X | | | X | | | | Mateusz Garncarczyk | ==X== | X | X | X | | X | | | | Mateusz Golisz | X | X | X | | | X | | | | Mateusz Kitzol | X | X | X | X | X | X | | | | Piotr Mańkowski | | | | | | | | | | Michał Mękarski | | | | | | | | | | Aleksandra Nicpoń | X | X | X | X | | X | | | | Ksawery Plis | X | ==X== | X | X | | X | | | | Patryk Rybak | X | X | X | X | | X | X | | | Rafał Spyra | X | X | X | X | X | X | ==X== | X | X | Dominik Szczepaniak | X | X | X | X | X | X | X | | ==X== | Taras Tsehenko | | | | | | | | | | Maksymilian Wiśniewski | X | X | X | X | | ==X== | X | X | | Martyna Wybraniec | X | X | X | X | | X | | | | Natalia Zychowicz | | | | | | | | | | Patryk Maciąg | X | X | X | X | X | X | X | | | ::: :::info **Uwaga:** Po rozwiązaniu zadania należy zmienić kolor nagłówka na zielony. ::: ## Zadanie 1 :::success Autor: Mateusz Garncarczyk ::: ![](https://i.imgur.com/ZhOQt9n.png) ![](https://i.imgur.com/h2LZvIo.png) ![](https://i.imgur.com/wY8LSNc.png) ![](https://i.imgur.com/VuUyz2p.png) ![](https://i.imgur.com/ioZ6WGj.png) ![](https://i.imgur.com/YdUvfND.png) ## Zadanie 2 :::success Autor: Ksawery Plis ::: ![](https://i.imgur.com/Jin5wQu.png) **Pamięć podręczna z mapowaniem bezpośrednim adresowanym bajtowo:** pamięć podręczna taka że w każdym zbiorze $S$ znajduje się tylko jeden wiersz $E$ (a więc $E$=1). * **Jaki jest rozmiar bloku w 32-bitowych słowach?** Offset zapisywany jest na 5 bitach. Jego maksymalna wartość to 31 (11111$_2$). Więc blok ma 32 bajty. * **Ile wierszy ma nasza pamięć podręczna?** Aby otrzymać liczbę wierszy, musimy spojrzeć na to, jakie indeksy są możliwe do uzyskania. Wiemy że index zapisywany jest na 5 bitach, także możemy otrzymać liczby od 0 do 31 (jest ich w sumie 32). Także liczba wierszy w pamięci podręcznej będzie wynosiła 32. * **Jaki jest stosunek liczby bitów składujących dane do liczby bitów składujących metadane?** Na metadane składa się tag (22 bity) oraz bit valid. Dane przechowywane są na 32 bajtach. Także stosunek danych do metadanych wynosi $\frac{8*32}{22+1} = \frac{256}{23} \approx 11.13$ ## Zadanie 3 :::success Autor: Mateusz Cerulewicz ::: ``` tag set offset 0: 0 00000 00000 compulsory 4: 0 00000 00100 hit 16: 0 00000 10000 hit 132: 0 00100 00100 compulsory 232: 0 00111 01000 compulsory 160: 0 00101 00000 compulsory 1024: 1 00000 00000 conflict 28: 0 00000 11100 conflict 140: 0 00100 01100 hit 3100: 11 00000 11000 conflict 180: 0 00101 10100 hit 2180: 10 00100 00100 conflict 8 podmian (4 konflikty i 4 puste) Liczba trafien: 4 Efektywnosc: 4/12 = 1/3 Pamiec na koncu: (11, 00000, ...) (10, 00100, ...) (0, 00101, ...) (0, 00111, ...) ``` ## Zadanie 4 :::success Autor: Mateusz Kitzol ::: ![](https://i.imgur.com/rMJzhIj.png) ![](https://i.imgur.com/i8f0zOB.png) ### a) sekcyjno-skojarzeniowa blok: 2 * 4B = 8B = 2^3B, czyli **offset - 3 bity** 24 bloki i po 3 bloki na zbiór, czyli 8 zbiorów, czyli **index - 3 bity** **Adres:** tag: 26 bitów index: 3 bity offset: 3 bity | Adres | Zapis bitowy | tag | index | offset | hit/miss? | | ---------:| ---------------- | --- | ----- | ------ | --------------- | | 0 | 0 00000 00000 | 0 | 000 | 000 | MISS compulsory | | 4 | 0 00000 00100 | 0 | 000 | 100 | HIT | | 16 | 0 00000 10000 | 0 | 010 | 000 | MISS compulsory | | 132 | 0 00100 00100 | 10 | 000 | 100 | MISS compulsory | | 232 | 0 00111 01000 | 11 | 101 | 000 | MISS compulsory | | 160 | 0 00101 00000 | 10 | 100 | 000 | MISS compulsory | | 1024 | 1 00000 00000 | 10000| 000 | 000 | MISS compulsory | | 28 | 0 00000 11100 | 0 | 011 | 100 | MISS compulsory | | 140 | 0 00100 01100 | 10 | 001 | 100 | MISS compulsory | | 3100 | 11 00000 11100 | 110000 | 011 | 100 | MISS compulsory | | 180 | 0 00101 10100 | 10 | 110 | 100 | MISS compulsory | | 2180 | 10 00100 00100 | 100010 | 000 | 100 | MISS conflict | **Liczba bloków zastąpionych:** $11$ (compulsory miss + conflict miss) **Efektywność pamięci wewnętrznej:** $\frac{1}{12} = 8.(3)$% **Zawartość pamięci:** |index|tag | |------|-----| |0 |100010 | | |10 | | |10000 | |1 |10 | | |- | | |- | |10 |0 | | |- | | |- | |11 |0 | | |110000 | | |- | |100 |10 | | |- | | |- | |101 |11 | | |- | | |- | |110 |10 | | |- | | |- | |111 |- | | |- | | |- | ### b) w pełni asocjacyjna Słowo: 32b = 4B, czyli blok: 4B = $2^2B$ **Adres:** offset: 2 bity index: 0 bitów tag: 32-2-0 = 30 bitów | Adres | Zapis bitowy | tag | offset | hit/miss? | | -----:| -------------- | ------ | ------ | --------------- | | 0 | 000000000 00 | 0 | 0 | MISS compulsory | | 4 | 000000001 00 | 1 | 0 | MISS compulsory | | 16 | 000000100 00 | 100 | 0 | MISS compulsory | | 132 | 000100001 00 | 100001 | 0 | MISS compulsory | | 232 | 000111010 00 | 111010 | 0 | MISS compulsory | | 160 | 000101000 00 | 101000 | 0 | MISS compulsory | | 1024 | 100000000 00 | 100000000 | 0 | MISS compulsory | | 28 | 000000111 00 | 111 | 0 | MISS compulsory | | 140 | 000100011 00 | 100011 | 0 | MISS conflict | | 3100 | 1100000111 00 | 1100000111 | 0 | MISS conflict | | 180 | 000101101 00 | 101101 | 0 | MISS conflict | | 2180 | 1000100001 00 | 1000100001 | 0 | MISS conflict | **Liczba bloków zastąpionych:** $12$ (compulsory miss + conflict miss) **Efektywność pamięci wewnętrznej:** $\frac{0}{12} = 0$% **Zawartość pamięci:** |index|tag | |------|-----| |0 |100011 | | |1100000111 | | |101101 | | |1000100001 | | |111011 | | |101000 | | |100000000 | | |111 | ## Zadanie 5 :::success Autor: Patryk Maciąg ::: ![](https://i.imgur.com/ME1T5Rk.png) ![](https://i.imgur.com/ZP2Ogcj.png) ## Zadanie 6 :::success Autor: Maksymilian Wiśniewski ::: ![](https://i.imgur.com/FWlLrCr.jpg) ## Zadanie 7 :::success Autor: Patryk Rybak ::: ![](https://i.imgur.com/yMMmghb.png) Sufit z logarytmu o podstawie 2 z 4! to 5. Mamy więc 5 bitów do wykorzystania. Set może mieć najwyżej 4 bloki. Dzięki temu zapisanie numeru bloku zajmie 2 bity (numeracja od 0 do 3). Wykorzystanie 5 bitów: - 2 pierwsze bity zapisują numer bloku, który jest najstarszy - 2 kolejne bity zapisują numer drugiego najstarszego bloku W tym momencie zostaje jeden bit do wykorzystania, który nie wystarcza na zapisanie liczby od 0 do 3. - ostatni bit informuje czy prawie najmłodszy blok i najmłodszy będące uporządkowane pod względem wieku, czy są też uporządkowane leksykograficznie Jak wyznaczyć kandydata do usunięcia ze zbioru? Wystarczy spojrzeć na dwa pierwszy bity naszej struktury. Jak aktualizować informacje zawarte w dodatkowych bitach przy wykonywaniu dostępów do elementów zbioru? 1. Jeżeli wykonamy dostęp do najmłodszego bloku, nic się nie zmieni. Nie musimy aktualizować struktury, ponieważ status wieku pozostaje ten sam i porządek leksykograficzny względem najłodszego i prawienajmłodszego bloku również się nie zmienia. 2. Jeżeli wykonamy dostęp do prawie najłodszego bloku, wystarczy zanegować piąty bit struktury. 3. Jeżeli wykonamy dostęp do prawie najstarszego bloku, należy rozpoznać, z pomocą struktury, prawie najmłodszy blok (odrzucamy bloki z czterech pierwszych bitów, wtedy o wyborze decyduje już tylok piąty bit), zapisać go na miejsce prawie najstarszego (trzeci i czwarty bit), następnie porównać leksykograficznie blok, do którego nastąpiło odwołanie ze "starym" najmłodszym blokiem. Skoro "stary" najmłodszy blok staje się tak na prawdę prawie najmłodszym to jeżeli leksykograficznie pierwszy okaże się blok z odwołania, należy piąty bit struktury ustawić na 1. 4. Jeżeli wykonamy dostęp do najstarszego bloku, należy zaminić miejscami wartości zapisane na dwóch pierwszych i dwóch kolejnych bitach struktury i wykonac działania w taki sposób, jakbyśmy wykonali dostęp do prawie najstarszego bloku. ## Zadanie 8 :::success Autor: Rafał Spyra ::: 1. cache: 2^9B offset: log2(rozmiar\ bloku) = log_2(16) = 4 liczba bloków: log2(rozmiar cache / rozmiar bloku) = log_2(2^9 / 2^4) = 5 tag: reszta | Tag | Index | Offset | |-|-|-| |1 | 5 | 4 | | Var | Address | Tag | Index | Offset | Result | Notes | | - | -| -| -| -| - | - | | x[0][0] | 0 | 0..00 | 00000 | 0000 | compulsory miss | | x[1][0] | 512 | 0..01 | 00000 | 0000 | conflict miss | nadpisuje x[0][0] | | x[0][1] | 4 | 0..00 | 00000 | 0100 | conflict miss | nadpisuje x[1][0] | | x[1][1] | 516 | 0..01 | 00000 | 0100 | conflict miss | nadpisuje x[0][1] | 100% bo każde chybia 2. cache: 2^10B offset: log2(rozmiar\ bloku) = log2(16) = 4 liczba bloków: log2(2^10 / 2^4) = 6 tag: reszta | Tag | Index | Offset | |-|-|-| | 0 | 6 | 4 | | Var | Address | Index | Offset | Result | Notes | | - | -| -| -| - | - | | x[0][0] | 0 | 000000 | 0000 | compulsory miss | | x[1][0] | 512 | 100000 | 0000 | compulsory miss | | x[0][1] | 4 | 000000 | 0100 | hit | wpis x[0][0] | | x[1][1] | 516 | 100000 | 0100 | hit | wpis x[1][0] | | x[0][2] | 8 | 000000 | 1000 | hit | wpis x[0][0] | | x[1][2] | 520 | 100000 | 1000 | hit | wpis x[1][0] | | x[0][3] | 12 | 000000 | 1100 | hit | wpis x[0][0] | | x[1][2] | 524 | 100000 | 1100 | hit | wpis x[1][0] | | x[0][4] | 16 | 000001 | 0000 | compulsory miss | | x[1][4] | 528 | 100001 | 0000 | compulsory miss | Wx[i][$\frac{j}{4}$] compulsory miss, następne 3 (x[i][j + {1,2,3}]) hit. 25% 3. cache: 2^9B offset: 4 liczba bloków: log2(rozmiar cache / (rozmiar bloku * liczba bloków na sekcje )) = log2(2^9 / (2^4 * 2)) = log(2^4) = 4 tag: reszta | Tag | Index | Offset | |-|-|-| | 2 | 4 | 4 | | Var | Address | Tag | Index | Offset | Result | Notes| | - | -| -| -| -| - | - | | x[0][0] | 0 | 0..000 | 0000 | 0000 | compulsory | | x[1][0] | 512 | 0..010 | 0000 | 0000 | compulsory | i=0 wolny tag | | x[0][1] | 4 | 0..000 | 0000 | 0100 | hit | wpis x[0][0] | | x[1][1] | 516 | 0..010 | 0000 | 0100 | hit | wpis x[1][0] | | x[0][2] | 8 | 0..000 | 0000 | 1000 | hit | wpis x[0][0] | | x[1][2] | 520 | 0..010 | 0000 | 1000 | hit | wpis x[1][0] | | x[0][3] | 12 | 0..000 | 0000 | 1100 | hit | wpis x[0][0] | | x[1][3] | 520 | 0..010 | 0000 | 1100 | hit | wpis x[1][0] | | x[0][4] | 16 | 0..000 | 0001 | 0000 | compulsory | | x[1][4] | 524 | 0..010 | 0001 | 0000 | compulsory | i=1 wolny tag | Analogicznie do B. 25%. Jeśli zwiększymy rozmiar bloku (offset) to zmiejszy się liczba chybień ## Zadanie 9 :::success Autor: Dominik Szczepaniak ::: ![](https://i.imgur.com/zW9vEyo.png) Rozmiar cache = 2^15 (32 kB) Offset = log2(rozmiar bloku) = log2(8) = 3 Index (liczba bloków) = log2(rozmiar cache / rozmiar bloku) = log2(2^15 / 2^3) = log2(2^12) = 12 Tag = 32-3-12 = 17 ```python from collections import defaultdict cache_testing = defaultdict(lambda: 0) MEMORY_SIZE = 1<<15 BLOCK_SIZE = 1<<3 SET_SIZE = 1<<12 miss = 0 total = 0 for j in range(639, -1, -1): for i in range(479, -1, -1): for pixel in range(4): mem_space = ((i * 640) + j) * 4 #miejsce w tablicy dla buffer[i][j] #(kolejne kolumny zaczynaja sie co caly wiersz miejsc, wiec co 640, #stad i*640, pozniej musimy dodac miejsce w ktorej kolumnie jestesmy (+j), #a nastepnie *4, gdyz pixel ma 4 chary - 4*1 = 4) mem_space_to_binary = bin(mem_space) #postac 0b{liczba binarna} mem_space_to_binary = mem_space_to_binary[2:] while(len(mem_space_to_binary) != 32): mem_space_to_binary = "0" + mem_space_to_binary index = mem_space_to_binary[17:28] #index to bit od 18 do 29 (-1 bo od 0 iterujemy) cache_index = int(index, 2) tag = int(mem_space_to_binary[0:16], 2) #tag ma 17 bitow (pierwsze) if cache_testing[cache_index] != tag: cache_testing[cache_index] = tag miss += 1 total+=1 print(miss/total) ``` Wynik: 0.25 Więc mamy 25% chybień, czyli 75% trafień

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully