|
| 1 | +// RUN: %clangxx -fsycl %s -o %t.out |
| 2 | +// RUN: %GPU_RUN_PLACEHOLDER %t.out |
| 3 | +// |
| 4 | +// UNSUPPORTED: windows |
| 5 | +// |
| 6 | +//==-----memory-consumption.cpp - SYCL memory consumption basic test ------==// |
| 7 | +// |
| 8 | +// This test specifically tests that memory consumption does not change |
| 9 | +// when the get_devices() is called repeatedly. |
| 10 | +// |
| 11 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 12 | +// See https://llvm.org/LICENSE.txt for license information. |
| 13 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 14 | +// |
| 15 | +//===----------------------------------------------------------------------===// |
| 16 | + |
| 17 | +#include "CL/sycl.hpp" |
| 18 | +#include <iostream> |
| 19 | +#include <thread> |
| 20 | + |
| 21 | +#ifdef __linux__ |
| 22 | +#include <strings.h> |
| 23 | +#include <sys/resource.h> |
| 24 | +#include <sys/time.h> |
| 25 | + |
| 26 | +long get_cpu_mem() { |
| 27 | + struct rusage usage; |
| 28 | + memset(&usage, 0, sizeof(rusage)); |
| 29 | + getrusage(RUSAGE_SELF, &usage); |
| 30 | + return usage.ru_maxrss; |
| 31 | +} |
| 32 | +#endif |
| 33 | + |
| 34 | +using namespace cl::sycl; |
| 35 | + |
| 36 | +int main() { |
| 37 | + constexpr auto dev_type = info::device_type::gpu; |
| 38 | + auto devices = device::get_devices(dev_type); |
| 39 | + |
| 40 | + int startSize = get_cpu_mem(); |
| 41 | + std::cout << startSize << " kb" << std::endl; |
| 42 | + |
| 43 | + for (int i = 0; i < 1000; i++) { |
| 44 | + devices = cl::sycl::device::get_devices(dev_type); |
| 45 | + } |
| 46 | + int endSize = get_cpu_mem(); |
| 47 | + std::cout << endSize << " kb" << std::endl; |
| 48 | + |
| 49 | + auto plat = devices[0].get_platform(); |
| 50 | + std::string plat_name = plat.get_info<info::platform::name>(); |
| 51 | + std::cout << "Platform: " << plat_name << std::endl; |
| 52 | + |
| 53 | + devices.erase(devices.begin(), devices.end()); |
| 54 | + |
| 55 | + if (startSize == endSize) { |
| 56 | + std::cout << "Passed" << std::endl; |
| 57 | + return 0; |
| 58 | + } else { |
| 59 | + std::cout << "Failed" << std::endl; |
| 60 | + return 1; |
| 61 | + } |
| 62 | +} |
0 commit comments