TEST_P(ocl_engine_test, BasicInteropC) { auto p = GetParam(); cl_device_id ocl_dev = (p.adev_kind == dev_kind::gpu) ? gpu_ocl_dev : (p.adev_kind == dev_kind::cpu) ? cpu_ocl_dev : nullptr; cl_context ocl_ctx = (p.actx_kind == ctx_kind::gpu) ? gpu_ocl_ctx : (p.actx_kind == ctx_kind::cpu) ? cpu_ocl_ctx : nullptr; SKIP_IF(p.adev_kind != dev_kind::null && !ocl_dev, "Required OpenCL device not found."); SKIP_IF(p.actx_kind != ctx_kind::null && !ocl_ctx, "Required OpenCL context not found."); SKIP_IF(cpu_ocl_dev == gpu_ocl_dev && (p.adev_kind == dev_kind::cpu || p.actx_kind == ctx_kind::cpu), "OpenCL CPU-only device not found."); mkldnn_engine_t eng; mkldnn_status_t s = mkldnn_engine_create_ocl(&eng, mkldnn_gpu, ocl_dev, ocl_ctx); EXPECT_EQ(s, p.expected_status); if (s == mkldnn_success) { cl_device_id dev; cl_context ctx; MKLDNN_CHECK(mkldnn_engine_get_ocl_device(eng, &dev)); MKLDNN_CHECK(mkldnn_engine_get_ocl_context(eng, &ctx)); EXPECT_EQ(dev, ocl_dev); EXPECT_EQ(ctx, ocl_ctx); cl_uint ref_count; OCL_CHECK(clGetContextInfo(ocl_ctx, CL_CONTEXT_REFERENCE_COUNT, sizeof(ref_count), &ref_count, nullptr)); int i_ref_count = int(ref_count); EXPECT_EQ(i_ref_count, 2); MKLDNN_CHECK(mkldnn_engine_destroy(eng)); OCL_CHECK(clGetContextInfo(ocl_ctx, CL_CONTEXT_REFERENCE_COUNT, sizeof(ref_count), &ref_count, nullptr)); i_ref_count = int(ref_count); EXPECT_EQ(i_ref_count, 1); } }
TEST_P(ocl_engine_test, BasicInteropCpp) { auto p = GetParam(); cl_device_id ocl_dev = (p.adev_kind == dev_kind::gpu) ? gpu_ocl_dev : (p.adev_kind == dev_kind::cpu) ? cpu_ocl_dev : nullptr; cl_context ocl_ctx = (p.actx_kind == ctx_kind::gpu) ? gpu_ocl_ctx : (p.actx_kind == ctx_kind::cpu) ? cpu_ocl_ctx : nullptr; SKIP_IF(p.adev_kind != dev_kind::null && !ocl_dev, "Required OpenCL device not found."); SKIP_IF(p.actx_kind != ctx_kind::null && !ocl_ctx, "Required OpenCL context not found."); SKIP_IF(cpu_ocl_dev == gpu_ocl_dev && (p.adev_kind == dev_kind::cpu || p.actx_kind == ctx_kind::cpu), "OpenCL CPU-only device not found."); catch_expected_failures( [&]() { { engine eng(engine::kind::gpu, ocl_dev, ocl_ctx); if (p.expected_status != mkldnn_success) { FAIL() << "Success not expected"; } cl_device_id dev = eng.get_ocl_device(); cl_context ctx = eng.get_ocl_context(); EXPECT_EQ(dev, ocl_dev); EXPECT_EQ(ctx, ocl_ctx); cl_uint ref_count; OCL_CHECK(clGetContextInfo(ocl_ctx, CL_CONTEXT_REFERENCE_COUNT, sizeof(ref_count), &ref_count, nullptr)); int i_ref_count = int(ref_count); EXPECT_EQ(i_ref_count, 2); } cl_uint ref_count; OCL_CHECK(clGetContextInfo(ocl_ctx, CL_CONTEXT_REFERENCE_COUNT, sizeof(ref_count), &ref_count, nullptr)); int i_ref_count = int(ref_count); EXPECT_EQ(i_ref_count, 1); }, p.expected_status != mkldnn_success, p.expected_status); }
TEST_P(Int8ToInt32, UsingLoadParam) { std::string arch = omrsysinfo_get_CPU_architecture(); SKIP_IF(OMRPORT_ARCH_S390 == arch || OMRPORT_ARCH_S390X == arch, KnownBug) << "The Z code generator incorrectly spills sub-integer types arguments (see issue #3525)"; auto param = TRTest::to_struct(GetParam()); char *inputTrees = "(method return=Int32 args=[Int8]" " (block" " (ireturn" " (b2i" " (bload parm=0) ) ) ) )"; auto trees = parseString(inputTrees); ASSERT_NOTNULL(trees); Tril::DefaultCompiler compiler{trees}; ASSERT_EQ(0, compiler.compile()) << "Compilation failed unexpectedly\n" << "Input trees: " << inputTrees; auto entry_point = compiler.getEntryPoint<int32_t (*)(int8_t)>(); volatile auto exp = param.oracle(param.value); volatile auto act = entry_point(param.value); ASSERT_EQ(exp, act); }
TEST_P(engine_test_c, CreateWithBackend) { mkldnn_engine_kind_t engine_kind = GetParam(); SKIP_IF(mkldnn_engine_get_count(engine_kind) == 0, "Engine kind is not supported."); auto backend_kinds = { mkldnn_backend_native, mkldnn_backend_ocl }; for (auto backend_kind : backend_kinds) { if (engine_kind == mkldnn_cpu) { if (backend_kind == mkldnn_backend_ocl) continue; } else if (engine_kind == mkldnn_gpu) { if (backend_kind == mkldnn_backend_native) continue; } mkldnn_engine_t engine; MKLDNN_CHECK(mkldnn_engine_create_with_backend( &engine, engine_kind, backend_kind, 0)); mkldnn_backend_kind_t queried_backend_kind; MKLDNN_CHECK( mkldnn_engine_get_backend_kind(engine, &queried_backend_kind)); EXPECT_EQ(queried_backend_kind, backend_kind); MKLDNN_CHECK(mkldnn_engine_destroy(engine)); } }
int main(void) { SKIP_IF(valgrind_is_caller()); ASSERT_TRUE(close(-1) == -1); ASSERT_TRUE(errno == EBADF); return EXIT_SUCCESS; }
TEST_P(engine_test_cpp, GetBackend) { engine::kind engine_kind = static_cast<engine::kind>(GetParam()); SKIP_IF(engine::get_count(engine_kind) == 0, "Engine kind is not supported."); engine eng(engine_kind, 0); compare_backend(static_cast<mkldnn_engine_kind_t>(engine_kind), static_cast<mkldnn_backend_kind_t>(eng.get_backend_kind())); }
int cpu_event_pinned_vs_ebb(void) { union pipe read_pipe, write_pipe; struct event event; int cpu, rc; pid_t pid; SKIP_IF(!ebb_is_supported()); cpu = pick_online_cpu(); FAIL_IF(cpu < 0); FAIL_IF(bind_to_cpu(cpu)); FAIL_IF(pipe(read_pipe.fds) == -1); FAIL_IF(pipe(write_pipe.fds) == -1); pid = fork(); if (pid == 0) { /* NB order of pipes looks reversed */ exit(ebb_child(write_pipe, read_pipe)); } /* We setup the cpu event first */ rc = setup_cpu_event(&event, cpu); if (rc) { kill_child_and_wait(pid); return rc; } /* Signal the child to install its EBB event and wait */ if (sync_with_child(read_pipe, write_pipe)) /* If it fails, wait for it to exit */ goto wait; /* Signal the child to run */ FAIL_IF(sync_with_child(read_pipe, write_pipe)); wait: /* We expect it to fail to read the event */ FAIL_IF(wait_for_child(pid) != 2); FAIL_IF(event_disable(&event)); FAIL_IF(event_read(&event)); event_report(&event); /* The cpu event should have run */ FAIL_IF(event.result.value == 0); FAIL_IF(event.result.enabled != event.result.running); return 0; }
runall_result test_main() { SKIP_IF(!is_gpu_hardware_available()); runall_result result; result &= REPORT_RESULT((test_feature<int, 1>())); result &= REPORT_RESULT((test_feature<unsigned int, 91>())); result &= REPORT_RESULT((test_feature<float, 5>())); result &= REPORT_RESULT((test_feature<double, 31>())); return result; }
int test_copy_unaligned(void) { /* Only run this test on a P9 or later */ SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_00)); /* Register our signal handler with SIGBUS */ setup_signal_handler(); /* +1 makes buf unaligned */ copy(cacheline_buf+1); /* We should not get here */ return 1; }
TEST_P(engine_test_c, GetBackend) { mkldnn_engine_kind_t engine_kind = GetParam(); SKIP_IF(mkldnn_engine_get_count(engine_kind) == 0, "Engine kind is not supported."); mkldnn_engine_t engine; MKLDNN_CHECK(mkldnn_engine_create(&engine, engine_kind, 0)); mkldnn_backend_kind_t backend_kind; MKLDNN_CHECK(mkldnn_engine_get_backend_kind(engine, &backend_kind)); compare_backend(engine_kind, backend_kind); MKLDNN_CHECK(mkldnn_engine_destroy(engine)); }
static int setup_cpu_event(struct event *event, int cpu) { event_init_named(event, 0x400FA, "PM_RUN_INST_CMPL"); event->attr.pinned = 1; event->attr.exclude_kernel = 1; event->attr.exclude_hv = 1; event->attr.exclude_idle = 1; SKIP_IF(require_paranoia_below(1)); FAIL_IF(event_open_with_cpu(event, cpu)); FAIL_IF(event_enable(event)); return 0; }
runall_result test_main() { SKIP_IF(!is_gpu_hardware_available()); runall_result result; result &= REPORT_RESULT((test_feature<int, 1, 1, 1>())); result &= REPORT_RESULT((test_feature<int, 7, 3, 2>())); result &= REPORT_RESULT((test_feature<int, 5, 3, 5>())); result &= REPORT_RESULT((test_feature<unsigned, 3, 2, 1>())); result &= REPORT_RESULT((test_feature<signed, 3, 5, 5>())); result &= REPORT_RESULT((test_feature<float, 2, 3, 2>())); result &= REPORT_RESULT((test_feature<float, 5, 1, 5>())); result &= REPORT_RESULT((test_feature<double, 2, 7, 7>())); return result; }
int task_event_vs_ebb(void) { union pipe read_pipe, write_pipe; struct event event; pid_t pid; int rc; SKIP_IF(!ebb_is_supported()); FAIL_IF(pipe(read_pipe.fds) == -1); FAIL_IF(pipe(write_pipe.fds) == -1); pid = fork(); if (pid == 0) { /* NB order of pipes looks reversed */ exit(ebb_child(write_pipe, read_pipe)); } /* We setup the task event first */ rc = setup_child_event(&event, pid); if (rc) { kill_child_and_wait(pid); return rc; } /* Signal the child to install its EBB event and wait */ if (sync_with_child(read_pipe, write_pipe)) /* If it fails, wait for it to exit */ goto wait; /* Signal the child to run */ FAIL_IF(sync_with_child(read_pipe, write_pipe)); wait: /* The EBB event should push the task event off so the child should succeed */ FAIL_IF(wait_for_child(pid)); FAIL_IF(event_disable(&event)); FAIL_IF(event_read(&event)); event_report(&event); /* The task event may have run, or not so we can't assert anything about it */ return 0; }
static int no_handler_test(void) { struct event event; u64 val; int i; SKIP_IF(!ebb_is_supported()); event_init_named(&event, 0x1001e, "cycles"); event_leader_ebb_init(&event); event.attr.exclude_kernel = 1; event.attr.exclude_hv = 1; event.attr.exclude_idle = 1; FAIL_IF(event_open(&event)); FAIL_IF(ebb_event_enable(&event)); val = mfspr(SPRN_EBBHR); FAIL_IF(val != 0); /* Make sure it overflows quickly */ sample_period = 1000; mtspr(SPRN_PMC1, pmc_sample_period(sample_period)); /* Spin to make sure the event has time to overflow */ for (i = 0; i < 1000; i++) mb(); dump_ebb_state(); /* We expect to see the PMU frozen & PMAO set */ val = mfspr(SPRN_MMCR0); FAIL_IF(val != 0x0000000080000080); event_close(&event); dump_ebb_state(); /* The real test is that we never took an EBB at 0x0 */ return 0; }
/* * Test basic access to the EBB regs, they should be user accessible with no * kernel interaction required. */ int reg_access(void) { uint64_t val, expected; SKIP_IF(!ebb_is_supported()); expected = 0x8000000100000000ull; mtspr(SPRN_BESCR, expected); val = mfspr(SPRN_BESCR); FAIL_IF(val != expected); expected = 0x0000000001000000ull; mtspr(SPRN_EBBHR, expected); val = mfspr(SPRN_EBBHR); FAIL_IF(val != expected); return 0; }
static int ipc_unmuxed(void) { int tests_done = 0; #define DO_TEST(_name, _num) \ FAIL_IF(test_##_name()); \ tests_done++; #include "ipc.h" #undef DO_TEST /* * If we ran no tests then it means none of the syscall numbers were * defined, possibly because we were built against old headers. But it * means we didn't really test anything, so instead of passing mark it * as a skip to give the user a clue. */ SKIP_IF(tests_done == 0); return 0; }
int tm_syscall(void) { unsigned count = 0; struct timeval end, now; SKIP_IF(!((long)get_auxv_entry(AT_HWCAP2) & PPC_FEATURE2_HTM_NOSC)); setbuf(stdout, NULL); printf("Testing transactional syscalls for %d seconds...\n", TEST_DURATION); gettimeofday(&end, NULL); now.tv_sec = TEST_DURATION; now.tv_usec = 0; timeradd(&end, &now, &end); for (count = 0; timercmp(&now, &end, <); count++) { /* * Test a syscall within a suspended transaction and verify * that it succeeds. */ FAIL_IF(getppid_tm(true) == -1); /* Should succeed. */ /* * Test a syscall within an active transaction and verify that * it fails with the correct failure code. */ FAIL_IF(getppid_tm(false) != -1); /* Should fail... */ FAIL_IF(!failure_is_persistent()); /* ...persistently... */ FAIL_IF(!failure_is_syscall()); /* ...with code syscall. */ gettimeofday(&now, 0); } printf("%d active and suspended transactions behaved correctly.\n", count); printf("(There were %d transaction retries.)\n", retries); return 0; }
static int per_event_excludes(void) { struct event *e, events[4]; char *platform; int i; platform = (char *)get_auxv_entry(AT_BASE_PLATFORM); FAIL_IF(!platform); SKIP_IF(strcmp(platform, "power8") != 0); /* * We need to create the events disabled, otherwise the running/enabled * counts don't match up. */ e = &events[0]; event_init_opts(e, PERF_COUNT_HW_INSTRUCTIONS, PERF_TYPE_HARDWARE, "instructions"); e->attr.disabled = 1; e = &events[1]; event_init_opts(e, PERF_COUNT_HW_INSTRUCTIONS, PERF_TYPE_HARDWARE, "instructions(k)"); e->attr.disabled = 1; e->attr.exclude_user = 1; e->attr.exclude_hv = 1; e = &events[2]; event_init_opts(e, PERF_COUNT_HW_INSTRUCTIONS, PERF_TYPE_HARDWARE, "instructions(h)"); e->attr.disabled = 1; e->attr.exclude_user = 1; e->attr.exclude_kernel = 1; e = &events[3]; event_init_opts(e, PERF_COUNT_HW_INSTRUCTIONS, PERF_TYPE_HARDWARE, "instructions(u)"); e->attr.disabled = 1; e->attr.exclude_hv = 1; e->attr.exclude_kernel = 1; FAIL_IF(event_open(&events[0])); /* * The open here will fail if we don't have per event exclude support, * because the second event has an incompatible set of exclude settings * and we're asking for the events to be in a group. */ for (i = 1; i < 4; i++) FAIL_IF(event_open_with_group(&events[i], events[0].fd)); /* * Even though the above will fail without per-event excludes we keep * testing in order to be thorough. */ prctl(PR_TASK_PERF_EVENTS_ENABLE); /* Spin for a while */ for (i = 0; i < INT_MAX; i++) asm volatile("" : : : "memory"); prctl(PR_TASK_PERF_EVENTS_DISABLE); for (i = 0; i < 4; i++) { FAIL_IF(event_read(&events[i])); event_report(&events[i]); } /* * We should see that all events have enabled == running. That * shows that they were all on the PMU at once. */ for (i = 0; i < 4; i++) FAIL_IF(events[i].result.running != events[i].result.enabled); /* * We can also check that the result for instructions is >= all the * other counts. That's because it is counting all instructions while * the others are counting a subset. */ for (i = 1; i < 4; i++) FAIL_IF(events[0].result.value < events[i].result.value); for (i = 0; i < 4; i++) event_close(&events[i]); return 0; }