1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_BENCH_H 18 #define ANDROID_BENCH_H 19 20 #include <pthread.h> 21 22 #include "WorkerPool.h" 23 24 #include <string.h> 25 26 27 28 class Bench { 29 public: 30 Bench(); 31 ~Bench(); 32 33 struct GFlop { 34 int kernelXSize; 35 //int kernelYSize; 36 int imageXSize; 37 //int imageYSize; 38 39 float *srcBuffer; 40 float *kernelBuffer; 41 float *dstBuffer; 42 43 44 }; 45 GFlop mGFlop; 46 47 bool init(); 48 49 bool runPowerManagementTest(uint64_t options); 50 bool runCPUHeatSoak(uint64_t options); 51 52 bool startMemTests(); 53 void endMemTests(); 54 float runMemoryBandwidthTest(uint64_t options); 55 float runMemoryLatencyTest(uint64_t options); 56 57 float runGFlopsTest(uint64_t options); 58 59 void getData(float *data, size_t count) const; 60 61 62 void finish(); 63 64 void setPriority(int32_t p); 65 void destroyWorkerThreadResources(); 66 67 uint64_t getTimeNanos() const; 68 uint64_t getTimeMillis() const; 69 70 // Adds a work unit completed to the timeline and returns 71 // true if the test is ongoing, false if time is up 72 bool incTimeBucket() const; 73 74 75 protected: 76 WorkerPool mWorkers; 77 78 bool mExit; 79 bool mPaused; 80 81 static void testWork(void *usr, uint32_t idx); 82 83 private: 84 uint8_t * volatile mMemSrc; 85 uint8_t * volatile mMemDst; 86 size_t mMemLoopCount; 87 size_t mMemLatencyLastSize; 88 89 90 float ** mIpKernel; 91 float * volatile * mSrcBuf; 92 float * volatile * mOutBuf; 93 uint32_t * mTimeBucket; 94 95 uint64_t mTimeStartNanos; 96 uint64_t mTimeEndNanos; 97 uint64_t mTimeBucketDivisor; 98 uint32_t mTimeBuckets; 99 100 uint64_t mTimeEndGroupNanos; 101 102 bool initIP(); 103 void GflopKernelC(); 104 void GflopKernelC_y3(); 105 106 bool allocateBuckets(size_t); 107 108 109 }; 110 111 112 #endif 113