Download ml-stable-diffusion/mlx/tests/allocator_tests.cpp from Fahad-S/FastVLM_SANA: direct link, hf CLI and curl.
- Browser
- Download file 831 Bytes
-
https://huggingface.co/Fahad-S/FastVLM_SANA/resolve/main/ml-stable-diffusion/mlx/tests/allocator_tests.cpp
- Command line
-
hf download hf://Fahad-S/FastVLM_SANA/ml-stable-diffusion/mlx/tests/allocator_tests.cpp
-
curl -L -o allocator_tests.cpp https://huggingface.co/Fahad-S/FastVLM_SANA/resolve/main/ml-stable-diffusion/mlx/tests/allocator_tests.cpp
831 Bytes
| // Copyright © 2023 Apple Inc. | |
| using namespace mlx::core; | |
| TEST_CASE("test simple allocations") { | |
| { | |
| auto buffer = allocator::malloc(sizeof(float)); | |
| auto fptr = static_cast<float*>(buffer.raw_ptr()); | |
| *fptr = 0.5f; | |
| CHECK_EQ(*fptr, 0.5f); | |
| allocator::free(buffer); | |
| } | |
| { | |
| auto buffer = allocator::malloc(128 * sizeof(int)); | |
| int* ptr = static_cast<int*>(buffer.raw_ptr()); | |
| for (int i = 0; i < 128; ++i) { | |
| ptr[i] = i; | |
| } | |
| allocator::free(buffer); | |
| } | |
| { | |
| auto buffer = allocator::malloc(0); | |
| allocator::free(buffer); | |
| } | |
| } | |
| TEST_CASE("test large allocations") { | |
| size_t size = 1 << 30; | |
| for (int i = 0; i < 100; ++i) { | |
| auto buffer = allocator::malloc(size); | |
| allocator::free(buffer); | |
| } | |
| } | |