ucbrise / piranha

Piranha: A GPU Platform for Secure Computation
MIT License
89 stars 25 forks source link

Timing differences in two tests: copy data from device to host #4

Closed DylanWangWQF closed 2 years ago

DylanWangWQF commented 2 years ago

Hi @jlwatson , When I test the timing results for copying data from device to host, I got the different results as shown:

  1. First test to print uint64_t in DeviceData

    # util.cuh
    template<typename T, typename I>
    void printDeviceDataForInteger(DeviceData<T, I> &device_data)
    {
    std::vector<uint64_t> host_temp(device_data.size());
    thrust::copy(device_data.begin(), device_data.end(), host_temp.begin());
    
    for (int i = 0; i < host_temp.size(); i++) {
        printf("%lld ", host_temp[i]);
    }
    std::cout << std::endl;
    }
    # DeviceData.cu
    TYPED_TEST(DeviceDataTest, IntegerDeviceData) {
    using T = typename TestFixture::ParamType;
    DeviceData<T> d1 = {1, 2, 3};
    DeviceData<T> d2 = {1, 1, 1};
    d1 += d2;
    printDeviceDataForInteger(d1);
    }

    The result is around 32538ms

  2. The second test is the original DRELU2 test in piranha:

    TYPED_TEST(FuncTest, DRELU2) {
    
    ....omit.....
    
    //Change to <uint8_t>
    DeviceData<uint64_t> super_result(result.size());
    reconstruct(result, super_result);
    
    printDeviceData(super_result, "actual", false);
    assertDeviceData(super_result, expected, false);
    }

    while the result is around 13ms as shown:

    [ RUN      ] FuncTest/1.DRELU2
    actual:
    0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 
    src/test/../mpc/../gpu/../util/util.cuh:343: Failure
    Expected: (fabs(host_result[i] - expected[i])) <= (epsilon), actual: 1 vs 0.001
    [  FAILED  ] FuncTest/1.DRELU2, where TypeParam = TPC<unsigned long, thrust::detail::normal_iterator<thrust::device_ptr<unsigned long> > > 
    (13 ms)

What's the reason for these two different timing results?

DylanWangWQF commented 2 years ago

The result is expected when I change the order of invoking each unit test. Maybe it's due to gtest.