turbopipe 1.2.1__cp311-cp311-win_amd64.whl → 1.2.3__cp311-cp311-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of turbopipe might be problematic. Click here for more details.

turbopipe/__init__.py CHANGED
@@ -4,33 +4,21 @@ from moderngl import Buffer
4
4
 
5
5
  from turbopipe import _turbopipe
6
6
 
7
+ __all__ = [
8
+ "pipe",
9
+ "sync",
10
+ "close"
11
+ ]
7
12
 
8
13
  def pipe(buffer: Union[Buffer, memoryview], fileno: int) -> None:
9
- """
10
- Pipe the content of a moderngl.Buffer or memoryview to a file descriptor, fast, threaded and
11
- blocking when needed. Call `sync(buffer)` before this, and `sync()` when done for
12
-
13
- Usage:
14
- ```python
15
- # Assuming `buffer = ctx.buffer(...)`
16
- # Note: Use as `fbo.read_into(buffer)`
17
-
18
- # As a open() file
19
- with open("file.bin", "wb") as file:
20
- turbopipe.pipe(buffer, file)
21
-
22
- # As a subprocess
23
- child = subprocess.Popen(..., stdin=subprocess.PIPE)
24
- turbopipe.pipe(buffer, child.stdin.fileno())
25
- ```
26
- """
14
+ """Pipe a buffer contents to a file descriptor, fast and threaded"""
27
15
  if isinstance(buffer, Buffer):
28
16
  buffer = memoryview(buffer.mglo)
29
17
  _turbopipe.pipe(buffer, fileno)
30
18
  del buffer
31
19
 
32
20
  def sync(buffer: Optional[Union[Buffer, memoryview]]=None) -> None:
33
- """Waits for any pending write operation on a buffer, or 'all buffers' if None, to finish"""
21
+ """Wait for pending operations on a buffer to finish"""
34
22
  if isinstance(buffer, Buffer):
35
23
  buffer = memoryview(buffer.mglo)
36
24
  _turbopipe.sync(buffer)
@@ -39,9 +27,3 @@ def sync(buffer: Optional[Union[Buffer, memoryview]]=None) -> None:
39
27
  def close() -> None:
40
28
  """Syncs and deletes objects"""
41
29
  _turbopipe.close()
42
-
43
- __all__ = [
44
- "pipe",
45
- "sync",
46
- "close"
47
- ]
Binary file
Binary file
@@ -1,41 +1,18 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: turbopipe
3
- Version: 1.2.1
4
- Summary: 🌀 Faster MemoryView inter-process data transfers for subprocesses
5
- Home-page: https://brokensrc.dev
3
+ Version: 1.2.3
4
+ Summary: 🌀 Faster ModernGL Buffers inter-process data transfers for subprocesses
6
5
  Author-Email: Tremeschin <29046864+Tremeschin@users.noreply.github.com>
7
- License: MIT License
8
-
9
- Copyright (c) 2024 Gabriel Tremeschin
10
-
11
- Permission is hereby granted, free of charge, to any person obtaining a copy
12
- of this software and associated documentation files (the "Software"), to deal
13
- in the Software without restriction, including without limitation the rights
14
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
- copies of the Software, and to permit persons to whom the Software is
16
- furnished to do so, subject to the following conditions:
17
-
18
- The above copyright notice and this permission notice shall be included in all
19
- copies or substantial portions of the Software.
20
-
21
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
- SOFTWARE.
28
- Project-URL: Issues, https://github.com/BrokenSource/TurboPipe/issues
29
- Project-URL: Repository, https://github.com/BrokenSource/TurboPipe
30
- Project-URL: Documentation, https://github.com/BrokenSource/TurboPipe
6
+ License-Expression: MIT
7
+ Project-URL: GitHub, https://github.com/BrokenSource/TurboPipe
8
+ Project-URL: Changelog, https://brokensrc.dev/about/changelog
9
+ Project-URL: Funding, https://brokensrc.dev/about/sponsors
10
+ Project-URL: Contact, https://brokensrc.dev/about/contact
31
11
  Project-URL: Homepage, https://brokensrc.dev
32
12
  Requires-Python: >=3.7
33
13
  Requires-Dist: moderngl
34
14
  Description-Content-Type: text/markdown
35
15
 
36
- > [!IMPORTANT]
37
- > <sub>Also check out [**ShaderFlow**](https://github.com/BrokenSource/ShaderFlow), where **TurboPipe** shines! 😉</sub>
38
- <!-- PyPI -->
39
16
  <div align="center">
40
17
  <a href="https://brokensrc.dev/"><img src="https://raw.githubusercontent.com/BrokenSource/TurboPipe/main/turbopipe/resources/images/turbopipe.png" width="200"></a>
41
18
  <h1>TurboPipe</h1>
@@ -57,15 +34,17 @@ Description-Content-Type: text/markdown
57
34
 
58
35
  The **optimizations** involved are:
59
36
 
60
- - **Zero-copy**: Avoid unnecessary memory copies or allocation (intermediate `buffer.read()`)
37
+ - **Zero-copy**: Avoid unnecessary memory copies or allocation (intermediate `buffer.read`)
61
38
  - **C++**: The core of TurboPipe is written in C++ for speed, efficiency and low-level control
62
- - **Chunks**: Write in chunks of 4096 bytes (RAM page size), so the hardware is happy (Unix)
63
39
  - **Threaded**:
64
40
  - Doesn't block Python code execution, allows to render next frame
65
41
  - Decouples the main thread from the I/O thread for performance
42
+ - **Chunks**: Write in chunks of 4096 bytes (RAM page size), so the hardware is happy (Unix)
66
43
 
67
44
  ✅ Don't worry, there's proper **safety** in place. TurboPipe will block Python if a memory address is already queued for writing, and guarantees order of writes per file-descriptor. Just call `.sync()` when done 😉
68
45
 
46
+ <sub>Also check out [**ShaderFlow**](https://github.com/BrokenSource/ShaderFlow), where **TurboPipe** shines! 😉</sub>
47
+
69
48
  <br>
70
49
 
71
50
  # 📦 Installation
@@ -90,7 +69,7 @@ rye add turbopipe
90
69
 
91
70
  # 🚀 Usage
92
71
 
93
- See also the [**Examples**](https://github.com/BrokenSource/TurboPipe/tree/main/examples) folder for comparisons, and [**ShaderFlow**](https://github.com/BrokenSource/ShaderFlow/blob/main/ShaderFlow/Scene.py) usage of it!
72
+ See also the [**Examples**](https://github.com/BrokenSource/TurboPipe/tree/main/examples) folder for comparisons, and [**ShaderFlow**](https://github.com/BrokenSource/ShaderFlow/blob/main/ShaderFlow/Exporting.py)'s usage of it!
94
73
 
95
74
  ```python
96
75
  import subprocess
@@ -98,27 +77,53 @@ import subprocess
98
77
  import moderngl
99
78
  import turbopipe
100
79
 
101
- # Create ModernGL objects
80
+ # Create ModernGL objects and proxy buffers
102
81
  ctx = moderngl.create_standalone_context()
103
- buffers = [ctx.buffer(reserve=1920*1080*3) for _ in range(2)]
82
+ width, height, duration, fps = (1920, 1080, 10, 60)
83
+ buffers = [
84
+ ctx.buffer(reserve=(width*height*3))
85
+ for _ in range(nbuffers := 2)
86
+ ]
87
+
88
+ # Create your FBO, Textures, Shaders, etc.
104
89
 
105
90
  # Make sure resolution, pixel format matches!
106
- ffmpeg = subprocess.Popen(
107
- 'ffmpeg -f rawvideo -pix_fmt rgb24 -r 60 -s 1920x1080 -i - -f null -'.split(),
108
- stdin=subprocess.PIPE
109
- )
110
-
111
- # Rendering loop of yours (eg. 1m footage)
112
- for frame in range(60 * 60):
113
- buffer = buffers[frame % len(buffer)]
91
+ ffmpeg = subprocess.Popen((
92
+ "ffmpeg",
93
+ "-f", "rawvideo",
94
+ "-pix_fmt", "rgb24",
95
+ "-r", str(fps),
96
+ "-s", f"{width}x{height}",
97
+ "-i", "-",
98
+ "-f", "null",
99
+ "output.mp4"
100
+ ), stdin=subprocess.PIPE)
101
+
102
+ # Rendering loop of yours
103
+ for frame in range(duration*fps):
104
+ buffer = buffers[frame % nbuffers]
105
+
106
+ # Wait queued writes before copying
114
107
  turbopipe.sync(buffer)
115
108
  fbo.read_into(buffer)
109
+
110
+ # Doesn't lock the GIL, writes in parallel
116
111
  turbopipe.pipe(buffer, ffmpeg.stdin.fileno())
117
112
 
118
- # Finalize writing, encoding
119
- turbopipe.sync()
113
+ # Wait for queued writes, clean memory
114
+ for buffer in buffers:
115
+ turbopipe.sync(buffer)
116
+ buffer.release()
117
+
118
+ # Signal stdin stream is done
120
119
  ffmpeg.stdin.close()
120
+
121
+ # wait for encoding to finish
121
122
  ffmpeg.wait()
123
+
124
+ # Warn: Albeit rare, only call close when no other data
125
+ # write is pending, as it might skip a frame or halt
126
+ turbopipe.close()
122
127
  ```
123
128
 
124
129
  <br>
@@ -370,6 +375,5 @@ On realistically loads, like [**ShaderFlow**](https://github.com/BrokenSource/Sh
370
375
  # 📚 Future work
371
376
 
372
377
  - Disable/investigate performance degradation on Windows iGPUs
373
- - Improve the thread synchronization and/or use a ThreadPool
374
378
  - Maybe use `mmap` instead of chunks writing on Linux
375
- - Test on macOS 🙈
379
+ - Split the code into a libturbopipe? Not sure where it would be useful 😅
@@ -0,0 +1,6 @@
1
+ turbopipe-1.2.3.dist-info/METADATA,sha256=MdldXjJ_g4d1H7thMGPxOrXbTYj3LiWFE3KaMJTACUw,21140
2
+ turbopipe-1.2.3.dist-info/WHEEL,sha256=JdLTWhc73oJ-lqTBYGgiVontr_vhzwzbpAOin_2bxTI,85
3
+ turbopipe/_turbopipe.cp311-win_amd64.pyd,sha256=yJD_XhGRyw9Z5sKjVzT3ubDx5d34o62faa1n7Z-bVkM,35328
4
+ turbopipe/_turbopipe.cp311-win_amd64.lib,sha256=KfpsBMKaMjWkL9k85fPiD8rbNah07ucga1jlAQAJ_Qw,2068
5
+ turbopipe/__init__.py,sha256=-dDOggd5gJ67k7Mv_GowhRegxEZFV4qzTvEPJOCTE-A,774
6
+ turbopipe-1.2.3.dist-info/RECORD,,
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Gabriel Tremeschin
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,7 +0,0 @@
1
- turbopipe-1.2.1.dist-info/METADATA,sha256=GuqiVUQMXXC0AGUHOjy5KX-UO0ouWSHZ39clFCpKRls,21841
2
- turbopipe-1.2.1.dist-info/WHEEL,sha256=JdLTWhc73oJ-lqTBYGgiVontr_vhzwzbpAOin_2bxTI,85
3
- turbopipe-1.2.1.dist-info/License.md,sha256=s3HF089BzBa_7DenpGj5kPHBu-XhGLP6gRzhhhLXLls,1096
4
- turbopipe/_turbopipe.cp311-win_amd64.pyd,sha256=umJ5kKlpQ0WCZPcowZyyL--OUwSsqVfgb3J7O_QErCE,35840
5
- turbopipe/_turbopipe.cp311-win_amd64.lib,sha256=FOg1T3nQ61oD9EUJCnT7a1rrfoVtdaiVT5r8mUNgwRM,2068
6
- turbopipe/__init__.py,sha256=D0FP-CR87qJeLGv_VYCGRcwdONFhBYt02D2bm4Xdax4,1346
7
- turbopipe-1.2.1.dist-info/RECORD,,